From be80d86d6cba564293053f883c0ceda186652fe0 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Fri, 28 Aug 2020 10:18:01 +0800 Subject: [PATCH] feat(api): get all age ratings --- .../domain/persistence/ReferentialRepository.kt | 3 +++ .../komga/infrastructure/jooq/ReferentialDao.kt | 14 ++++++++++++++ .../komga/interfaces/rest/ReferentialController.kt | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/persistence/ReferentialRepository.kt b/komga/src/main/kotlin/org/gotson/komga/domain/persistence/ReferentialRepository.kt index 1b2347a698..b39d1d70d0 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/persistence/ReferentialRepository.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/persistence/ReferentialRepository.kt @@ -15,4 +15,7 @@ interface ReferentialRepository { fun findAllPublishers(): Set fun findAllPublishersByLibrary(libraryId: String): Set + + fun findAllAgeRatings(): Set + fun findAllAgeRatingsByLibrary(libraryId: String): Set } diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReferentialDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReferentialDao.kt index de6e5bd151..17777b0462 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReferentialDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReferentialDao.kt @@ -98,4 +98,18 @@ class ReferentialDao( .and(s.LIBRARY_ID.eq(libraryId)) .orderBy(sd.PUBLISHER) .fetchSet(sd.PUBLISHER) + + override fun findAllAgeRatings(): Set = + dsl.selectDistinct(sd.AGE_RATING) + .from(sd) + .orderBy(sd.AGE_RATING) + .fetchSet(sd.AGE_RATING) + + override fun findAllAgeRatingsByLibrary(libraryId: String): Set = + dsl.selectDistinct(sd.AGE_RATING) + .from(sd) + .leftJoin(s).on(sd.SERIES_ID.eq(s.ID)) + .where(s.LIBRARY_ID.eq(libraryId)) + .orderBy(sd.AGE_RATING) + .fetchSet(sd.AGE_RATING) } diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/ReferentialController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/ReferentialController.kt index 5cce96ccdf..f44ca0a48b 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/ReferentialController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/ReferentialController.kt @@ -51,4 +51,14 @@ class ReferentialController( ): Set = if (libraryId != null) referentialRepository.findAllPublishersByLibrary(libraryId) else referentialRepository.findAllPublishers() + + @GetMapping("/age-ratings") + fun getAgeRatings( + @RequestParam(name = "library_id", required = false) libraryId: String? + ): Set = + if (libraryId != null) { + referentialRepository.findAllAgeRatingsByLibrary(libraryId) + } else { + referentialRepository.findAllAgeRatings() + }.map { it?.toString() ?: "None" }.toSet() }