mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-10 22:34:33 -05:00
Rewrite meta and add meta mutations (#556)
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.types.CategoryMetaType
|
||||
import suwayomi.tachidesk.manga.impl.Category
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMetaTable
|
||||
|
||||
/**
|
||||
* TODO Mutations
|
||||
* - Name
|
||||
* - Order
|
||||
* - Default
|
||||
* - Create
|
||||
* - Delete
|
||||
*/
|
||||
class CategoryMutation {
|
||||
data class SetCategoryMetaInput(
|
||||
val clientMutationId: String? = null,
|
||||
val meta: CategoryMetaType
|
||||
)
|
||||
data class SetCategoryMetaPayload(
|
||||
val clientMutationId: String?,
|
||||
val meta: CategoryMetaType
|
||||
)
|
||||
fun setCategoryMeta(
|
||||
input: SetCategoryMetaInput
|
||||
): SetCategoryMetaPayload {
|
||||
val (clientMutationId, meta) = input
|
||||
|
||||
Category.modifyMeta(meta.categoryId, meta.key, meta.value)
|
||||
|
||||
return SetCategoryMetaPayload(clientMutationId, meta)
|
||||
}
|
||||
|
||||
data class DeleteCategoryMetaInput(
|
||||
val clientMutationId: String? = null,
|
||||
val categoryId: Int,
|
||||
val key: String
|
||||
)
|
||||
data class DeleteCategoryMetaPayload(
|
||||
val clientMutationId: String?,
|
||||
val meta: CategoryMetaType?
|
||||
)
|
||||
fun deleteCategoryMeta(
|
||||
input: DeleteCategoryMetaInput
|
||||
): DeleteCategoryMetaPayload {
|
||||
val (clientMutationId, categoryId, key) = input
|
||||
|
||||
val meta = transaction {
|
||||
val meta = CategoryMetaTable.select { (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }
|
||||
.firstOrNull()
|
||||
|
||||
CategoryMetaTable.deleteWhere { (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }
|
||||
|
||||
if (meta != null) {
|
||||
CategoryMetaType(meta)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
return DeleteCategoryMetaPayload(clientMutationId, meta)
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,16 @@ 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.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import suwayomi.tachidesk.graphql.types.ChapterMetaType
|
||||
import suwayomi.tachidesk.graphql.types.ChapterType
|
||||
import suwayomi.tachidesk.manga.impl.Chapter
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterMetaTable
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
import java.time.Instant
|
||||
@@ -15,7 +20,6 @@ import java.util.concurrent.CompletableFuture
|
||||
|
||||
/**
|
||||
* TODO Mutations
|
||||
* - Check for updates?
|
||||
* - Download
|
||||
* - Delete download
|
||||
*/
|
||||
@@ -124,4 +128,52 @@ class ChapterMutation {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class SetChapterMetaInput(
|
||||
val clientMutationId: String? = null,
|
||||
val meta: ChapterMetaType
|
||||
)
|
||||
data class SetChapterMetaPayload(
|
||||
val clientMutationId: String?,
|
||||
val meta: ChapterMetaType
|
||||
)
|
||||
fun setChapterMeta(
|
||||
input: SetChapterMetaInput
|
||||
): SetChapterMetaPayload {
|
||||
val (clientMutationId, meta) = input
|
||||
|
||||
Chapter.modifyChapterMeta(meta.chapterId, meta.key, meta.value)
|
||||
|
||||
return SetChapterMetaPayload(clientMutationId, meta)
|
||||
}
|
||||
|
||||
data class DeleteChapterMetaInput(
|
||||
val clientMutationId: String? = null,
|
||||
val chapterId: Int,
|
||||
val key: String
|
||||
)
|
||||
data class DeleteChapterMetaPayload(
|
||||
val clientMutationId: String?,
|
||||
val meta: ChapterMetaType?
|
||||
)
|
||||
fun deleteChapterMeta(
|
||||
input: DeleteChapterMetaInput
|
||||
): DeleteChapterMetaPayload {
|
||||
val (clientMutationId, chapterId, key) = input
|
||||
|
||||
val meta = transaction {
|
||||
val meta = ChapterMetaTable.select { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
|
||||
.firstOrNull()
|
||||
|
||||
ChapterMetaTable.deleteWhere { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
|
||||
|
||||
if (meta != null) {
|
||||
ChapterMetaType(meta)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
return DeleteChapterMetaPayload(clientMutationId, meta)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
/**
|
||||
* TODO Mutations
|
||||
* - Install
|
||||
* - Update
|
||||
* - Uninstall
|
||||
* - Check for updates (global mutation?)
|
||||
*/
|
||||
class ExtensionMutation
|
||||
@@ -3,12 +3,16 @@ 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.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import suwayomi.tachidesk.graphql.queries.MangaQuery
|
||||
import suwayomi.tachidesk.graphql.types.MangaMetaType
|
||||
import suwayomi.tachidesk.graphql.types.MangaType
|
||||
import suwayomi.tachidesk.manga.impl.Manga
|
||||
import suwayomi.tachidesk.manga.model.table.MangaMetaTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
import java.util.concurrent.CompletableFuture
|
||||
@@ -17,11 +21,8 @@ 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(
|
||||
@@ -112,4 +113,52 @@ class MangaMutation {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class SetMangaMetaInput(
|
||||
val clientMutationId: String? = null,
|
||||
val meta: MangaMetaType
|
||||
)
|
||||
data class SetMangaMetaPayload(
|
||||
val clientMutationId: String?,
|
||||
val meta: MangaMetaType
|
||||
)
|
||||
fun setMangaMeta(
|
||||
input: SetMangaMetaInput
|
||||
): SetMangaMetaPayload {
|
||||
val (clientMutationId, meta) = input
|
||||
|
||||
Manga.modifyMangaMeta(meta.mangaId, meta.key, meta.value)
|
||||
|
||||
return SetMangaMetaPayload(clientMutationId, meta)
|
||||
}
|
||||
|
||||
data class DeleteMangaMetaInput(
|
||||
val clientMutationId: String? = null,
|
||||
val mangaId: Int,
|
||||
val key: String
|
||||
)
|
||||
data class DeleteMangaMetaPayload(
|
||||
val clientMutationId: String?,
|
||||
val meta: MangaMetaType?
|
||||
)
|
||||
fun deleteMangaMeta(
|
||||
input: DeleteMangaMetaInput
|
||||
): DeleteMangaMetaPayload {
|
||||
val (clientMutationId, mangaId, key) = input
|
||||
|
||||
val meta = transaction {
|
||||
val meta = MangaMetaTable.select { (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }
|
||||
.firstOrNull()
|
||||
|
||||
MangaMetaTable.deleteWhere { (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }
|
||||
|
||||
if (meta != null) {
|
||||
MangaMetaType(meta)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
return DeleteMangaMetaPayload(clientMutationId, meta)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.global.impl.GlobalMeta
|
||||
import suwayomi.tachidesk.global.model.table.GlobalMetaTable
|
||||
import suwayomi.tachidesk.graphql.types.GlobalMetaType
|
||||
import suwayomi.tachidesk.manga.model.table.MangaMetaTable
|
||||
|
||||
class MetaMutation {
|
||||
|
||||
data class SetGlobalMetaInput(
|
||||
val clientMutationId: String? = null,
|
||||
val meta: GlobalMetaType
|
||||
)
|
||||
data class SetGlobalMetaPayload(
|
||||
val clientMutationId: String?,
|
||||
val meta: GlobalMetaType
|
||||
)
|
||||
fun setGlobalMeta(
|
||||
input: SetGlobalMetaInput
|
||||
): SetGlobalMetaPayload {
|
||||
val (clientMutationId, meta) = input
|
||||
|
||||
GlobalMeta.modifyMeta(meta.key, meta.value)
|
||||
|
||||
return SetGlobalMetaPayload(clientMutationId, meta)
|
||||
}
|
||||
|
||||
data class DeleteGlobalMetaInput(
|
||||
val clientMutationId: String? = null,
|
||||
val key: String
|
||||
)
|
||||
data class DeleteGlobalMetaPayload(
|
||||
val clientMutationId: String?,
|
||||
val meta: GlobalMetaType?
|
||||
)
|
||||
fun deleteGlobalMeta(
|
||||
input: DeleteGlobalMetaInput
|
||||
): DeleteGlobalMetaPayload {
|
||||
val (clientMutationId, key) = input
|
||||
|
||||
val meta = transaction {
|
||||
val meta = GlobalMetaTable.select { MangaMetaTable.key eq key }
|
||||
.firstOrNull()
|
||||
|
||||
GlobalMetaTable.deleteWhere { GlobalMetaTable.key eq key }
|
||||
|
||||
if (meta != null) {
|
||||
GlobalMetaType(meta)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
return DeleteGlobalMetaPayload(clientMutationId, meta)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
/**
|
||||
* TODO Mutations
|
||||
* - Browse with filters
|
||||
* - Configure settings
|
||||
*/
|
||||
class SourceMutation
|
||||
Reference in New Issue
Block a user