mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
More mutations
This commit is contained in:
@@ -28,7 +28,7 @@ class ChapterMutation {
|
|||||||
val chapter: ChapterType
|
val chapter: ChapterType
|
||||||
)
|
)
|
||||||
data class UpdateChapterInput(
|
data class UpdateChapterInput(
|
||||||
val clientMutationId: String?,
|
val clientMutationId: String? = null,
|
||||||
val id: Int,
|
val id: Int,
|
||||||
val patch: UpdateChapterPatch
|
val patch: UpdateChapterPatch
|
||||||
)
|
)
|
||||||
@@ -38,7 +38,7 @@ class ChapterMutation {
|
|||||||
val chapters: List<ChapterType>
|
val chapters: List<ChapterType>
|
||||||
)
|
)
|
||||||
data class UpdateChaptersInput(
|
data class UpdateChaptersInput(
|
||||||
val clientMutationId: String?,
|
val clientMutationId: String? = null,
|
||||||
val ids: List<Int>,
|
val ids: List<Int>,
|
||||||
val patch: UpdateChapterPatch
|
val patch: UpdateChapterPatch
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package suwayomi.tachidesk.graphql.mutations
|
||||||
|
|
||||||
|
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||||
|
import com.expediagroup.graphql.server.extensions.getValuesFromDataLoader
|
||||||
|
import graphql.schema.DataFetchingEnvironment
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import org.jetbrains.exposed.sql.update
|
||||||
|
import suwayomi.tachidesk.graphql.types.MangaType
|
||||||
|
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||||
|
import java.util.concurrent.CompletableFuture
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO Mutations
|
||||||
|
* - Add to category
|
||||||
|
* - Remove from category
|
||||||
|
* - Check for updates
|
||||||
|
* - Download x(all = -1) chapters
|
||||||
|
* - Delete read/all downloaded chapters
|
||||||
|
* - Add/update meta
|
||||||
|
* - Delete meta
|
||||||
|
*/
|
||||||
|
class MangaMutation {
|
||||||
|
data class UpdateMangaPatch(
|
||||||
|
val inLibrary: Boolean? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
data class UpdateMangaPayload(
|
||||||
|
val clientMutationId: String?,
|
||||||
|
val manga: MangaType
|
||||||
|
)
|
||||||
|
data class UpdateMangaInput(
|
||||||
|
val clientMutationId: String? = null,
|
||||||
|
val id: Int,
|
||||||
|
val patch: UpdateMangaPatch
|
||||||
|
)
|
||||||
|
|
||||||
|
data class UpdateMangasPayload(
|
||||||
|
val clientMutationId: String?,
|
||||||
|
val mangas: List<MangaType>
|
||||||
|
)
|
||||||
|
data class UpdateMangasInput(
|
||||||
|
val clientMutationId: String?? = null,
|
||||||
|
val ids: List<Int>,
|
||||||
|
val patch: UpdateMangaPatch
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun updateMangas(ids: List<Int>, patch: UpdateMangaPatch) {
|
||||||
|
transaction {
|
||||||
|
if (patch.inLibrary != null) {
|
||||||
|
MangaTable.update({ MangaTable.id inList ids }) { update ->
|
||||||
|
patch.inLibrary.also {
|
||||||
|
update[inLibrary] = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateManga(dataFetchingEnvironment: DataFetchingEnvironment, input: UpdateMangaInput): CompletableFuture<UpdateMangaPayload> {
|
||||||
|
val (clientMutationId, id, patch) = input
|
||||||
|
|
||||||
|
updateMangas(listOf(id), patch)
|
||||||
|
|
||||||
|
return dataFetchingEnvironment.getValueFromDataLoader<Int, MangaType>("MangaDataLoader", id).thenApply { manga ->
|
||||||
|
UpdateMangaPayload(
|
||||||
|
clientMutationId = clientMutationId,
|
||||||
|
manga = manga
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateMangas(dataFetchingEnvironment: DataFetchingEnvironment, input: UpdateMangasInput): CompletableFuture<UpdateMangasPayload> {
|
||||||
|
val (clientMutationId, ids, patch) = input
|
||||||
|
|
||||||
|
updateMangas(ids, patch)
|
||||||
|
|
||||||
|
return dataFetchingEnvironment.getValuesFromDataLoader<Int, MangaType>("MangaDataLoader", ids).thenApply { mangas ->
|
||||||
|
UpdateMangasPayload(
|
||||||
|
clientMutationId = clientMutationId,
|
||||||
|
mangas = mangas
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,17 +45,6 @@ import java.util.concurrent.CompletableFuture
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO Queries
|
* TODO Queries
|
||||||
*
|
|
||||||
* TODO Mutations
|
|
||||||
* - Favorite
|
|
||||||
* - Unfavorite
|
|
||||||
* - Add to category
|
|
||||||
* - Remove from category
|
|
||||||
* - Check for updates
|
|
||||||
* - Download x(all = -1) chapters
|
|
||||||
* - Delete read/all downloaded chapters
|
|
||||||
* - Add/update meta
|
|
||||||
* - Delete meta
|
|
||||||
*/
|
*/
|
||||||
class MangaQuery {
|
class MangaQuery {
|
||||||
fun manga(dataFetchingEnvironment: DataFetchingEnvironment, id: Int): CompletableFuture<MangaType?> {
|
fun manga(dataFetchingEnvironment: DataFetchingEnvironment, id: Int): CompletableFuture<MangaType?> {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.expediagroup.graphql.generator.hooks.FlowSubscriptionSchemaGeneratorH
|
|||||||
import com.expediagroup.graphql.generator.toSchema
|
import com.expediagroup.graphql.generator.toSchema
|
||||||
import graphql.schema.GraphQLType
|
import graphql.schema.GraphQLType
|
||||||
import suwayomi.tachidesk.graphql.mutations.ChapterMutation
|
import suwayomi.tachidesk.graphql.mutations.ChapterMutation
|
||||||
|
import suwayomi.tachidesk.graphql.mutations.MangaMutation
|
||||||
import suwayomi.tachidesk.graphql.queries.CategoryQuery
|
import suwayomi.tachidesk.graphql.queries.CategoryQuery
|
||||||
import suwayomi.tachidesk.graphql.queries.ChapterQuery
|
import suwayomi.tachidesk.graphql.queries.ChapterQuery
|
||||||
import suwayomi.tachidesk.graphql.queries.ExtensionQuery
|
import suwayomi.tachidesk.graphql.queries.ExtensionQuery
|
||||||
@@ -49,7 +50,8 @@ val schema = toSchema(
|
|||||||
TopLevelObject(MetaQuery())
|
TopLevelObject(MetaQuery())
|
||||||
),
|
),
|
||||||
mutations = listOf(
|
mutations = listOf(
|
||||||
TopLevelObject(ChapterMutation())
|
TopLevelObject(ChapterMutation()),
|
||||||
|
TopLevelObject(MangaMutation())
|
||||||
),
|
),
|
||||||
subscriptions = listOf(
|
subscriptions = listOf(
|
||||||
TopLevelObject(DownloadSubscription())
|
TopLevelObject(DownloadSubscription())
|
||||||
|
|||||||
Reference in New Issue
Block a user