mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-07 06:39:32 +00:00
Add route to create and associate correspondent org
This commit is contained in:
parent
459647f83f
commit
c6accca0ff
modules
backend/src/main/scala/docspell/backend/ops
restapi/src/main/resources
restserver/src/main/scala/docspell/restserver/routes
@ -53,6 +53,8 @@ trait OItem[F[_]] {
|
||||
|
||||
def setCorrOrg(item: Ident, org: Option[Ident], collective: Ident): F[AddResult]
|
||||
|
||||
def addCorrOrg(item: Ident, org: OOrganization.OrgAndContacts): F[AddResult]
|
||||
|
||||
def setCorrPerson(item: Ident, person: Option[Ident], collective: Ident): F[AddResult]
|
||||
|
||||
def setConcPerson(item: Ident, person: Option[Ident], collective: Ident): F[AddResult]
|
||||
@ -138,6 +140,7 @@ object OItem {
|
||||
def apply[F[_]: Effect](store: Store[F]): Resource[F, OItem[F]] =
|
||||
for {
|
||||
otag <- OTag(store)
|
||||
oorg <- OOrganization(store)
|
||||
oitem <- Resource.pure[F, OItem[F]](new OItem[F] {
|
||||
def moveAttachmentBefore(
|
||||
itemId: Ident,
|
||||
@ -282,6 +285,26 @@ object OItem {
|
||||
.attempt
|
||||
.map(AddResult.fromUpdate)
|
||||
|
||||
def addCorrOrg(item: Ident, org: OOrganization.OrgAndContacts): F[AddResult] =
|
||||
(for {
|
||||
_ <- OptionT(store.transact(RItem.getCollective(item)))
|
||||
.filter(_ == org.org.cid)
|
||||
addres <- OptionT.liftF(oorg.addOrg(org))
|
||||
_ <- addres match {
|
||||
case AddResult.Success =>
|
||||
OptionT.liftF(
|
||||
store.transact(
|
||||
RItem.updateCorrOrg(item, org.org.cid, Some(org.org.oid))
|
||||
)
|
||||
)
|
||||
case AddResult.EntityExists(_) =>
|
||||
OptionT.pure[F](0)
|
||||
case AddResult.Failure(_) =>
|
||||
OptionT.pure[F](0)
|
||||
}
|
||||
} yield addres)
|
||||
.getOrElse(AddResult.Failure(new Exception("Collective mismatch")))
|
||||
|
||||
def setCorrPerson(
|
||||
item: Ident,
|
||||
person: Option[Ident],
|
||||
|
@ -1150,6 +1150,28 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
post:
|
||||
tags: [ Item ]
|
||||
summary: Set a new correspondent organization of an item.
|
||||
description: |
|
||||
Create a new organization and update the correspondent
|
||||
organization of an item.
|
||||
security:
|
||||
- authTokenHeader: []
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/id"
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Organization"
|
||||
responses:
|
||||
200:
|
||||
description: Ok
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
/sec/item/{id}/corrPerson:
|
||||
put:
|
||||
tags: [ Item ]
|
||||
|
@ -100,6 +100,14 @@ object ItemRoutes {
|
||||
resp <- Ok(Conversions.basicResult(res, "Correspondent organization updated"))
|
||||
} yield resp
|
||||
|
||||
case req @ POST -> Root / Ident(id) / "corrOrg" =>
|
||||
for {
|
||||
data <- req.as[Organization]
|
||||
org <- Conversions.newOrg(data, user.account.collective)
|
||||
res <- backend.item.addCorrOrg(id, org)
|
||||
resp <- Ok(Conversions.basicResult(res, "Correspondent organization updated"))
|
||||
} yield resp
|
||||
|
||||
case req @ PUT -> Root / Ident(id) / "corrPerson" =>
|
||||
for {
|
||||
idref <- req.as[OptionalId]
|
||||
|
Loading…
x
Reference in New Issue
Block a user