Provide email proposals from address book

This commit is contained in:
Eike Kettner
2020-01-12 01:04:42 +01:00
parent c84a69aa9c
commit d535130c9e
14 changed files with 426 additions and 43 deletions

View File

@ -39,6 +39,9 @@ case class Column(name: String, ns: String = "", alias: String = "") {
def isIn(values: Seq[Fragment]): Fragment =
f ++ fr"IN (" ++ commas(values) ++ fr")"
def isIn(frag: Fragment): Fragment =
f ++ fr"IN (" ++ frag ++ fr")"
def isOrDiscard[A: Put](value: Option[A]): Fragment =
value match {
case Some(v) => is(v)

View File

@ -1,10 +1,12 @@
package docspell.store.queries
import fs2.Stream
import doobie._
import doobie.implicits._
import docspell.common.{Direction, Ident}
import docspell.store.impl.Implicits._
import docspell.store.records.{RAttachment, RItem, RTag, RTagItem}
import docspell.store.records._
import docspell.common.ContactKind
object QCollective {
@ -50,4 +52,38 @@ object QCollective {
} yield InsightData(n0, n1, n2.getOrElse(0), Map.from(n3))
}
def getContacts(
coll: Ident,
query: Option[String],
kind: Option[ContactKind]
): Stream[ConnectionIO, RContact] = {
val RO = ROrganization
val RP = RPerson
val RC = RContact
val orgCond = selectSimple(Seq(RO.Columns.oid), RO.table, RO.Columns.cid.is(coll))
val persCond = selectSimple(Seq(RP.Columns.pid), RP.table, RP.Columns.cid.is(coll))
val queryCond = query match {
case Some(q) =>
Seq(RC.Columns.value.lowerLike(s"%${q.toLowerCase}%"))
case None =>
Seq.empty
}
val kindCond = kind match {
case Some(k) =>
Seq(RC.Columns.kind.is(k))
case None =>
Seq.empty
}
val q = selectSimple(
RC.Columns.all,
RC.table,
and(
Seq(or(RC.Columns.orgId.isIn(orgCond), RC.Columns.personId.isIn(persCond))) ++ queryCond ++ kindCond
)
) ++ orderBy(RC.Columns.value.f)
q.query[RContact].stream
}
}