mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Initial impl of import from mailbox user task
This commit is contained in:
@ -2,6 +2,7 @@ package docspell.store.impl
|
||||
|
||||
import doobie._, doobie.implicits._
|
||||
import docspell.store.impl.DoobieSyntax._
|
||||
import cats.data.NonEmptyList
|
||||
|
||||
case class Column(name: String, ns: String = "", alias: String = "") {
|
||||
|
||||
@ -46,6 +47,9 @@ case class Column(name: String, ns: String = "", alias: String = "") {
|
||||
def isIn(values: Seq[Fragment]): Fragment =
|
||||
f ++ fr"IN (" ++ commas(values) ++ fr")"
|
||||
|
||||
def isIn[A: Put](values: NonEmptyList[A]): Fragment =
|
||||
isIn(values.map(a => sql"$a").toList)
|
||||
|
||||
def isIn(frag: Fragment): Fragment =
|
||||
f ++ fr"IN (" ++ frag ++ fr")"
|
||||
|
||||
|
@ -86,6 +86,31 @@ object QOrganization {
|
||||
})
|
||||
}
|
||||
|
||||
def findPersonByContact(
|
||||
coll: Ident,
|
||||
value: String,
|
||||
ck: Option[ContactKind],
|
||||
concerning: Option[Boolean]
|
||||
): Stream[ConnectionIO, RPerson] = {
|
||||
val pColl = PC.cid.prefix("p")
|
||||
val pConc = PC.concerning.prefix("p")
|
||||
val pId = PC.pid.prefix("p")
|
||||
val cPers = RContact.Columns.personId.prefix("c")
|
||||
val cVal = RContact.Columns.value.prefix("c")
|
||||
val cKind = RContact.Columns.kind.prefix("c")
|
||||
|
||||
val from = RPerson.table ++ fr"p INNER JOIN" ++
|
||||
RContact.table ++ fr"c ON" ++ cPers.is(pId)
|
||||
val q = Seq(
|
||||
cVal.lowerLike(s"%${value.toLowerCase}%"),
|
||||
pColl.is(coll)
|
||||
) ++ concerning.map(pConc.is(_)).toSeq ++ ck.map(cKind.is(_)).toSeq
|
||||
|
||||
selectDistinct(PC.all.map(_.prefix("p")), from, and(q))
|
||||
.query[RPerson]
|
||||
.stream
|
||||
}
|
||||
|
||||
def addOrg[F[_]](
|
||||
org: ROrganization,
|
||||
contacts: Seq[RContact],
|
||||
|
@ -6,6 +6,7 @@ import doobie.implicits._
|
||||
import docspell.common._
|
||||
import docspell.store.impl._
|
||||
import docspell.store.impl.Implicits._
|
||||
import cats.data.NonEmptyList
|
||||
|
||||
/** The archive file of some attachment. The `id` is shared with the
|
||||
* attachment, to create a 0..1-1 relationship.
|
||||
@ -72,6 +73,26 @@ object RAttachmentArchive {
|
||||
selectSimple(all.map(_.prefix("a")), from, where).query[RAttachmentArchive].option
|
||||
}
|
||||
|
||||
def findByMessageIdAndCollective(
|
||||
messageIds: NonEmptyList[String],
|
||||
collective: Ident
|
||||
): ConnectionIO[Vector[RAttachmentArchive]] = {
|
||||
val bId = RAttachment.Columns.id.prefix("b")
|
||||
val bItem = RAttachment.Columns.itemId.prefix("b")
|
||||
val aMsgId = Columns.messageId.prefix("a")
|
||||
val aId = Columns.id.prefix("a")
|
||||
val iId = RItem.Columns.id.prefix("i")
|
||||
val iColl = RItem.Columns.cid.prefix("i")
|
||||
|
||||
val from = table ++ fr"a INNER JOIN" ++
|
||||
RAttachment.table ++ fr"b ON" ++ aId.is(bId) ++
|
||||
fr"INNER JOIN" ++ RItem.table ++ fr"i ON" ++ bItem.is(iId)
|
||||
|
||||
val where = and(aMsgId.isIn(messageIds), iColl.is(collective))
|
||||
|
||||
selectSimple(all.map(_.prefix("a")), from, where).query[RAttachmentArchive].to[Vector]
|
||||
}
|
||||
|
||||
def findByItemWithMeta(
|
||||
id: Ident
|
||||
): ConnectionIO[Vector[(RAttachmentArchive, FileMeta)]] = {
|
||||
|
Reference in New Issue
Block a user