Skip to content

Commit

Permalink
feat(api): search series by collection ids
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Jun 26, 2020
1 parent b6bd735 commit ca91af7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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> =
Expand Down Expand Up @@ -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() }
Expand Down Expand Up @@ -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)) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -86,6 +87,7 @@ class SeriesController(

val seriesSearch = SeriesSearchWithReadProgress(
libraryIds = principal.user.getAuthorizedLibraryIds(libraryIds),
collectionIds = collectionIds,
searchTerm = searchTerm,
metadataStatus = metadataStatus,
readStatus = readStatus
Expand Down

0 comments on commit ca91af7

Please sign in to comment.