Add missing organization/person/equipment routes

This commit is contained in:
Eike Kettner
2020-08-07 01:20:26 +02:00
parent 639ab7440e
commit f3ba224124
8 changed files with 115 additions and 1 deletions

View File

@ -52,6 +52,34 @@ object QOrganization {
})
}
def getOrgAndContact(
coll: Ident,
orgId: Ident
): ConnectionIO[Option[(ROrganization, Vector[RContact])]] = {
val oColl = ROrganization.Columns.cid.prefix("o")
val oId = ROrganization.Columns.oid.prefix("o")
val cOrg = RContact.Columns.orgId.prefix("c")
val cols = ROrganization.Columns.all.map(_.prefix("o")) ++ RContact.Columns.all
.map(_.prefix("c"))
val from = ROrganization.table ++ fr"o LEFT JOIN" ++
RContact.table ++ fr"c ON" ++ cOrg.is(oId)
val q = and(oColl.is(coll), oId.is(orgId))
selectSimple(cols, from, q)
.query[(ROrganization, Option[RContact])]
.stream
.groupAdjacentBy(_._1)
.map({
case (ro, chunk) =>
val cs = chunk.toVector.flatMap(_._2)
(ro, cs)
})
.compile
.last
}
def findPersonAndContact(
coll: Ident,
query: Option[String],
@ -88,6 +116,34 @@ object QOrganization {
})
}
def getPersonAndContact(
coll: Ident,
persId: Ident
): ConnectionIO[Option[(RPerson, Vector[RContact])]] = {
val pColl = PC.cid.prefix("p")
val pId = RPerson.Columns.pid.prefix("p")
val cPers = RContact.Columns.personId.prefix("c")
val cols = RPerson.Columns.all.map(_.prefix("p")) ++ RContact.Columns.all
.map(_.prefix("c"))
val from = RPerson.table ++ fr"p LEFT JOIN" ++
RContact.table ++ fr"c ON" ++ cPers.is(pId)
val q = and(pColl.is(coll), pId.is(persId))
selectSimple(cols, from, q)
.query[(RPerson, Option[RContact])]
.stream
.groupAdjacentBy(_._1)
.map({
case (ro, chunk) =>
val cs = chunk.toVector.flatMap(_._2)
(ro, cs)
})
.compile
.last
}
def findPersonByContact(
coll: Ident,
value: String,

View File

@ -1,8 +1,10 @@
package docspell.store.records
import cats.data.NonEmptyList
import docspell.common._
import docspell.store.impl.Implicits._
import cats.data.NonEmptyList
import doobie._
import doobie.implicits._