mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-07 15:45:59 +00:00
Add route to create and associate correspondent org
This commit is contained in:
parent
459647f83f
commit
c6accca0ff
@ -53,6 +53,8 @@ trait OItem[F[_]] {
|
|||||||
|
|
||||||
def setCorrOrg(item: Ident, org: Option[Ident], collective: Ident): F[AddResult]
|
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 setCorrPerson(item: Ident, person: Option[Ident], collective: Ident): F[AddResult]
|
||||||
|
|
||||||
def setConcPerson(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]] =
|
def apply[F[_]: Effect](store: Store[F]): Resource[F, OItem[F]] =
|
||||||
for {
|
for {
|
||||||
otag <- OTag(store)
|
otag <- OTag(store)
|
||||||
|
oorg <- OOrganization(store)
|
||||||
oitem <- Resource.pure[F, OItem[F]](new OItem[F] {
|
oitem <- Resource.pure[F, OItem[F]](new OItem[F] {
|
||||||
def moveAttachmentBefore(
|
def moveAttachmentBefore(
|
||||||
itemId: Ident,
|
itemId: Ident,
|
||||||
@ -282,6 +285,26 @@ object OItem {
|
|||||||
.attempt
|
.attempt
|
||||||
.map(AddResult.fromUpdate)
|
.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(
|
def setCorrPerson(
|
||||||
item: Ident,
|
item: Ident,
|
||||||
person: Option[Ident],
|
person: Option[Ident],
|
||||||
|
@ -1150,6 +1150,28 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/BasicResult"
|
$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:
|
/sec/item/{id}/corrPerson:
|
||||||
put:
|
put:
|
||||||
tags: [ Item ]
|
tags: [ Item ]
|
||||||
|
@ -100,6 +100,14 @@ object ItemRoutes {
|
|||||||
resp <- Ok(Conversions.basicResult(res, "Correspondent organization updated"))
|
resp <- Ok(Conversions.basicResult(res, "Correspondent organization updated"))
|
||||||
} yield resp
|
} 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" =>
|
case req @ PUT -> Root / Ident(id) / "corrPerson" =>
|
||||||
for {
|
for {
|
||||||
idref <- req.as[OptionalId]
|
idref <- req.as[OptionalId]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user