mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -05:00
Query for mangas in specific categories (#712)
This commit is contained in:
@@ -44,6 +44,7 @@ import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
|
|||||||
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
||||||
import suwayomi.tachidesk.graphql.types.MangaNodeList
|
import suwayomi.tachidesk.graphql.types.MangaNodeList
|
||||||
import suwayomi.tachidesk.graphql.types.MangaType
|
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.MangaStatus
|
||||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||||
import java.util.concurrent.CompletableFuture
|
import java.util.concurrent.CompletableFuture
|
||||||
@@ -110,6 +111,7 @@ class MangaQuery {
|
|||||||
val realUrl: String? = null,
|
val realUrl: String? = null,
|
||||||
val lastFetchedAt: Long? = null,
|
val lastFetchedAt: Long? = null,
|
||||||
val chaptersLastFetchedAt: Long? = null,
|
val chaptersLastFetchedAt: Long? = null,
|
||||||
|
val categoryIds: List<Int>? = null,
|
||||||
) : HasGetOp {
|
) : HasGetOp {
|
||||||
override fun getOp(): Op<Boolean>? {
|
override fun getOp(): Op<Boolean>? {
|
||||||
val opAnd = OpAnd()
|
val opAnd = OpAnd()
|
||||||
@@ -129,6 +131,7 @@ class MangaQuery {
|
|||||||
opAnd.eq(realUrl, MangaTable.realUrl)
|
opAnd.eq(realUrl, MangaTable.realUrl)
|
||||||
opAnd.eq(lastFetchedAt, MangaTable.lastFetchedAt)
|
opAnd.eq(lastFetchedAt, MangaTable.lastFetchedAt)
|
||||||
opAnd.eq(chaptersLastFetchedAt, MangaTable.chaptersLastFetchedAt)
|
opAnd.eq(chaptersLastFetchedAt, MangaTable.chaptersLastFetchedAt)
|
||||||
|
opAnd.inList(categoryIds, CategoryMangaTable.category)
|
||||||
|
|
||||||
return opAnd.op
|
return opAnd.op
|
||||||
}
|
}
|
||||||
@@ -179,6 +182,7 @@ class MangaQuery {
|
|||||||
val realUrl: StringFilter? = null,
|
val realUrl: StringFilter? = null,
|
||||||
val lastFetchedAt: LongFilter? = null,
|
val lastFetchedAt: LongFilter? = null,
|
||||||
val chaptersLastFetchedAt: LongFilter? = null,
|
val chaptersLastFetchedAt: LongFilter? = null,
|
||||||
|
val categoryId: IntFilter? = null,
|
||||||
override val and: List<MangaFilter>? = null,
|
override val and: List<MangaFilter>? = null,
|
||||||
override val or: List<MangaFilter>? = null,
|
override val or: List<MangaFilter>? = null,
|
||||||
override val not: MangaFilter? = null,
|
override val not: MangaFilter? = null,
|
||||||
@@ -201,6 +205,7 @@ class MangaQuery {
|
|||||||
andFilterWithCompareString(MangaTable.realUrl, realUrl),
|
andFilterWithCompareString(MangaTable.realUrl, realUrl),
|
||||||
andFilterWithCompare(MangaTable.lastFetchedAt, lastFetchedAt),
|
andFilterWithCompare(MangaTable.lastFetchedAt, lastFetchedAt),
|
||||||
andFilterWithCompare(MangaTable.chaptersLastFetchedAt, chaptersLastFetchedAt),
|
andFilterWithCompare(MangaTable.chaptersLastFetchedAt, chaptersLastFetchedAt),
|
||||||
|
andFilterWithCompareEntity(CategoryMangaTable.category, categoryId),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,7 +223,7 @@ class MangaQuery {
|
|||||||
): MangaNodeList {
|
): MangaNodeList {
|
||||||
val queryResults =
|
val queryResults =
|
||||||
transaction {
|
transaction {
|
||||||
val res = MangaTable.selectAll()
|
val res = MangaTable.leftJoin(CategoryMangaTable).selectAll()
|
||||||
|
|
||||||
res.applyOps(condition, filter)
|
res.applyOps(condition, filter)
|
||||||
|
|
||||||
|
|||||||
@@ -382,6 +382,15 @@ class OpAnd(var op: Op<Boolean>? = null) {
|
|||||||
op = if (op == null) expr else (op!! and expr)
|
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(
|
fun <T> eq(
|
||||||
value: T?,
|
value: T?,
|
||||||
column: Column<T>,
|
column: Column<T>,
|
||||||
@@ -392,10 +401,22 @@ class OpAnd(var op: Op<Boolean>? = null) {
|
|||||||
column: Column<EntityID<T>>,
|
column: Column<EntityID<T>>,
|
||||||
) = andWhere(value) { column eq it }
|
) = 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(
|
fun like(
|
||||||
value: String?,
|
value: String?,
|
||||||
column: Column<String?>,
|
column: Column<String?>,
|
||||||
) = andWhere(value) { column like it }
|
) = andWhere(value) { column like it }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : Comparable<T>> andFilterWithCompare(
|
fun <T : Comparable<T>> andFilterWithCompare(
|
||||||
|
|||||||
Reference in New Issue
Block a user