mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2026-01-29 06:54:13 +01:00
Default is now a category, no more library
This commit is contained in:
@@ -14,9 +14,9 @@ import io.javalin.apibuilder.ApiBuilder.path
|
||||
import io.javalin.apibuilder.ApiBuilder.post
|
||||
import io.javalin.apibuilder.ApiBuilder.ws
|
||||
import suwayomi.tachidesk.manga.controller.BackupController
|
||||
import suwayomi.tachidesk.manga.controller.CategoryController
|
||||
import suwayomi.tachidesk.manga.controller.DownloadController
|
||||
import suwayomi.tachidesk.manga.controller.ExtensionController
|
||||
import suwayomi.tachidesk.manga.controller.LibraryController
|
||||
import suwayomi.tachidesk.manga.controller.MangaController
|
||||
import suwayomi.tachidesk.manga.controller.SourceController
|
||||
|
||||
@@ -70,19 +70,18 @@ object MangaAPI {
|
||||
get(":mangaId/chapter/:chapterIndex/page/:index", MangaController::pageRetrieve)
|
||||
}
|
||||
|
||||
path("") {
|
||||
get("library", LibraryController::list)
|
||||
path("category") {
|
||||
get("", CategoryController::categoryList)
|
||||
post("", CategoryController::categoryCreate)
|
||||
|
||||
path("category") {
|
||||
get("", LibraryController::categoryList)
|
||||
post("", LibraryController::categoryCreate)
|
||||
get(":categoryId", CategoryController::categoryMangas)
|
||||
patch(":categoryId", CategoryController::categoryModify)
|
||||
delete(":categoryId", CategoryController::categoryDelete)
|
||||
|
||||
get(":categoryId", LibraryController::categoryMangas)
|
||||
patch(":categoryId", LibraryController::categoryModify)
|
||||
delete(":categoryId", LibraryController::categoryDelete)
|
||||
|
||||
patch(":categoryId/reorder", LibraryController::categoryReorder) // TODO: the underlying code doesn't need `:categoryId`, remove it
|
||||
}
|
||||
patch(
|
||||
":categoryId/reorder",
|
||||
CategoryController::categoryReorder
|
||||
) // TODO: the underlying code doesn't need `:categoryId`, remove it
|
||||
}
|
||||
|
||||
path("backup") {
|
||||
|
||||
@@ -10,14 +10,8 @@ package suwayomi.tachidesk.manga.controller
|
||||
import io.javalin.http.Context
|
||||
import suwayomi.tachidesk.manga.impl.Category
|
||||
import suwayomi.tachidesk.manga.impl.CategoryManga
|
||||
import suwayomi.tachidesk.manga.impl.Library
|
||||
|
||||
object LibraryController {
|
||||
/** lists mangas that have no category assigned */
|
||||
fun list(ctx: Context) {
|
||||
ctx.json(Library.getLibraryMangas())
|
||||
}
|
||||
|
||||
object CategoryController {
|
||||
/** category list */
|
||||
fun categoryList(ctx: Context) {
|
||||
ctx.json(Category.getCategoryList())
|
||||
@@ -8,6 +8,7 @@ package suwayomi.tachidesk.manga.impl
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.insert
|
||||
import org.jetbrains.exposed.sql.select
|
||||
@@ -15,9 +16,11 @@ import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import suwayomi.tachidesk.manga.impl.CategoryManga.removeMangaFromCategory
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.isNotEmpty
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
|
||||
object Category {
|
||||
@@ -68,11 +71,21 @@ object Category {
|
||||
}
|
||||
}
|
||||
|
||||
const val DEFAULT_CATEGORY_ID = 0
|
||||
private fun addDefaultIfNecessary(categories: List<CategoryDataClass>): List<CategoryDataClass> =
|
||||
if (MangaTable.select { (MangaTable.inLibrary eq true) and (MangaTable.defaultCategory eq true) }.isNotEmpty()) {
|
||||
listOf(CategoryDataClass(DEFAULT_CATEGORY_ID, 0, "Default", true)) + categories
|
||||
} else {
|
||||
categories
|
||||
}
|
||||
|
||||
fun getCategoryList(): List<CategoryDataClass> {
|
||||
return transaction {
|
||||
CategoryTable.selectAll().orderBy(CategoryTable.order to SortOrder.ASC).map {
|
||||
val categories = CategoryTable.selectAll().orderBy(CategoryTable.order to SortOrder.ASC).map {
|
||||
CategoryTable.toDataClass(it)
|
||||
}
|
||||
|
||||
addDefaultIfNecessary(categories)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.jetbrains.exposed.sql.insert
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import suwayomi.tachidesk.manga.impl.Category.DEFAULT_CATEGORY_ID
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.isEmpty
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.MangaDataClass
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
||||
@@ -23,8 +25,10 @@ import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
|
||||
object CategoryManga {
|
||||
fun addMangaToCategory(mangaId: Int, categoryId: Int) {
|
||||
fun notAlreadyInCategory() = CategoryMangaTable.select { (CategoryMangaTable.category eq categoryId) and (CategoryMangaTable.manga eq mangaId) }.isEmpty()
|
||||
|
||||
transaction {
|
||||
if (CategoryMangaTable.select { (CategoryMangaTable.category eq categoryId) and (CategoryMangaTable.manga eq mangaId) }.firstOrNull() == null) {
|
||||
if (notAlreadyInCategory()) {
|
||||
CategoryMangaTable.insert {
|
||||
it[CategoryMangaTable.category] = categoryId
|
||||
it[CategoryMangaTable.manga] = mangaId
|
||||
@@ -52,6 +56,13 @@ object CategoryManga {
|
||||
* list of mangas that belong to a category
|
||||
*/
|
||||
fun getCategoryMangaList(categoryId: Int): List<MangaDataClass> {
|
||||
if (categoryId == DEFAULT_CATEGORY_ID)
|
||||
return transaction {
|
||||
MangaTable.select { (MangaTable.inLibrary eq true) and (MangaTable.defaultCategory eq true) }.map {
|
||||
MangaTable.toDataClass(it)
|
||||
}
|
||||
}
|
||||
|
||||
return transaction {
|
||||
CategoryMangaTable.innerJoin(MangaTable).select { CategoryMangaTable.category eq categoryId }.map {
|
||||
MangaTable.toDataClass(it)
|
||||
|
||||
@@ -7,18 +7,15 @@ package suwayomi.tachidesk.manga.impl
|
||||
* 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/. */
|
||||
|
||||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.insert
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import suwayomi.tachidesk.manga.impl.Manga.getManga
|
||||
import suwayomi.tachidesk.manga.model.dataclass.MangaDataClass
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
|
||||
object Library {
|
||||
suspend fun addMangaToLibrary(mangaId: Int) {
|
||||
@@ -54,12 +51,4 @@ object Library {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getLibraryMangas(): List<MangaDataClass> {
|
||||
return transaction {
|
||||
MangaTable.select { (MangaTable.inLibrary eq true) and (MangaTable.defaultCategory eq true) }.map {
|
||||
MangaTable.toDataClass(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package suwayomi.tachidesk.manga.impl.util.lang
|
||||
|
||||
/*
|
||||
* 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/. */
|
||||
|
||||
import org.jetbrains.exposed.sql.Query
|
||||
|
||||
fun Query.isEmpty() = this.count() == 0L
|
||||
|
||||
fun Query.isNotEmpty() = !this.isEmpty()
|
||||
Reference in New Issue
Block a user