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 1b2347a69..b39d1d70d 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 de6e5bd15..17777b046 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 5cce96ccd..f44ca0a48 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() }