Query for mangas in specific categories (#712)

This commit is contained in:
schroda
2023-10-16 02:14:59 +02:00
committed by GitHub
parent 0ba6c88d69
commit e70730e9a8
2 changed files with 27 additions and 1 deletions
@@ -44,6 +44,7 @@ import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
import suwayomi.tachidesk.graphql.types.MangaNodeList
import suwayomi.tachidesk.graphql.types.MangaType
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
import suwayomi.tachidesk.manga.model.table.MangaStatus
import suwayomi.tachidesk.manga.model.table.MangaTable
import java.util.concurrent.CompletableFuture
@@ -110,6 +111,7 @@ class MangaQuery {
val realUrl: String? = null,
val lastFetchedAt: Long? = null,
val chaptersLastFetchedAt: Long? = null,
val categoryIds: List<Int>? = null,
) : HasGetOp {
override fun getOp(): Op<Boolean>? {
val opAnd = OpAnd()
@@ -129,6 +131,7 @@ class MangaQuery {
opAnd.eq(realUrl, MangaTable.realUrl)
opAnd.eq(lastFetchedAt, MangaTable.lastFetchedAt)
opAnd.eq(chaptersLastFetchedAt, MangaTable.chaptersLastFetchedAt)
opAnd.inList(categoryIds, CategoryMangaTable.category)
return opAnd.op
}
@@ -179,6 +182,7 @@ class MangaQuery {
val realUrl: StringFilter? = null,
val lastFetchedAt: LongFilter? = null,
val chaptersLastFetchedAt: LongFilter? = null,
val categoryId: IntFilter? = null,
override val and: List<MangaFilter>? = null,
override val or: List<MangaFilter>? = null,
override val not: MangaFilter? = null,
@@ -201,6 +205,7 @@ class MangaQuery {
andFilterWithCompareString(MangaTable.realUrl, realUrl),
andFilterWithCompare(MangaTable.lastFetchedAt, lastFetchedAt),
andFilterWithCompare(MangaTable.chaptersLastFetchedAt, chaptersLastFetchedAt),
andFilterWithCompareEntity(CategoryMangaTable.category, categoryId),
)
}
}
@@ -218,7 +223,7 @@ class MangaQuery {
): MangaNodeList {
val queryResults =
transaction {
val res = MangaTable.selectAll()
val res = MangaTable.leftJoin(CategoryMangaTable).selectAll()
res.applyOps(condition, filter)
@@ -382,6 +382,15 @@ class OpAnd(var op: Op<Boolean>? = null) {
op = if (op == null) expr else (op!! and expr)
}
fun <T : Any> andWhere(
values: List<T>?,
andPart: SqlExpressionBuilder.(List<T>) -> Op<Boolean>,
) {
values ?: return
val expr = Op.build { andPart(values) }
op = if (op == null) expr else (op!! and expr)
}
fun <T> eq(
value: T?,
column: Column<T>,
@@ -392,10 +401,22 @@ class OpAnd(var op: Op<Boolean>? = null) {
column: Column<EntityID<T>>,
) = andWhere(value) { column eq it }
fun <T> inList(
values: List<T>?,
column: Column<T>,
) = andWhere(values) { column inList it }
@JvmName("inListComparable")
fun <T : Comparable<T>> inList(
values: List<T>?,
column: Column<EntityID<T>>,
) = andWhere(values) { column inList it }
fun like(
value: String?,
column: Column<String?>,
) = andWhere(value) { column like it }
}
fun <T : Comparable<T>> andFilterWithCompare(