mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-10-31 17:50:11 +00:00 
			
		
		
		
	Add remaining routes to create and update item meta data
This commit is contained in:
		| @@ -57,10 +57,16 @@ trait OItem[F[_]] { | ||||
|  | ||||
|   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 addConcPerson(item: Ident, person: OOrganization.PersonAndContacts): 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 setName(item: Ident, notes: String, collective: Ident): F[AddResult] | ||||
| @@ -139,8 +145,9 @@ object OItem { | ||||
|  | ||||
|   def apply[F[_]: Effect](store: Store[F]): Resource[F, OItem[F]] = | ||||
|     for { | ||||
|       otag <- OTag(store) | ||||
|       oorg <- OOrganization(store) | ||||
|       otag   <- OTag(store) | ||||
|       oorg   <- OOrganization(store) | ||||
|       oequip <- OEquipment(store) | ||||
|       oitem <- Resource.pure[F, OItem[F]](new OItem[F] { | ||||
|         def moveAttachmentBefore( | ||||
|             itemId: Ident, | ||||
| @@ -315,6 +322,30 @@ object OItem { | ||||
|             .attempt | ||||
|             .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( | ||||
|             item: Ident, | ||||
|             person: Option[Ident], | ||||
| @@ -325,6 +356,30 @@ object OItem { | ||||
|             .attempt | ||||
|             .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( | ||||
|             item: Ident, | ||||
|             equip: Option[Ident], | ||||
| @@ -335,6 +390,26 @@ object OItem { | ||||
|             .attempt | ||||
|             .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( | ||||
|             item: Ident, | ||||
|             notes: Option[String], | ||||
|   | ||||
| @@ -1194,6 +1194,28 @@ paths: | ||||
|             application/json: | ||||
|               schema: | ||||
|                 $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: | ||||
|     put: | ||||
|       tags: [ Item ] | ||||
| @@ -1216,6 +1238,28 @@ paths: | ||||
|             application/json: | ||||
|               schema: | ||||
|                 $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: | ||||
|     put: | ||||
|       tags: [ Item ] | ||||
| @@ -1238,6 +1282,28 @@ paths: | ||||
|             application/json: | ||||
|               schema: | ||||
|                 $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: | ||||
|     put: | ||||
|       tags: [ Item ] | ||||
|   | ||||
| @@ -115,6 +115,14 @@ object ItemRoutes { | ||||
|           resp  <- Ok(Conversions.basicResult(res, "Correspondent person updated")) | ||||
|         } 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" => | ||||
|         for { | ||||
|           idref <- req.as[OptionalId] | ||||
| @@ -122,6 +130,14 @@ object ItemRoutes { | ||||
|           resp  <- Ok(Conversions.basicResult(res, "Concerned person updated")) | ||||
|         } 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" => | ||||
|         for { | ||||
|           idref <- req.as[OptionalId] | ||||
| @@ -129,6 +145,14 @@ object ItemRoutes { | ||||
|           resp  <- Ok(Conversions.basicResult(res, "Concerned equipment updated")) | ||||
|         } 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" => | ||||
|         for { | ||||
|           text <- req.as[OptionalText] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user