mirror of
https://github.com/gotson/komga.git
synced 2025-01-09 04:08:00 +08:00
feat(api): search series by collection ids
This commit is contained in:
parent
b6bd735bdb
commit
ca91af7792
@ -2,13 +2,15 @@ package org.gotson.komga.domain.model
|
||||
|
||||
open class SeriesSearch(
|
||||
val libraryIds: Collection<Long>? = null,
|
||||
val collectionIds: Collection<Long>? = null,
|
||||
val searchTerm: String? = null,
|
||||
val metadataStatus: Collection<SeriesMetadata.Status>? = null
|
||||
)
|
||||
|
||||
class SeriesSearchWithReadProgress(
|
||||
libraryIds: Collection<Long>? = null,
|
||||
collectionIds: Collection<Long>? = null,
|
||||
searchTerm: String? = null,
|
||||
metadataStatus: Collection<SeriesMetadata.Status>? = null,
|
||||
val readStatus: Collection<ReadStatus>? = null
|
||||
) : SeriesSearch(libraryIds, searchTerm, metadataStatus)
|
||||
) : SeriesSearch(libraryIds, collectionIds, searchTerm, metadataStatus)
|
||||
|
@ -21,6 +21,7 @@ class SeriesDao(
|
||||
private val s = Tables.SERIES
|
||||
private val d = Tables.SERIES_METADATA
|
||||
private val b = Tables.BOOK
|
||||
private val cs = Tables.COLLECTION_SERIES
|
||||
|
||||
|
||||
override fun findAll(): Collection<Series> =
|
||||
@ -63,7 +64,10 @@ class SeriesDao(
|
||||
override fun findAll(search: SeriesSearch): Collection<Series> {
|
||||
val conditions = search.toCondition()
|
||||
|
||||
return dsl.selectFrom(s)
|
||||
return dsl.select(*s.fields())
|
||||
.from(s)
|
||||
.leftJoin(cs).on(s.ID.eq(cs.SERIES_ID))
|
||||
.leftJoin(d).on(s.ID.eq(d.SERIES_ID))
|
||||
.where(conditions)
|
||||
.fetchInto(s)
|
||||
.map { it.toDomain() }
|
||||
@ -132,6 +136,7 @@ class SeriesDao(
|
||||
var c: Condition = DSL.trueCondition()
|
||||
|
||||
libraryIds?.let { c = c.and(s.LIBRARY_ID.`in`(it)) }
|
||||
collectionIds?.let { c = c.and(cs.COLLECTION_ID.`in`(it)) }
|
||||
searchTerm?.let { c = c.and(d.TITLE.containsIgnoreCase(it)) }
|
||||
metadataStatus?.let { c = c.and(d.STATUS.`in`(it)) }
|
||||
|
||||
|
@ -39,6 +39,7 @@ class SeriesDtoDao(
|
||||
private val b = Tables.BOOK
|
||||
private val d = Tables.SERIES_METADATA
|
||||
private val r = Tables.READ_PROGRESS
|
||||
private val cs = Tables.COLLECTION_SERIES
|
||||
|
||||
val countUnread: AggregateFunction<BigDecimal> = DSL.sum(DSL.`when`(r.COMPLETED.isNull, 1).otherwise(0))
|
||||
val countRead: AggregateFunction<BigDecimal> = DSL.sum(DSL.`when`(r.COMPLETED.isTrue, 1).otherwise(0))
|
||||
@ -95,6 +96,7 @@ class SeriesDtoDao(
|
||||
.leftJoin(b).on(s.ID.eq(b.SERIES_ID))
|
||||
.leftJoin(d).on(s.ID.eq(d.SERIES_ID))
|
||||
.leftJoin(r).on(b.ID.eq(r.BOOK_ID))
|
||||
.leftJoin(cs).on(s.ID.eq(cs.SERIES_ID))
|
||||
.where(conditions)
|
||||
.groupBy(s.ID)
|
||||
.having(having)
|
||||
@ -129,6 +131,7 @@ class SeriesDtoDao(
|
||||
.leftJoin(b).on(s.ID.eq(b.SERIES_ID))
|
||||
.leftJoin(d).on(s.ID.eq(d.SERIES_ID))
|
||||
.leftJoin(r).on(b.ID.eq(r.BOOK_ID))
|
||||
.leftJoin(cs).on(s.ID.eq(cs.SERIES_ID))
|
||||
.and(readProgressCondition(userId))
|
||||
|
||||
private fun readProgressCondition(userId: Long): Condition = r.USER_ID.eq(userId).or(r.USER_ID.isNull)
|
||||
@ -149,6 +152,7 @@ class SeriesDtoDao(
|
||||
var c: Condition = DSL.trueCondition()
|
||||
|
||||
libraryIds?.let { c = c.and(s.LIBRARY_ID.`in`(it)) }
|
||||
collectionIds?.let { c = c.and(cs.COLLECTION_ID.`in`(it)) }
|
||||
searchTerm?.let { c = c.and(d.TITLE.containsIgnoreCase(it)) }
|
||||
metadataStatus?.let { c = c.and(d.STATUS.`in`(it)) }
|
||||
|
||||
|
@ -73,6 +73,7 @@ class SeriesController(
|
||||
@AuthenticationPrincipal principal: KomgaPrincipal,
|
||||
@RequestParam(name = "search", required = false) searchTerm: String?,
|
||||
@RequestParam(name = "library_id", required = false) libraryIds: List<Long>?,
|
||||
@RequestParam(name = "collection_id", required = false) collectionIds: List<Long>?,
|
||||
@RequestParam(name = "status", required = false) metadataStatus: List<SeriesMetadata.Status>?,
|
||||
@RequestParam(name = "read_status", required = false) readStatus: List<ReadStatus>?,
|
||||
@Parameter(hidden = true) page: Pageable
|
||||
@ -86,6 +87,7 @@ class SeriesController(
|
||||
|
||||
val seriesSearch = SeriesSearchWithReadProgress(
|
||||
libraryIds = principal.user.getAuthorizedLibraryIds(libraryIds),
|
||||
collectionIds = collectionIds,
|
||||
searchTerm = searchTerm,
|
||||
metadataStatus = metadataStatus,
|
||||
readStatus = readStatus
|
||||
|
Loading…
Reference in New Issue
Block a user