mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-04 22:25:58 +00:00
Add missing organization/person/equipment routes
This commit is contained in:
parent
639ab7440e
commit
f3ba224124
@ -11,6 +11,8 @@ trait OEquipment[F[_]] {
|
|||||||
|
|
||||||
def findAll(account: AccountId, nameQuery: Option[String]): F[Vector[REquipment]]
|
def findAll(account: AccountId, nameQuery: Option[String]): F[Vector[REquipment]]
|
||||||
|
|
||||||
|
def find(account: AccountId, id: Ident): F[Option[REquipment]]
|
||||||
|
|
||||||
def add(s: REquipment): F[AddResult]
|
def add(s: REquipment): F[AddResult]
|
||||||
|
|
||||||
def update(s: REquipment): F[AddResult]
|
def update(s: REquipment): F[AddResult]
|
||||||
@ -25,6 +27,9 @@ object OEquipment {
|
|||||||
def findAll(account: AccountId, nameQuery: Option[String]): F[Vector[REquipment]] =
|
def findAll(account: AccountId, nameQuery: Option[String]): F[Vector[REquipment]] =
|
||||||
store.transact(REquipment.findAll(account.collective, nameQuery, _.name))
|
store.transact(REquipment.findAll(account.collective, nameQuery, _.name))
|
||||||
|
|
||||||
|
def find(account: AccountId, id: Ident): F[Option[REquipment]] =
|
||||||
|
store.transact(REquipment.findById(id)).map(_.filter(_.cid == account.collective))
|
||||||
|
|
||||||
def add(e: REquipment): F[AddResult] = {
|
def add(e: REquipment): F[AddResult] = {
|
||||||
def insert = REquipment.insert(e)
|
def insert = REquipment.insert(e)
|
||||||
def exists = REquipment.existsByName(e.cid, e.name)
|
def exists = REquipment.existsByName(e.cid, e.name)
|
||||||
|
@ -11,6 +11,7 @@ import docspell.store.records._
|
|||||||
|
|
||||||
trait OOrganization[F[_]] {
|
trait OOrganization[F[_]] {
|
||||||
def findAllOrg(account: AccountId, query: Option[String]): F[Vector[OrgAndContacts]]
|
def findAllOrg(account: AccountId, query: Option[String]): F[Vector[OrgAndContacts]]
|
||||||
|
def findOrg(account: AccountId, orgId: Ident): F[Option[OrgAndContacts]]
|
||||||
|
|
||||||
def findAllOrgRefs(account: AccountId, nameQuery: Option[String]): F[Vector[IdRef]]
|
def findAllOrgRefs(account: AccountId, nameQuery: Option[String]): F[Vector[IdRef]]
|
||||||
|
|
||||||
@ -23,6 +24,8 @@ trait OOrganization[F[_]] {
|
|||||||
query: Option[String]
|
query: Option[String]
|
||||||
): F[Vector[PersonAndContacts]]
|
): F[Vector[PersonAndContacts]]
|
||||||
|
|
||||||
|
def findPerson(account: AccountId, persId: Ident): F[Option[PersonAndContacts]]
|
||||||
|
|
||||||
def findAllPersonRefs(account: AccountId, nameQuery: Option[String]): F[Vector[IdRef]]
|
def findAllPersonRefs(account: AccountId, nameQuery: Option[String]): F[Vector[IdRef]]
|
||||||
|
|
||||||
def addPerson(s: PersonAndContacts): F[AddResult]
|
def addPerson(s: PersonAndContacts): F[AddResult]
|
||||||
@ -53,6 +56,11 @@ object OOrganization {
|
|||||||
.compile
|
.compile
|
||||||
.toVector
|
.toVector
|
||||||
|
|
||||||
|
def findOrg(account: AccountId, orgId: Ident): F[Option[OrgAndContacts]] =
|
||||||
|
store
|
||||||
|
.transact(QOrganization.getOrgAndContact(account.collective, orgId))
|
||||||
|
.map(_.map({ case (org, cont) => OrgAndContacts(org, cont) }))
|
||||||
|
|
||||||
def findAllOrgRefs(
|
def findAllOrgRefs(
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
nameQuery: Option[String]
|
nameQuery: Option[String]
|
||||||
@ -75,6 +83,11 @@ object OOrganization {
|
|||||||
.compile
|
.compile
|
||||||
.toVector
|
.toVector
|
||||||
|
|
||||||
|
def findPerson(account: AccountId, persId: Ident): F[Option[PersonAndContacts]] =
|
||||||
|
store
|
||||||
|
.transact(QOrganization.getPersonAndContact(account.collective, persId))
|
||||||
|
.map(_.map({ case (org, cont) => PersonAndContacts(org, cont) }))
|
||||||
|
|
||||||
def findAllPersonRefs(
|
def findAllPersonRefs(
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
nameQuery: Option[String]
|
nameQuery: Option[String]
|
||||||
|
@ -778,6 +778,23 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/BasicResult"
|
$ref: "#/components/schemas/BasicResult"
|
||||||
/sec/equipment/{id}:
|
/sec/equipment/{id}:
|
||||||
|
get:
|
||||||
|
tags: [ Equipment ]
|
||||||
|
summary: Get details about a single equipment.
|
||||||
|
description: |
|
||||||
|
Loads one equipment by its id.
|
||||||
|
security:
|
||||||
|
- authTokenHeader: []
|
||||||
|
parameters:
|
||||||
|
- $ref: "#/components/parameters/id"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Ok
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Equipment"
|
||||||
|
|
||||||
delete:
|
delete:
|
||||||
tags: [ Equipment ]
|
tags: [ Equipment ]
|
||||||
summary: Delete a equipment.
|
summary: Delete a equipment.
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package docspell.restserver.routes
|
package docspell.restserver.routes
|
||||||
|
|
||||||
|
import cats.data.OptionT
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
import cats.implicits._
|
import cats.implicits._
|
||||||
|
|
||||||
@ -49,6 +50,12 @@ object EquipmentRoutes {
|
|||||||
del <- backend.equipment.delete(id, user.account.collective)
|
del <- backend.equipment.delete(id, user.account.collective)
|
||||||
resp <- Ok(basicResult(del, "Equipment deleted."))
|
resp <- Ok(basicResult(del, "Equipment deleted."))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
|
||||||
|
case GET -> Root / Ident(id) =>
|
||||||
|
(for {
|
||||||
|
equip <- OptionT(backend.equipment.find(user.account, id))
|
||||||
|
resp <- OptionT.liftF(Ok(mkEquipment(equip)))
|
||||||
|
} yield resp).getOrElseF(NotFound())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package docspell.restserver.routes
|
package docspell.restserver.routes
|
||||||
|
|
||||||
|
import cats.data.OptionT
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
import cats.implicits._
|
import cats.implicits._
|
||||||
|
|
||||||
@ -55,6 +56,12 @@ object OrganizationRoutes {
|
|||||||
delOrg <- backend.organization.deleteOrg(id, user.account.collective)
|
delOrg <- backend.organization.deleteOrg(id, user.account.collective)
|
||||||
resp <- Ok(basicResult(delOrg, "Organization deleted."))
|
resp <- Ok(basicResult(delOrg, "Organization deleted."))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
|
||||||
|
case GET -> Root / Ident(id) =>
|
||||||
|
(for {
|
||||||
|
org <- OptionT(backend.organization.findOrg(user.account, id))
|
||||||
|
resp <- OptionT.liftF(Ok(mkOrg(org)))
|
||||||
|
} yield resp).getOrElseF(NotFound())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package docspell.restserver.routes
|
package docspell.restserver.routes
|
||||||
|
|
||||||
|
import cats.data.OptionT
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
import cats.implicits._
|
import cats.implicits._
|
||||||
|
|
||||||
@ -59,6 +60,12 @@ object PersonRoutes {
|
|||||||
delOrg <- backend.organization.deletePerson(id, user.account.collective)
|
delOrg <- backend.organization.deletePerson(id, user.account.collective)
|
||||||
resp <- Ok(basicResult(delOrg, "Person deleted."))
|
resp <- Ok(basicResult(delOrg, "Person deleted."))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
|
||||||
|
case GET -> Root / Ident(id) =>
|
||||||
|
(for {
|
||||||
|
org <- OptionT(backend.organization.findPerson(user.account, id))
|
||||||
|
resp <- OptionT.liftF(Ok(mkPerson(org)))
|
||||||
|
} yield resp).getOrElseF(NotFound())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(
|
def findPersonAndContact(
|
||||||
coll: Ident,
|
coll: Ident,
|
||||||
query: Option[String],
|
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(
|
def findPersonByContact(
|
||||||
coll: Ident,
|
coll: Ident,
|
||||||
value: String,
|
value: String,
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package docspell.store.records
|
package docspell.store.records
|
||||||
|
|
||||||
|
import cats.data.NonEmptyList
|
||||||
|
|
||||||
import docspell.common._
|
import docspell.common._
|
||||||
import docspell.store.impl.Implicits._
|
import docspell.store.impl.Implicits._
|
||||||
import cats.data.NonEmptyList
|
|
||||||
import doobie._
|
import doobie._
|
||||||
import doobie.implicits._
|
import doobie.implicits._
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user