Skip to content

Commit

Permalink
feat(api): ability to filter series by status
Browse files Browse the repository at this point in the history
linked to #48
  • Loading branch information
gotson committed Jan 22, 2020
1 parent f522142 commit c96bf19
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.gotson.komga.application.service.AsyncOrchestrator
import org.gotson.komga.domain.model.Library
import org.gotson.komga.domain.model.Media
import org.gotson.komga.domain.model.Series
import org.gotson.komga.domain.model.SeriesMetadata
import org.gotson.komga.domain.persistence.BookRepository
import org.gotson.komga.domain.persistence.SeriesRepository
import org.gotson.komga.infrastructure.security.KomgaPrincipal
Expand Down Expand Up @@ -55,6 +56,7 @@ class SeriesController(
@AuthenticationPrincipal principal: KomgaPrincipal,
@RequestParam(name = "search", required = false) searchTerm: String?,
@RequestParam(name = "library_id", required = false) libraryIds: List<Long>?,
@RequestParam(name = "status", required = false) metadataStatus: List<SeriesMetadata.Status>?,
page: Pageable
): Page<SeriesDto> {
val pageRequest = PageRequest.of(
Expand Down Expand Up @@ -86,6 +88,10 @@ class SeriesController(
specs.add(Series::name.likeLower("%$searchTerm%"))
}

if (!metadataStatus.isNullOrEmpty()) {
specs.add(Series::metadata.toJoin().where(SeriesMetadata::status).`in`(metadataStatus))
}

if (specs.isNotEmpty()) {
seriesRepository.findAll(specs.reduce { acc, spec -> acc.and(spec)!! }, pageRequest)
} else {
Expand Down

0 comments on commit c96bf19

Please sign in to comment.