Skip to content

Commit

Permalink
feat(api): search series by sharing label
Browse files Browse the repository at this point in the history
Closes: #1146
  • Loading branch information
gotson committed Jul 12, 2023
1 parent 66dd1c2 commit 7a21fe0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SeriesSearchWithReadProgress(
val releaseYears: Collection<String>? = null,
val readStatus: Collection<ReadStatus>? = null,
val authors: Collection<Author>? = null,
val sharingLabels: Collection<String>? = null,
) : SeriesSearch(
libraryIds = libraryIds,
collectionIds = collectionIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class SeriesDtoDao(
}
.apply { if (joinConditions.collection) leftJoin(cs).on(s.ID.eq(cs.SERIES_ID)) }
.apply { if (joinConditions.aggregationAuthor) leftJoin(bmaa).on(s.ID.eq(bmaa.SERIES_ID)) }
.apply { if (joinConditions.sharingLabel) leftJoin(sl).on(s.ID.eq(sl.SERIES_ID)) }
.where(conditions)
.and(searchCondition)
.groupBy(firstChar)
Expand Down Expand Up @@ -172,6 +173,7 @@ class SeriesDtoDao(
}
.apply { if (joinConditions.collection) leftJoin(cs).on(s.ID.eq(cs.SERIES_ID)) }
.apply { if (joinConditions.aggregationAuthor) leftJoin(bmaa).on(s.ID.eq(bmaa.SERIES_ID)) }
.apply { if (joinConditions.sharingLabel) leftJoin(sl).on(s.ID.eq(sl.SERIES_ID)) }

private fun findAll(
conditions: Condition,
Expand All @@ -196,6 +198,7 @@ class SeriesDtoDao(
}
.apply { if (joinConditions.collection) leftJoin(cs).on(s.ID.eq(cs.SERIES_ID)) }
.apply { if (joinConditions.aggregationAuthor) leftJoin(bmaa).on(s.ID.eq(bmaa.SERIES_ID)) }
.apply { if (joinConditions.sharingLabel) leftJoin(sl).on(s.ID.eq(sl.SERIES_ID)) }
.where(conditions)
.and(searchCondition)
.fetchOne(countDistinct(s.ID)) ?: 0
Expand Down Expand Up @@ -317,6 +320,7 @@ class SeriesDtoDao(
}
c = c.and(ca)
}
if (!sharingLabels.isNullOrEmpty()) c = c.and(sl.LABEL.collate(SqliteUdfDataSource.collationUnicode3).`in`(sharingLabels))
if (!readStatus.isNullOrEmpty()) {
val cr = readStatus.map {
when (it) {
Expand Down Expand Up @@ -344,6 +348,7 @@ class SeriesDtoDao(
tag = !tags.isNullOrEmpty(),
collection = !collectionIds.isNullOrEmpty(),
aggregationAuthor = !authors.isNullOrEmpty(),
sharingLabel = !sharingLabels.isNullOrEmpty(),
)

private data class JoinConditions(
Expand All @@ -352,6 +357,7 @@ class SeriesDtoDao(
val tag: Boolean = false,
val collection: Boolean = false,
val aggregationAuthor: Boolean = false,
val sharingLabel: Boolean = false,
)

private fun SeriesRecord.toDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class SeriesController(
@RequestParam(name = "genre", required = false) genres: List<String>? = null,
@RequestParam(name = "tag", required = false) tags: List<String>? = null,
@RequestParam(name = "age_rating", required = false) ageRatings: List<String>? = null,
@RequestParam(name = "release_year", required = false) release_years: List<String>? = null,
@RequestParam(name = "release_year", required = false) releaseYears: List<String>? = null,
@RequestParam(name = "sharing_label", required = false) sharingLabels: List<String>? = null,
@RequestParam(name = "deleted", required = false) deleted: Boolean? = null,
@RequestParam(name = "complete", required = false) complete: Boolean? = null,
@RequestParam(name = "unpaged", required = false) unpaged: Boolean = false,
Expand Down Expand Up @@ -181,8 +182,9 @@ class SeriesController(
genres = genres,
tags = tags,
ageRatings = ageRatings?.map { it.toIntOrNull() },
releaseYears = release_years,
releaseYears = releaseYears,
authors = authors,
sharingLabels = sharingLabels,
)

return seriesDtoRepository.findAll(seriesSearch, principal.user.id, pageRequest, principal.user.restrictions)
Expand Down Expand Up @@ -214,7 +216,8 @@ class SeriesController(
@RequestParam(name = "genre", required = false) genres: List<String>?,
@RequestParam(name = "tag", required = false) tags: List<String>?,
@RequestParam(name = "age_rating", required = false) ageRatings: List<String>?,
@RequestParam(name = "release_year", required = false) release_years: List<String>?,
@RequestParam(name = "release_year", required = false) releaseYears: List<String>?,
@RequestParam(name = "sharing_label", required = false) sharingLabels: List<String>? = null,
@RequestParam(name = "deleted", required = false) deleted: Boolean?,
@RequestParam(name = "complete", required = false) complete: Boolean?,
@Parameter(hidden = true) @Authors authors: List<Author>?,
Expand All @@ -240,8 +243,9 @@ class SeriesController(
genres = genres,
tags = tags,
ageRatings = ageRatings?.map { it.toIntOrNull() },
releaseYears = release_years,
releaseYears = releaseYears,
authors = authors,
sharingLabels = sharingLabels,
)

return seriesDtoRepository.countByFirstCharacter(seriesSearch, principal.user.id, principal.user.restrictions)
Expand Down

0 comments on commit 7a21fe0

Please sign in to comment.