Add remaining routes to create and update item meta data

This commit is contained in:
Eike Kettner 2020-06-11 22:28:31 +02:00
parent a4d60c0d92
commit 363eb81aff
3 changed files with 167 additions and 2 deletions

View File

@ -57,10 +57,16 @@ trait OItem[F[_]] {
def setCorrPerson(item: Ident, person: Option[Ident], collective: Ident): F[AddResult] def setCorrPerson(item: Ident, person: Option[Ident], collective: Ident): F[AddResult]
def addCorrPerson(item: Ident, person: OOrganization.PersonAndContacts): F[AddResult]
def setConcPerson(item: Ident, person: Option[Ident], collective: Ident): F[AddResult] def setConcPerson(item: Ident, person: Option[Ident], collective: Ident): F[AddResult]
def addConcPerson(item: Ident, person: OOrganization.PersonAndContacts): F[AddResult]
def setConcEquip(item: Ident, equip: Option[Ident], collective: Ident): F[AddResult] def setConcEquip(item: Ident, equip: Option[Ident], collective: Ident): F[AddResult]
def addConcEquip(item: Ident, equip: REquipment): F[AddResult]
def setNotes(item: Ident, notes: Option[String], collective: Ident): F[AddResult] def setNotes(item: Ident, notes: Option[String], collective: Ident): F[AddResult]
def setName(item: Ident, notes: String, collective: Ident): F[AddResult] def setName(item: Ident, notes: String, collective: Ident): F[AddResult]
@ -141,6 +147,7 @@ object OItem {
for { for {
otag <- OTag(store) otag <- OTag(store)
oorg <- OOrganization(store) oorg <- OOrganization(store)
oequip <- OEquipment(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,
@ -315,6 +322,30 @@ object OItem {
.attempt .attempt
.map(AddResult.fromUpdate) .map(AddResult.fromUpdate)
def addCorrPerson(
item: Ident,
person: OOrganization.PersonAndContacts
): F[AddResult] =
(for {
_ <- OptionT(store.transact(RItem.getCollective(item)))
.filter(_ == person.person.cid)
addres <- OptionT.liftF(oorg.addPerson(person))
_ <- addres match {
case AddResult.Success =>
OptionT.liftF(
store.transact(
RItem
.updateCorrPerson(item, person.person.cid, Some(person.person.pid))
)
)
case AddResult.EntityExists(_) =>
OptionT.pure[F](0)
case AddResult.Failure(_) =>
OptionT.pure[F](0)
}
} yield addres)
.getOrElse(AddResult.Failure(new Exception("Collective mismatch")))
def setConcPerson( def setConcPerson(
item: Ident, item: Ident,
person: Option[Ident], person: Option[Ident],
@ -325,6 +356,30 @@ object OItem {
.attempt .attempt
.map(AddResult.fromUpdate) .map(AddResult.fromUpdate)
def addConcPerson(
item: Ident,
person: OOrganization.PersonAndContacts
): F[AddResult] =
(for {
_ <- OptionT(store.transact(RItem.getCollective(item)))
.filter(_ == person.person.cid)
addres <- OptionT.liftF(oorg.addPerson(person))
_ <- addres match {
case AddResult.Success =>
OptionT.liftF(
store.transact(
RItem
.updateConcPerson(item, person.person.cid, Some(person.person.pid))
)
)
case AddResult.EntityExists(_) =>
OptionT.pure[F](0)
case AddResult.Failure(_) =>
OptionT.pure[F](0)
}
} yield addres)
.getOrElse(AddResult.Failure(new Exception("Collective mismatch")))
def setConcEquip( def setConcEquip(
item: Ident, item: Ident,
equip: Option[Ident], equip: Option[Ident],
@ -335,6 +390,26 @@ object OItem {
.attempt .attempt
.map(AddResult.fromUpdate) .map(AddResult.fromUpdate)
def addConcEquip(item: Ident, equip: REquipment): F[AddResult] =
(for {
_ <- OptionT(store.transact(RItem.getCollective(item)))
.filter(_ == equip.cid)
addres <- OptionT.liftF(oequip.add(equip))
_ <- addres match {
case AddResult.Success =>
OptionT.liftF(
store.transact(
RItem.updateConcEquip(item, equip.cid, Some(equip.eid))
)
)
case AddResult.EntityExists(_) =>
OptionT.pure[F](0)
case AddResult.Failure(_) =>
OptionT.pure[F](0)
}
} yield addres)
.getOrElse(AddResult.Failure(new Exception("Collective mismatch")))
def setNotes( def setNotes(
item: Ident, item: Ident,
notes: Option[String], notes: Option[String],

View File

@ -1194,6 +1194,28 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/BasicResult" $ref: "#/components/schemas/BasicResult"
post:
tags: [ Item ]
summary: Create and set the correspondent person of an item.
description: |
Creates a new person and updates the correspondent person of
an item.
security:
- authTokenHeader: []
parameters:
- $ref: "#/components/parameters/id"
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Person"
responses:
200:
description: Ok
content:
application/json:
schema:
$ref: "#/components/schemas/BasicResult"
/sec/item/{id}/concPerson: /sec/item/{id}/concPerson:
put: put:
tags: [ Item ] tags: [ Item ]
@ -1216,6 +1238,28 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/BasicResult" $ref: "#/components/schemas/BasicResult"
post:
tags: [ Item ]
summary: Create and set the concerning person of an item.
description: |
Creates a new person and updates the concerning person of an
item.
security:
- authTokenHeader: []
parameters:
- $ref: "#/components/parameters/id"
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Person"
responses:
200:
description: Ok
content:
application/json:
schema:
$ref: "#/components/schemas/BasicResult"
/sec/item/{id}/concEquipment: /sec/item/{id}/concEquipment:
put: put:
tags: [ Item ] tags: [ Item ]
@ -1238,6 +1282,28 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/BasicResult" $ref: "#/components/schemas/BasicResult"
post:
tags: [ Item ]
summary: Create and set a new the concering equipment of an item.
description: |
Creates a new equipment and sets it as the concering equipment
of an item.
security:
- authTokenHeader: []
parameters:
- $ref: "#/components/parameters/id"
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Equipment"
responses:
200:
description: Ok
content:
application/json:
schema:
$ref: "#/components/schemas/BasicResult"
/sec/item/{id}/notes: /sec/item/{id}/notes:
put: put:
tags: [ Item ] tags: [ Item ]

View File

@ -115,6 +115,14 @@ object ItemRoutes {
resp <- Ok(Conversions.basicResult(res, "Correspondent person updated")) resp <- Ok(Conversions.basicResult(res, "Correspondent person updated"))
} yield resp } yield resp
case req @ POST -> Root / Ident(id) / "corrPerson" =>
for {
data <- req.as[Person]
pers <- Conversions.newPerson(data, user.account.collective)
res <- backend.item.addCorrPerson(id, pers)
resp <- Ok(Conversions.basicResult(res, "Correspondent person updated"))
} yield resp
case req @ PUT -> Root / Ident(id) / "concPerson" => case req @ PUT -> Root / Ident(id) / "concPerson" =>
for { for {
idref <- req.as[OptionalId] idref <- req.as[OptionalId]
@ -122,6 +130,14 @@ object ItemRoutes {
resp <- Ok(Conversions.basicResult(res, "Concerned person updated")) resp <- Ok(Conversions.basicResult(res, "Concerned person updated"))
} yield resp } yield resp
case req @ POST -> Root / Ident(id) / "concPerson" =>
for {
data <- req.as[Person]
pers <- Conversions.newPerson(data, user.account.collective)
res <- backend.item.addConcPerson(id, pers)
resp <- Ok(Conversions.basicResult(res, "Concerned person updated"))
} yield resp
case req @ PUT -> Root / Ident(id) / "concEquipment" => case req @ PUT -> Root / Ident(id) / "concEquipment" =>
for { for {
idref <- req.as[OptionalId] idref <- req.as[OptionalId]
@ -129,6 +145,14 @@ object ItemRoutes {
resp <- Ok(Conversions.basicResult(res, "Concerned equipment updated")) resp <- Ok(Conversions.basicResult(res, "Concerned equipment updated"))
} yield resp } yield resp
case req @ POST -> Root / Ident(id) / "concEquipment" =>
for {
data <- req.as[Equipment]
equip <- Conversions.newEquipment(data, user.account.collective)
res <- backend.item.addConcEquip(id, equip)
resp <- Ok(Conversions.basicResult(res, "Concerned equipment updated"))
} yield resp
case req @ PUT -> Root / Ident(id) / "notes" => case req @ PUT -> Root / Ident(id) / "notes" =>
for { for {
text <- req.as[OptionalText] text <- req.as[OptionalText]