From ca91af7792559c54a9e1843368a29b7b9d7db3de Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Thu, 25 Jun 2020 12:26:26 +0800 Subject: [PATCH] feat(api): search series by collection ids --- .../kotlin/org/gotson/komga/domain/model/SeriesSearch.kt | 4 +++- .../org/gotson/komga/infrastructure/jooq/SeriesDao.kt | 7 ++++++- .../org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt | 4 ++++ .../org/gotson/komga/interfaces/rest/SeriesController.kt | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/model/SeriesSearch.kt b/komga/src/main/kotlin/org/gotson/komga/domain/model/SeriesSearch.kt index c0ec65e4dc..c99256df37 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/model/SeriesSearch.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/model/SeriesSearch.kt @@ -2,13 +2,15 @@ package org.gotson.komga.domain.model open class SeriesSearch( val libraryIds: Collection? = null, + val collectionIds: Collection? = null, val searchTerm: String? = null, val metadataStatus: Collection? = null ) class SeriesSearchWithReadProgress( libraryIds: Collection? = null, + collectionIds: Collection? = null, searchTerm: String? = null, metadataStatus: Collection? = null, val readStatus: Collection? = null -) : SeriesSearch(libraryIds, searchTerm, metadataStatus) +) : SeriesSearch(libraryIds, collectionIds, searchTerm, metadataStatus) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt index bf588f42c2..6d31d2411d 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt @@ -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 = @@ -63,7 +64,10 @@ class SeriesDao( override fun findAll(search: SeriesSearch): Collection { 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)) } diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt index 35e0a1e3fe..52b6c66729 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt @@ -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 = DSL.sum(DSL.`when`(r.COMPLETED.isNull, 1).otherwise(0)) val countRead: AggregateFunction = 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)) } diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt index 8686c596a4..cd3dc14183 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/SeriesController.kt @@ -73,6 +73,7 @@ class SeriesController( @AuthenticationPrincipal principal: KomgaPrincipal, @RequestParam(name = "search", required = false) searchTerm: String?, @RequestParam(name = "library_id", required = false) libraryIds: List?, + @RequestParam(name = "collection_id", required = false) collectionIds: List?, @RequestParam(name = "status", required = false) metadataStatus: List?, @RequestParam(name = "read_status", required = false) readStatus: List?, @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