mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-03-25 16:45:05 +00:00
Allow to remove tags from multiple items
This commit is contained in:
parent
51c55f64b9
commit
f4c79c72ae
@ -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],
|
||||
|
@ -1945,6 +1945,29 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
|
||||
/sec/items/tagsremove:
|
||||
post:
|
||||
tags:
|
||||
- Item (Multi Edit)
|
||||
summary: Remove tags from multiple items
|
||||
description: |
|
||||
Remove the given tags from all given items.
|
||||
security:
|
||||
- authTokenHeader: []
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ItemsAndRefs"
|
||||
responses:
|
||||
200:
|
||||
description: Ok
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
|
||||
put:
|
||||
tags:
|
||||
- Item (Multi Edit)
|
||||
|
@ -73,6 +73,18 @@ object ItemMultiRoutes {
|
||||
resp <- Ok(Conversions.basicResult(res, "Tags added."))
|
||||
} yield resp
|
||||
|
||||
case req @ POST -> Root / "tagsremove" =>
|
||||
for {
|
||||
json <- req.as[ItemsAndRefs]
|
||||
items <- readIds[F](json.items)
|
||||
res <- backend.item.removeTagsMultipleItems(
|
||||
items,
|
||||
json.refs,
|
||||
user.account.collective
|
||||
)
|
||||
resp <- Ok(Conversions.basicResult(res, "Tags removed"))
|
||||
} yield resp
|
||||
|
||||
case req @ PUT -> Root / "name" =>
|
||||
for {
|
||||
json <- req.as[ItemsAndName]
|
||||
|
Loading…
x
Reference in New Issue
Block a user