From 05b5a7f598723f30fd5c8a0b783900a1aed6661d Mon Sep 17 00:00:00 2001 From: Syer10 Date: Fri, 31 Mar 2023 23:03:26 -0400 Subject: [PATCH] Add updates --- .../tachidesk/graphql/queries/UpdatesQuery.kt | 48 +++++++++++++++++++ .../graphql/server/TachideskGraphQLSchema.kt | 4 +- .../tachidesk/graphql/types/UpdatesType.kt | 20 ++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/UpdatesQuery.kt create mode 100644 server/src/main/kotlin/suwayomi/tachidesk/graphql/types/UpdatesType.kt diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/UpdatesQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/UpdatesQuery.kt new file mode 100644 index 00000000..afb5ae72 --- /dev/null +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/UpdatesQuery.kt @@ -0,0 +1,48 @@ +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +package suwayomi.tachidesk.graphql.queries + +import org.jetbrains.exposed.sql.SortOrder +import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater +import org.jetbrains.exposed.sql.and +import org.jetbrains.exposed.sql.select +import org.jetbrains.exposed.sql.transactions.transaction +import suwayomi.tachidesk.graphql.types.UpdatesType +import suwayomi.tachidesk.manga.model.dataclass.PaginationFactor +import suwayomi.tachidesk.manga.model.table.ChapterTable +import suwayomi.tachidesk.manga.model.table.MangaTable + +/** + * TODO Queries + * + * TODO Mutations + * - Update the library + * - Update a category + * - Reset updater + * + */ +class UpdatesQuery { + data class UpdatesQueryInput( + val page: Int + ) + + fun updates(input: UpdatesQueryInput): List { + val results = transaction { + ChapterTable.innerJoin(MangaTable) + .select { (MangaTable.inLibrary eq true) and (ChapterTable.fetchedAt greater MangaTable.inLibraryAt) } + .orderBy(ChapterTable.fetchedAt to SortOrder.DESC) + .limit(PaginationFactor, (input.page - 1L) * PaginationFactor) + .map { + UpdatesType(it) + } + } + + return results + } +} diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt index 92e0d2a5..af87d63e 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt @@ -20,6 +20,7 @@ import suwayomi.tachidesk.graphql.queries.ExtensionQuery import suwayomi.tachidesk.graphql.queries.MangaQuery import suwayomi.tachidesk.graphql.queries.MetaQuery import suwayomi.tachidesk.graphql.queries.SourceQuery +import suwayomi.tachidesk.graphql.queries.UpdatesQuery import suwayomi.tachidesk.graphql.subscriptions.DownloadSubscription import kotlin.reflect.KClass import kotlin.reflect.KType @@ -43,7 +44,8 @@ val schema = toSchema( TopLevelObject(CategoryQuery()), TopLevelObject(SourceQuery()), TopLevelObject(ExtensionQuery()), - TopLevelObject(MetaQuery()) + TopLevelObject(MetaQuery()), + TopLevelObject(UpdatesQuery()) ), mutations = listOf( TopLevelObject(ChapterMutation()) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/UpdatesType.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/UpdatesType.kt new file mode 100644 index 00000000..2e7d952c --- /dev/null +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/UpdatesType.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +package suwayomi.tachidesk.graphql.types + +import org.jetbrains.exposed.sql.ResultRow + +class UpdatesType( + val manga: MangaType, + val chapter: ChapterType +) { + constructor(row: ResultRow) : this( + manga = MangaType(row), + chapter = ChapterType(row) + ) +}