Skip to content

Commit c84cab3

Browse files
committed
Query for mangas in specific categories
1 parent a449a01 commit c84cab3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
4444
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
4545
import suwayomi.tachidesk.graphql.types.MangaNodeList
4646
import suwayomi.tachidesk.graphql.types.MangaType
47+
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
4748
import suwayomi.tachidesk.manga.model.table.MangaStatus
4849
import suwayomi.tachidesk.manga.model.table.MangaTable
4950
import java.util.concurrent.CompletableFuture
@@ -110,6 +111,7 @@ class MangaQuery {
110111
val realUrl: String? = null,
111112
val lastFetchedAt: Long? = null,
112113
val chaptersLastFetchedAt: Long? = null,
114+
val categoryIds: List<Int>? = null,
113115
) : HasGetOp {
114116
override fun getOp(): Op<Boolean>? {
115117
val opAnd = OpAnd()
@@ -129,6 +131,7 @@ class MangaQuery {
129131
opAnd.eq(realUrl, MangaTable.realUrl)
130132
opAnd.eq(lastFetchedAt, MangaTable.lastFetchedAt)
131133
opAnd.eq(chaptersLastFetchedAt, MangaTable.chaptersLastFetchedAt)
134+
opAnd.inList(categoryIds, CategoryMangaTable.category)
132135

133136
return opAnd.op
134137
}
@@ -179,6 +182,7 @@ class MangaQuery {
179182
val realUrl: StringFilter? = null,
180183
val lastFetchedAt: LongFilter? = null,
181184
val chaptersLastFetchedAt: LongFilter? = null,
185+
val categoryId: IntFilter? = null,
182186
override val and: List<MangaFilter>? = null,
183187
override val or: List<MangaFilter>? = null,
184188
override val not: MangaFilter? = null,
@@ -200,6 +204,7 @@ class MangaQuery {
200204
andFilterWithCompareString(MangaTable.realUrl, realUrl),
201205
andFilterWithCompare(MangaTable.lastFetchedAt, lastFetchedAt),
202206
andFilterWithCompare(MangaTable.chaptersLastFetchedAt, chaptersLastFetchedAt),
207+
andFilterWithCompareEntity(CategoryMangaTable.category, categoryId),
203208
)
204209
}
205210
}
@@ -217,7 +222,7 @@ class MangaQuery {
217222
): MangaNodeList {
218223
val queryResults =
219224
transaction {
220-
val res = MangaTable.selectAll()
225+
val res = MangaTable.leftJoin(CategoryMangaTable).selectAll()
221226

222227
res.applyOps(condition, filter)
223228

server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/filter/Filter.kt

+20
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,15 @@ class OpAnd(var op: Op<Boolean>? = null) {
382382
op = if (op == null) expr else (op!! and expr)
383383
}
384384

385+
fun <T : Any> andWhere(
386+
values: List<T>?,
387+
andPart: SqlExpressionBuilder.(List<T>) -> Op<Boolean>,
388+
) {
389+
values ?: return
390+
val expr = Op.build { andPart(values) }
391+
op = if (op == null) expr else (op!! and expr)
392+
}
393+
385394
fun <T> eq(
386395
value: T?,
387396
column: Column<T>,
@@ -391,6 +400,17 @@ class OpAnd(var op: Op<Boolean>? = null) {
391400
value: T?,
392401
column: Column<EntityID<T>>,
393402
) = andWhere(value) { column eq it }
403+
404+
fun <T> inList(
405+
values: List<T>?,
406+
column: Column<T>,
407+
) = andWhere(values) { column inList it }
408+
409+
@JvmName("inListComparable")
410+
fun <T : Comparable<T>> inList(
411+
values: List<T>?,
412+
column: Column<EntityID<T>>,
413+
) = andWhere(values) { column inList it }
394414
}
395415

396416
fun <T : Comparable<T>> andFilterWithCompare(

0 commit comments

Comments
 (0)