mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +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],
|
||||
|
Reference in New Issue
Block a user