mirror of
https://github.com/gotson/komga.git
synced 2026-02-15 11:54:48 +01:00
feat(api): search series by collection ids
This commit is contained in:
parent
b6bd735bdb
commit
ca91af7792
4 changed files with 15 additions and 2 deletions
|
|
@ -2,13 +2,15 @@ package org.gotson.komga.domain.model
|
||||||
|
|
||||||
open class SeriesSearch(
|
open class SeriesSearch(
|
||||||
val libraryIds: Collection<Long>? = null,
|
val libraryIds: Collection<Long>? = null,
|
||||||
|
val collectionIds: Collection<Long>? = null,
|
||||||
val searchTerm: String? = null,
|
val searchTerm: String? = null,
|
||||||
val metadataStatus: Collection<SeriesMetadata.Status>? = null
|
val metadataStatus: Collection<SeriesMetadata.Status>? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
class SeriesSearchWithReadProgress(
|
class SeriesSearchWithReadProgress(
|
||||||
libraryIds: Collection<Long>? = null,
|
libraryIds: Collection<Long>? = null,
|
||||||
|
collectionIds: Collection<Long>? = null,
|
||||||
searchTerm: String? = null,
|
searchTerm: String? = null,
|
||||||
metadataStatus: Collection<SeriesMetadata.Status>? = null,
|
metadataStatus: Collection<SeriesMetadata.Status>? = null,
|
||||||
val readStatus: Collection<ReadStatus>? = 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 s = Tables.SERIES
|
||||||
private val d = Tables.SERIES_METADATA
|
private val d = Tables.SERIES_METADATA
|
||||||
private val b = Tables.BOOK
|
private val b = Tables.BOOK
|
||||||
|
private val cs = Tables.COLLECTION_SERIES
|
||||||
|
|
||||||
|
|
||||||
override fun findAll(): Collection<Series> =
|
override fun findAll(): Collection<Series> =
|
||||||
|
|
@ -63,7 +64,10 @@ class SeriesDao(
|
||||||
override fun findAll(search: SeriesSearch): Collection<Series> {
|
override fun findAll(search: SeriesSearch): Collection<Series> {
|
||||||
val conditions = search.toCondition()
|
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)
|
.where(conditions)
|
||||||
.fetchInto(s)
|
.fetchInto(s)
|
||||||
.map { it.toDomain() }
|
.map { it.toDomain() }
|
||||||
|
|
@ -132,6 +136,7 @@ class SeriesDao(
|
||||||
var c: Condition = DSL.trueCondition()
|
var c: Condition = DSL.trueCondition()
|
||||||
|
|
||||||
libraryIds?.let { c = c.and(s.LIBRARY_ID.`in`(it)) }
|
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)) }
|
searchTerm?.let { c = c.and(d.TITLE.containsIgnoreCase(it)) }
|
||||||
metadataStatus?.let { c = c.and(d.STATUS.`in`(it)) }
|
metadataStatus?.let { c = c.and(d.STATUS.`in`(it)) }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ class SeriesDtoDao(
|
||||||
private val b = Tables.BOOK
|
private val b = Tables.BOOK
|
||||||
private val d = Tables.SERIES_METADATA
|
private val d = Tables.SERIES_METADATA
|
||||||
private val r = Tables.READ_PROGRESS
|
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 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))
|
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(b).on(s.ID.eq(b.SERIES_ID))
|
||||||
.leftJoin(d).on(s.ID.eq(d.SERIES_ID))
|
.leftJoin(d).on(s.ID.eq(d.SERIES_ID))
|
||||||
.leftJoin(r).on(b.ID.eq(r.BOOK_ID))
|
.leftJoin(r).on(b.ID.eq(r.BOOK_ID))
|
||||||
|
.leftJoin(cs).on(s.ID.eq(cs.SERIES_ID))
|
||||||
.where(conditions)
|
.where(conditions)
|
||||||
.groupBy(s.ID)
|
.groupBy(s.ID)
|
||||||
.having(having)
|
.having(having)
|
||||||
|
|
@ -129,6 +131,7 @@ class SeriesDtoDao(
|
||||||
.leftJoin(b).on(s.ID.eq(b.SERIES_ID))
|
.leftJoin(b).on(s.ID.eq(b.SERIES_ID))
|
||||||
.leftJoin(d).on(s.ID.eq(d.SERIES_ID))
|
.leftJoin(d).on(s.ID.eq(d.SERIES_ID))
|
||||||
.leftJoin(r).on(b.ID.eq(r.BOOK_ID))
|
.leftJoin(r).on(b.ID.eq(r.BOOK_ID))
|
||||||
|
.leftJoin(cs).on(s.ID.eq(cs.SERIES_ID))
|
||||||
.and(readProgressCondition(userId))
|
.and(readProgressCondition(userId))
|
||||||
|
|
||||||
private fun readProgressCondition(userId: Long): Condition = r.USER_ID.eq(userId).or(r.USER_ID.isNull)
|
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()
|
var c: Condition = DSL.trueCondition()
|
||||||
|
|
||||||
libraryIds?.let { c = c.and(s.LIBRARY_ID.`in`(it)) }
|
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)) }
|
searchTerm?.let { c = c.and(d.TITLE.containsIgnoreCase(it)) }
|
||||||
metadataStatus?.let { c = c.and(d.STATUS.`in`(it)) }
|
metadataStatus?.let { c = c.and(d.STATUS.`in`(it)) }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ class SeriesController(
|
||||||
@AuthenticationPrincipal principal: KomgaPrincipal,
|
@AuthenticationPrincipal principal: KomgaPrincipal,
|
||||||
@RequestParam(name = "search", required = false) searchTerm: String?,
|
@RequestParam(name = "search", required = false) searchTerm: String?,
|
||||||
@RequestParam(name = "library_id", required = false) libraryIds: List<Long>?,
|
@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 = "status", required = false) metadataStatus: List<SeriesMetadata.Status>?,
|
||||||
@RequestParam(name = "read_status", required = false) readStatus: List<ReadStatus>?,
|
@RequestParam(name = "read_status", required = false) readStatus: List<ReadStatus>?,
|
||||||
@Parameter(hidden = true) page: Pageable
|
@Parameter(hidden = true) page: Pageable
|
||||||
|
|
@ -86,6 +87,7 @@ class SeriesController(
|
||||||
|
|
||||||
val seriesSearch = SeriesSearchWithReadProgress(
|
val seriesSearch = SeriesSearchWithReadProgress(
|
||||||
libraryIds = principal.user.getAuthorizedLibraryIds(libraryIds),
|
libraryIds = principal.user.getAuthorizedLibraryIds(libraryIds),
|
||||||
|
collectionIds = collectionIds,
|
||||||
searchTerm = searchTerm,
|
searchTerm = searchTerm,
|
||||||
metadataStatus = metadataStatus,
|
metadataStatus = metadataStatus,
|
||||||
readStatus = readStatus
|
readStatus = readStatus
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue