Skip to content

Commit

Permalink
feat(api): get all age ratings
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Aug 28, 2020
1 parent 93efd98 commit be80d86
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ interface ReferentialRepository {

fun findAllPublishers(): Set<String>
fun findAllPublishersByLibrary(libraryId: String): Set<String>

fun findAllAgeRatings(): Set<Int?>
fun findAllAgeRatingsByLibrary(libraryId: String): Set<Int?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,18 @@ class ReferentialDao(
.and(s.LIBRARY_ID.eq(libraryId))
.orderBy(sd.PUBLISHER)
.fetchSet(sd.PUBLISHER)

override fun findAllAgeRatings(): Set<Int> =
dsl.selectDistinct(sd.AGE_RATING)
.from(sd)
.orderBy(sd.AGE_RATING)
.fetchSet(sd.AGE_RATING)

override fun findAllAgeRatingsByLibrary(libraryId: String): Set<Int> =
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ class ReferentialController(
): Set<String> =
if (libraryId != null) referentialRepository.findAllPublishersByLibrary(libraryId)
else referentialRepository.findAllPublishers()

@GetMapping("/age-ratings")
fun getAgeRatings(
@RequestParam(name = "library_id", required = false) libraryId: String?
): Set<String> =
if (libraryId != null) {
referentialRepository.findAllAgeRatingsByLibrary(libraryId)
} else {
referentialRepository.findAllAgeRatings()
}.map { it?.toString() ?: "None" }.toSet()
}

0 comments on commit be80d86

Please sign in to comment.