Add routes to conveniently set/toggle tags

This commit is contained in:
Eike Kettner
2020-08-08 15:03:28 +02:00
parent f86f644365
commit 06ad9ac46c
4 changed files with 110 additions and 0 deletions

View File

@ -55,6 +55,14 @@ object RTagItem {
Vector.empty.pure[ConnectionIO]
}
def removeAllTags(item: Ident, tags: Seq[Ident]): ConnectionIO[Int] =
NonEmptyList.fromList(tags.toList) match {
case None =>
0.pure[ConnectionIO]
case Some(nel) =>
deleteFrom(table, and(itemId.is(item), tagId.isIn(nel))).update.run
}
def setAllTags(item: Ident, tags: Seq[Ident]): ConnectionIO[Int] =
if (tags.isEmpty) 0.pure[ConnectionIO]
else