Skip to content

Commit

Permalink
feat(api): filter collection's series
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Aug 28, 2020
1 parent d7fd296 commit cfa06a9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ class SeriesDtoDao(
return findAll(conditions, having, userId, pageable, search.toJoinConditions())
}

override fun findByCollectionId(collectionId: String, userId: String, pageable: Pageable): Page<SeriesDto> {
val conditions = cs.COLLECTION_ID.eq(collectionId)
val having = DSL.trueCondition()
override fun findByCollectionId(collectionId: String, search: SeriesSearchWithReadProgress, userId: String, pageable: Pageable): Page<SeriesDto> {
val conditions = search.toCondition().and(cs.COLLECTION_ID.eq(collectionId))
val having = search.readStatus?.toCondition() ?: DSL.trueCondition()
val joinConditions = search.toJoinConditions().copy(selectCollectionNumber = true, collection = true)

return findAll(conditions, having, userId, pageable, JoinConditions(selectCollectionNumber = true, collection = true))
return findAll(conditions, having, userId, pageable, joinConditions)
}

override fun findRecentlyUpdated(search: SeriesSearchWithReadProgress, userId: String, pageable: Pageable): Page<SeriesDto> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse
import mu.KotlinLogging
import org.gotson.komga.domain.model.DuplicateNameException
import org.gotson.komga.domain.model.ROLE_ADMIN
import org.gotson.komga.domain.model.ReadStatus
import org.gotson.komga.domain.model.SeriesCollection
import org.gotson.komga.domain.model.SeriesMetadata
import org.gotson.komga.domain.model.SeriesSearchWithReadProgress
import org.gotson.komga.domain.persistence.SeriesCollectionRepository
import org.gotson.komga.domain.service.SeriesCollectionLifecycle
import org.gotson.komga.infrastructure.jooq.UnpagedSorted
Expand Down Expand Up @@ -153,6 +156,14 @@ class SeriesCollectionController(
fun getSeriesForCollection(
@PathVariable id: String,
@AuthenticationPrincipal principal: KomgaPrincipal,
@RequestParam(name = "library_id", required = false) libraryIds: List<String>?,
@RequestParam(name = "status", required = false) metadataStatus: List<SeriesMetadata.Status>?,
@RequestParam(name = "read_status", required = false) readStatus: List<ReadStatus>?,
@RequestParam(name = "publisher", required = false) publishers: List<String>?,
@RequestParam(name = "language", required = false) languages: List<String>?,
@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 = "unpaged", required = false) unpaged: Boolean = false,
@Parameter(hidden = true) page: Pageable
): Page<SeriesDto> =
Expand All @@ -169,7 +180,18 @@ class SeriesCollectionController(
sort
)

seriesDtoRepository.findByCollectionId(collection.id, principal.user.id, pageRequest)
val seriesSearch = SeriesSearchWithReadProgress(
libraryIds = principal.user.getAuthorizedLibraryIds(libraryIds),
metadataStatus = metadataStatus,
readStatus = readStatus,
publishers = publishers,
languages = languages,
genres = genres,
tags = tags,
ageRatings = ageRatings?.map { it.toIntOrNull() }
)

seriesDtoRepository.findByCollectionId(collection.id, seriesSearch, principal.user.id, pageRequest)
.map { it.restrictUrl(!principal.user.roleAdmin) }
} ?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.springframework.data.domain.Pageable

interface SeriesDtoRepository {
fun findAll(search: SeriesSearchWithReadProgress, userId: String, pageable: Pageable): Page<SeriesDto>
fun findByCollectionId(collectionId: String, userId: String, pageable: Pageable): Page<SeriesDto>
fun findByCollectionId(collectionId: String, search: SeriesSearchWithReadProgress, userId: String, pageable: Pageable): Page<SeriesDto>
fun findRecentlyUpdated(search: SeriesSearchWithReadProgress, userId: String, pageable: Pageable): Page<SeriesDto>
fun findByIdOrNull(seriesId: String, userId: String): SeriesDto?
}

0 comments on commit cfa06a9

Please sign in to comment.