Allow to remove tags from multiple items

This commit is contained in:
Eike Kettner
2020-10-31 12:03:05 +01:00
parent 51c55f64b9
commit f4c79c72ae
3 changed files with 64 additions and 0 deletions

View File

@ -46,6 +46,12 @@ trait OItem[F[_]] {
collective: Ident
): F[UpdateResult]
def removeTagsMultipleItems(
items: NonEmptyList[Ident],
tags: List[String],
collective: Ident
): F[UpdateResult]
/** Toggles tags of the given item. Tags must exist, but can be IDs or names. */
def toggleTags(item: Ident, tags: List[String], collective: Ident): F[UpdateResult]
@ -225,6 +231,29 @@ object OItem {
}
}
def removeTagsMultipleItems(
items: NonEmptyList[Ident],
tags: List[String],
collective: Ident
): F[UpdateResult] =
tags.distinct match {
case Nil => UpdateResult.success.pure[F]
case ws =>
store.transact {
(for {
itemIds <- OptionT
.liftF(RItem.filterItems(items, collective))
.filter(_.nonEmpty)
given <- OptionT.liftF(RTag.findAllByNameOrId(ws, collective))
_ <- OptionT.liftF(
itemIds.traverse(item =>
RTagItem.removeAllTags(item, given.map(_.tagId).toList)
)
)
} yield UpdateResult.success).getOrElse(UpdateResult.notFound)
}
}
def toggleTags(
item: Ident,
tags: List[String],