Exclude tags w/o category from classifying; remove obsolete models

This commit is contained in:
Eike Kettner
2021-01-18 21:48:40 +01:00
parent 3e28ce1254
commit cce8878898
4 changed files with 59 additions and 12 deletions

View File

@ -1,7 +1,7 @@
package docspell.store.records
import cats.effect._
import cats.data.NonEmptyList
import cats.effect._
import cats.implicits._
import docspell.common._
@ -63,6 +63,17 @@ object RClassifierModel {
else 0.pure[ConnectionIO]
} yield n + k
def deleteById(id: Ident): ConnectionIO[Int] =
DML.delete(T, T.id === id)
def deleteAll(ids: List[Ident]): ConnectionIO[Int] =
NonEmptyList.fromList(ids) match {
case Some(nel) =>
DML.delete(T, T.id.in(nel))
case None =>
0.pure[ConnectionIO]
}
def findByName(cid: Ident, name: String): ConnectionIO[Option[RClassifierModel]] =
Select(select(T.all), from(T), T.cid === cid && T.name === name).build
.query[RClassifierModel]
@ -75,4 +86,5 @@ object RClassifierModel {
Select(select(T.all), from(T), T.cid === cid && T.name.in(names)).build
.query[RClassifierModel]
.to[List]
}

View File

@ -148,11 +148,11 @@ object RTag {
).orderBy(T.name.asc).build.query[RTag].to[List]
}
def listCategories(coll: Ident, fallback: String): ConnectionIO[List[String]] =
def listCategories(coll: Ident): ConnectionIO[List[String]] =
Select(
coalesce(T.category.s, lit(fallback)).s,
T.category.s,
from(T),
T.cid === coll
T.cid === coll && T.category.isNotNull
).distinct.build.query[String].to[List]
def delete(tagId: Ident, coll: Ident): ConnectionIO[Int] =