mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Instead of client only, make bookmarks a server aware feature
Makes it much more useful
This commit is contained in:
@ -49,6 +49,7 @@ trait BackendApp[F[_]] {
|
||||
def pubSub: PubSubT[F]
|
||||
def events: EventExchange[F]
|
||||
def notification: ONotification[F]
|
||||
def bookmarks: OQueryBookmarks[F]
|
||||
}
|
||||
|
||||
object BackendApp {
|
||||
@ -89,6 +90,7 @@ object BackendApp {
|
||||
OShare(store, itemSearchImpl, simpleSearchImpl, javaEmil)
|
||||
)
|
||||
notifyImpl <- ONotification(store, notificationMod)
|
||||
bookmarksImpl <- OQueryBookmarks(store)
|
||||
} yield new BackendApp[F] {
|
||||
val pubSub = pubSubT
|
||||
val login = loginImpl
|
||||
@ -115,5 +117,6 @@ object BackendApp {
|
||||
val share = shareImpl
|
||||
val events = notificationMod
|
||||
val notification = notifyImpl
|
||||
val bookmarks = bookmarksImpl
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,83 @@
|
||||
package docspell.backend.ops
|
||||
|
||||
import docspell.common._
|
||||
import docspell.query.ItemQuery
|
||||
import cats.effect._
|
||||
import docspell.store.Store
|
||||
import docspell.store.records.RQueryBookmark
|
||||
import cats.implicits._
|
||||
import docspell.store.UpdateResult
|
||||
import docspell.store.AddResult
|
||||
|
||||
trait OQueryBookmarks[F[_]] {
|
||||
|
||||
def getAll(account: AccountId): F[Vector[OQueryBookmarks.Bookmark]]
|
||||
|
||||
def create(account: AccountId, bookmark: OQueryBookmarks.NewBookmark): F[AddResult]
|
||||
|
||||
def update(
|
||||
account: AccountId,
|
||||
id: Ident,
|
||||
bookmark: OQueryBookmarks.NewBookmark
|
||||
): F[UpdateResult]
|
||||
|
||||
def delete(account: AccountId, bookmark: Ident): F[Unit]
|
||||
}
|
||||
|
||||
object OQueryBookmarks {
|
||||
final case class NewBookmark(
|
||||
name: String,
|
||||
label: Option[String],
|
||||
query: ItemQuery,
|
||||
personal: Boolean
|
||||
)
|
||||
|
||||
final case class Bookmark(
|
||||
id: Ident,
|
||||
name: String,
|
||||
label: Option[String],
|
||||
query: ItemQuery,
|
||||
personal: Boolean,
|
||||
created: Timestamp
|
||||
)
|
||||
|
||||
def apply[F[_]: Sync](store: Store[F]): Resource[F, OQueryBookmarks[F]] =
|
||||
Resource.pure(new OQueryBookmarks[F] {
|
||||
def getAll(account: AccountId): F[Vector[Bookmark]] =
|
||||
store
|
||||
.transact(RQueryBookmark.allForUser(account))
|
||||
.map(
|
||||
_.map(r => Bookmark(r.id, r.name, r.label, r.query, r.isPersonal, r.created))
|
||||
)
|
||||
|
||||
def create(account: AccountId, b: NewBookmark): F[AddResult] =
|
||||
store
|
||||
.transact(for {
|
||||
r <- RQueryBookmark.createNew(account, b.name, b.label, b.query, b.personal)
|
||||
n <- RQueryBookmark.insert(r)
|
||||
} yield n)
|
||||
.attempt
|
||||
.map(AddResult.fromUpdate)
|
||||
|
||||
def update(account: AccountId, id: Ident, b: NewBookmark): F[UpdateResult] =
|
||||
UpdateResult.fromUpdate(
|
||||
store.transact(
|
||||
RQueryBookmark.update(
|
||||
RQueryBookmark(
|
||||
id,
|
||||
b.name,
|
||||
b.label,
|
||||
None, // userId and some other values are not used
|
||||
account.collective,
|
||||
b.query,
|
||||
Timestamp.Epoch
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def delete(account: AccountId, bookmark: Ident): F[Unit] =
|
||||
store.transact(RQueryBookmark.deleteById(account.collective, bookmark)).as(())
|
||||
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user