Allow bookmarks in periodic query notification

This commit is contained in:
eikek
2022-01-10 14:25:20 +01:00
parent ccb4df5bd7
commit 699cf091e6
19 changed files with 497 additions and 82 deletions

View File

@ -11,12 +11,12 @@ import cats.syntax.all._
import docspell.common._
import docspell.query.ItemQuery
import docspell.store.AddResult
import docspell.store.qb.DSL._
import docspell.store.qb._
import doobie._
import doobie.implicits._
import docspell.store.AddResult
final case class RQueryBookmark(
id: Ident,
@ -153,4 +153,25 @@ object RQueryBookmark {
bm.cid === account.collective && (bm.userId.isNull || bm.userId.in(users))
).build.query[RQueryBookmark].to[Vector]
}
def findByNameOrId(
account: AccountId,
nameOrId: String
): ConnectionIO[Option[RQueryBookmark]] = {
val user = RUser.as("u")
val bm = RQueryBookmark.as("bm")
val users = Select(
user.uid.s,
from(user),
user.cid === account.collective && user.login === account.user
)
Select(
select(bm.all),
from(bm),
bm.cid === account.collective &&
(bm.userId.isNull || bm.userId.in(users)) &&
(bm.name === nameOrId || bm.id ==== nameOrId)
).build.query[RQueryBookmark].option
}
}

View File

@ -138,6 +138,23 @@ object RShare {
.option
})
def findOneByCollective(
cid: Ident,
enabled: Option[Boolean],
nameOrId: String
): ConnectionIO[Option[RShare]] = {
val s = RShare.as("s")
val u = RUser.as("u")
Select(
select(s.all),
from(s).innerJoin(u, u.uid === s.userId),
u.cid === cid &&
(s.name === nameOrId || s.id ==== nameOrId) &&?
enabled.map(e => s.enabled === e)
).build.query[RShare].option
}
def findAllByCollective(
cid: Ident,
ownerLogin: Option[Ident],