mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Allow tag ids or tag names when replacing tags
This commit is contained in:
@ -24,7 +24,7 @@ import org.log4s.getLogger
|
||||
trait OItem[F[_]] {
|
||||
|
||||
/** Sets the given tags (removing all existing ones). */
|
||||
def setTags(item: Ident, tagIds: List[Ident], collective: Ident): F[UpdateResult]
|
||||
def setTags(item: Ident, tagIds: List[String], collective: Ident): F[UpdateResult]
|
||||
|
||||
/** Sets tags for multiple items. The tags of the items will be
|
||||
* replaced with the given ones. Same as `setTags` but for multiple
|
||||
@ -32,7 +32,7 @@ trait OItem[F[_]] {
|
||||
*/
|
||||
def setTagsMultipleItems(
|
||||
items: NonEmptyList[Ident],
|
||||
tags: List[Ident],
|
||||
tags: List[String],
|
||||
collective: Ident
|
||||
): F[UpdateResult]
|
||||
|
||||
@ -304,19 +304,20 @@ object OItem {
|
||||
|
||||
def setTags(
|
||||
item: Ident,
|
||||
tagIds: List[Ident],
|
||||
tagIds: List[String],
|
||||
collective: Ident
|
||||
): F[UpdateResult] =
|
||||
setTagsMultipleItems(NonEmptyList.of(item), tagIds, collective)
|
||||
|
||||
def setTagsMultipleItems(
|
||||
items: NonEmptyList[Ident],
|
||||
tags: List[Ident],
|
||||
tags: List[String],
|
||||
collective: Ident
|
||||
): F[UpdateResult] =
|
||||
UpdateResult.fromUpdate(store.transact(for {
|
||||
k <- RTagItem.deleteItemTags(items, collective)
|
||||
res <- items.traverse(i => RTagItem.setAllTags(i, tags))
|
||||
k <- RTagItem.deleteItemTags(items, collective)
|
||||
rtags <- RTag.findAllByNameOrId(tags, collective)
|
||||
res <- items.traverse(i => RTagItem.setAllTags(i, rtags.map(_.tagId)))
|
||||
n = res.fold
|
||||
} yield k + n))
|
||||
|
||||
|
Reference in New Issue
Block a user