From 313da995365d41100eec73025d927b0a9f84e275 Mon Sep 17 00:00:00 2001 From: Syer10 Date: Sat, 8 Apr 2023 22:54:56 -0400 Subject: [PATCH] Add in library filter for chapters --- .../tachidesk/graphql/queries/ChapterQuery.kt | 12 ++++++++++++ .../suwayomi/tachidesk/graphql/queries/MangaQuery.kt | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt index 162b9f3d..821639fc 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt @@ -39,6 +39,7 @@ import suwayomi.tachidesk.graphql.server.primitives.maybeSwap import suwayomi.tachidesk.graphql.types.ChapterNodeList import suwayomi.tachidesk.graphql.types.ChapterType import suwayomi.tachidesk.manga.model.table.ChapterTable +import suwayomi.tachidesk.manga.model.table.MangaTable import java.util.concurrent.CompletableFuture /** @@ -164,6 +165,7 @@ class ChapterQuery { val fetchedAt: LongFilter? = null, val isDownloaded: BooleanFilter? = null, val pageCount: IntFilter? = null, + val inLibrary: BooleanFilter? = null, override val and: List? = null, override val or: List? = null, override val not: ChapterFilter? = null @@ -188,6 +190,8 @@ class ChapterQuery { andFilterWithCompare(ChapterTable.pageCount, pageCount) ) } + + fun getLibraryOp() = andFilterWithCompare(MangaTable.inLibrary, inLibrary) } fun chapters( @@ -204,6 +208,14 @@ class ChapterQuery { val queryResults = transaction { val res = ChapterTable.selectAll() + val libraryOp = filter?.getLibraryOp() + if (libraryOp != null) { + res.adjustColumnSet { + innerJoin(MangaTable) + } + res.andWhere { libraryOp } + } + res.applyOps(condition, filter) if (orderBy != null || (last != null || before != null)) { diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt index 95a6f48c..b8375037 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt @@ -15,7 +15,6 @@ import org.jetbrains.exposed.sql.SortOrder import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater import org.jetbrains.exposed.sql.SqlExpressionBuilder.less import org.jetbrains.exposed.sql.andWhere -import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.transactions.transaction import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter @@ -224,12 +223,14 @@ class MangaQuery { offset: Int? = null ): MangaNodeList { val queryResults = transaction { - var res = MangaTable.selectAll() + val res = MangaTable.selectAll() val categoryOp = filter?.getCategoryOp() if (categoryOp != null) { - res = MangaTable.innerJoin(CategoryMangaTable) - .select { categoryOp } + res.adjustColumnSet { + innerJoin(CategoryMangaTable) + } + res.andWhere { categoryOp } } res.applyOps(condition, filter)