mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
Implement more query parameters
This commit is contained in:
@@ -9,6 +9,7 @@ package suwayomi.tachidesk.graphql.queries
|
||||
|
||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||
import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.andWhere
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
@@ -18,11 +19,7 @@ import java.util.concurrent.CompletableFuture
|
||||
|
||||
/**
|
||||
* TODO Queries
|
||||
* - Filter by read
|
||||
* - Filter by bookmarked
|
||||
* - Filter by downloaded
|
||||
* - Filter by scanlators
|
||||
* - Sort? Upload date, source order, last read, chapter number
|
||||
* - Get page list?
|
||||
*
|
||||
* TODO Mutations
|
||||
@@ -38,9 +35,23 @@ class ChapterQuery {
|
||||
return dataFetchingEnvironment.getValueFromDataLoader<Int, ChapterType>("ChapterDataLoader", id)
|
||||
}
|
||||
|
||||
enum class ChapterSort {
|
||||
SOURCE_ORDER,
|
||||
NAME,
|
||||
UPLOAD_DATE,
|
||||
CHAPTER_NUMBER,
|
||||
LAST_READ_AT,
|
||||
FETCHED_AT
|
||||
}
|
||||
|
||||
data class ChapterQueryInput(
|
||||
val ids: List<Int>? = null,
|
||||
val mangaIds: List<Int>? = null,
|
||||
val read: Boolean? = null,
|
||||
val bookmarked: Boolean? = null,
|
||||
val downloaded: Boolean? = null,
|
||||
val sort: ChapterSort? = null,
|
||||
val sortOrder: SortOrder? = null,
|
||||
val page: Int? = null,
|
||||
val count: Int? = null
|
||||
)
|
||||
@@ -51,15 +62,36 @@ class ChapterQuery {
|
||||
|
||||
if (input != null) {
|
||||
if (input.mangaIds != null) {
|
||||
res = res.andWhere { ChapterTable.manga inList input.mangaIds }
|
||||
res.andWhere { ChapterTable.manga inList input.mangaIds }
|
||||
}
|
||||
if (input.ids != null) {
|
||||
res = res.andWhere { ChapterTable.id inList input.ids }
|
||||
res.andWhere { ChapterTable.id inList input.ids }
|
||||
}
|
||||
if (input.read != null) {
|
||||
res.andWhere { ChapterTable.isRead eq input.read }
|
||||
}
|
||||
if (input.bookmarked != null) {
|
||||
res.andWhere { ChapterTable.isBookmarked eq input.bookmarked }
|
||||
}
|
||||
if (input.downloaded != null) {
|
||||
res.andWhere { ChapterTable.isDownloaded eq input.downloaded }
|
||||
}
|
||||
val orderBy = when (input.sort) {
|
||||
ChapterSort.SOURCE_ORDER, null -> ChapterTable.sourceOrder
|
||||
ChapterSort.NAME -> ChapterTable.name
|
||||
ChapterSort.UPLOAD_DATE -> ChapterTable.date_upload
|
||||
ChapterSort.CHAPTER_NUMBER -> ChapterTable.chapter_number
|
||||
ChapterSort.LAST_READ_AT -> ChapterTable.lastReadAt
|
||||
ChapterSort.FETCHED_AT -> ChapterTable.fetchedAt
|
||||
}
|
||||
res.orderBy(orderBy, order = input.sortOrder ?: SortOrder.ASC)
|
||||
|
||||
if (input.count != null) {
|
||||
val offset = if (input.page == null) 0 else (input.page * input.count).toLong()
|
||||
res = res.limit(input.count, offset)
|
||||
res.limit(input.count, offset)
|
||||
}
|
||||
} else {
|
||||
res.orderBy(ChapterTable.sourceOrder)
|
||||
}
|
||||
|
||||
res.toList()
|
||||
|
||||
Reference in New Issue
Block a user