feat(api): ability to filter series by status

linked to #48
This commit is contained in:
Gauthier Roebroeck 2020-01-22 14:48:33 +08:00
parent f5221420fd
commit c96bf19048

View file

@ -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
@ -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(
@ -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 {