mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-05-28 11:09:15 +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
|
collective: Ident
|
||||||
): F[UpdateResult]
|
): 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. */
|
/** 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]
|
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(
|
def toggleTags(
|
||||||
item: Ident,
|
item: Ident,
|
||||||
tags: List[String],
|
tags: List[String],
|
||||||
|
@ -1945,6 +1945,29 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/BasicResult"
|
$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:
|
put:
|
||||||
tags:
|
tags:
|
||||||
- Item (Multi Edit)
|
- Item (Multi Edit)
|
||||||
|
@ -73,6 +73,18 @@ object ItemMultiRoutes {
|
|||||||
resp <- Ok(Conversions.basicResult(res, "Tags added."))
|
resp <- Ok(Conversions.basicResult(res, "Tags added."))
|
||||||
} yield resp
|
} 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" =>
|
case req @ PUT -> Root / "name" =>
|
||||||
for {
|
for {
|
||||||
json <- req.as[ItemsAndName]
|
json <- req.as[ItemsAndName]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user