mirror of
https://github.com/gotson/komga.git
synced 2025-12-22 00:13:30 +01:00
feat(api): get referential data by collection
This commit is contained in:
parent
01eef838a2
commit
d7fd296492
3 changed files with 78 additions and 15 deletions
|
|
@ -5,17 +5,22 @@ interface ReferentialRepository {
|
|||
|
||||
fun findAllGenres(): Set<String>
|
||||
fun findAllGenresByLibrary(libraryId: String): Set<String>
|
||||
fun findAllGenresByCollection(collectionId: String): Set<String>
|
||||
|
||||
fun findAllTags(): Set<String>
|
||||
fun findAllTagsByLibrary(libraryId: String): Set<String>
|
||||
fun findAllTagsBySeries(seriesId: String): Set<String>
|
||||
fun findAllTagsByCollection(collectionId: String): Set<String>
|
||||
|
||||
fun findAllLanguages(): Set<String>
|
||||
fun findAllLanguagesByLibrary(libraryId: String): Set<String>
|
||||
fun findAllLanguagesByCollection(collectionId: String): Set<String>
|
||||
|
||||
fun findAllPublishers(): Set<String>
|
||||
fun findAllPublishersByLibrary(libraryId: String): Set<String>
|
||||
fun findAllPublishersByCollection(collectionId: String): Set<String>
|
||||
|
||||
fun findAllAgeRatings(): Set<Int?>
|
||||
fun findAllAgeRatingsByLibrary(libraryId: String): Set<Int?>
|
||||
fun findAllAgeRatingsByCollection(collectionId: String): Iterable<Int?>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class ReferentialDao(
|
|||
private val g = Tables.SERIES_METADATA_GENRE
|
||||
private val bt = Tables.BOOK_METADATA_TAG
|
||||
private val st = Tables.SERIES_METADATA_TAG
|
||||
private val cs = Tables.COLLECTION_SERIES
|
||||
|
||||
override fun findAuthorsByName(search: String): List<String> =
|
||||
dsl.selectDistinct(a.NAME)
|
||||
|
|
@ -41,6 +42,14 @@ class ReferentialDao(
|
|||
.orderBy(lower(g.GENRE))
|
||||
.fetchSet(g.GENRE)
|
||||
|
||||
override fun findAllGenresByCollection(collectionId: String): Set<String> =
|
||||
dsl.selectDistinct(g.GENRE)
|
||||
.from(g)
|
||||
.leftJoin(cs).on(g.SERIES_ID.eq(cs.SERIES_ID))
|
||||
.where(cs.COLLECTION_ID.eq(collectionId))
|
||||
.orderBy(lower(g.GENRE))
|
||||
.fetchSet(g.GENRE)
|
||||
|
||||
override fun findAllTags(): Set<String> =
|
||||
dsl.select(bt.TAG.`as`("tag"))
|
||||
.from(bt)
|
||||
|
|
@ -67,6 +76,14 @@ class ReferentialDao(
|
|||
.orderBy(lower(bt.TAG))
|
||||
.fetchSet(bt.TAG)
|
||||
|
||||
override fun findAllTagsByCollection(collectionId: String): Set<String> =
|
||||
dsl.select(st.TAG)
|
||||
.from(st)
|
||||
.leftJoin(cs).on(st.SERIES_ID.eq(cs.SERIES_ID))
|
||||
.where(cs.COLLECTION_ID.eq(collectionId))
|
||||
.orderBy(lower(st.TAG))
|
||||
.fetchSet(st.TAG)
|
||||
|
||||
override fun findAllLanguages(): Set<String> =
|
||||
dsl.selectDistinct(sd.LANGUAGE)
|
||||
.from(sd)
|
||||
|
|
@ -83,6 +100,15 @@ class ReferentialDao(
|
|||
.orderBy(sd.LANGUAGE)
|
||||
.fetchSet(sd.LANGUAGE)
|
||||
|
||||
override fun findAllLanguagesByCollection(collectionId: String): Set<String> =
|
||||
dsl.selectDistinct(sd.LANGUAGE)
|
||||
.from(sd)
|
||||
.leftJoin(cs).on(sd.SERIES_ID.eq(cs.SERIES_ID))
|
||||
.where(sd.LANGUAGE.ne(""))
|
||||
.and(cs.COLLECTION_ID.eq(collectionId))
|
||||
.orderBy(sd.LANGUAGE)
|
||||
.fetchSet(sd.LANGUAGE)
|
||||
|
||||
override fun findAllPublishers(): Set<String> =
|
||||
dsl.selectDistinct(sd.PUBLISHER)
|
||||
.from(sd)
|
||||
|
|
@ -99,6 +125,15 @@ class ReferentialDao(
|
|||
.orderBy(sd.PUBLISHER)
|
||||
.fetchSet(sd.PUBLISHER)
|
||||
|
||||
override fun findAllPublishersByCollection(collectionId: String): Set<String> =
|
||||
dsl.selectDistinct(sd.PUBLISHER)
|
||||
.from(sd)
|
||||
.leftJoin(cs).on(sd.SERIES_ID.eq(cs.SERIES_ID))
|
||||
.where(sd.PUBLISHER.ne(""))
|
||||
.and(cs.COLLECTION_ID.eq(collectionId))
|
||||
.orderBy(sd.PUBLISHER)
|
||||
.fetchSet(sd.PUBLISHER)
|
||||
|
||||
override fun findAllAgeRatings(): Set<Int> =
|
||||
dsl.selectDistinct(sd.AGE_RATING)
|
||||
.from(sd)
|
||||
|
|
@ -112,4 +147,12 @@ class ReferentialDao(
|
|||
.where(s.LIBRARY_ID.eq(libraryId))
|
||||
.orderBy(sd.AGE_RATING)
|
||||
.fetchSet(sd.AGE_RATING)
|
||||
|
||||
override fun findAllAgeRatingsByCollection(collectionId: String): Iterable<Int?> =
|
||||
dsl.selectDistinct(sd.AGE_RATING)
|
||||
.from(sd)
|
||||
.leftJoin(cs).on(sd.SERIES_ID.eq(cs.SERIES_ID))
|
||||
.where(cs.COLLECTION_ID.eq(collectionId))
|
||||
.orderBy(sd.AGE_RATING)
|
||||
.fetchSet(sd.AGE_RATING)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,43 +22,58 @@ class ReferentialController(
|
|||
|
||||
@GetMapping("/genres")
|
||||
fun getGenres(
|
||||
@RequestParam(name = "library_id", required = false) libraryId: String?
|
||||
@RequestParam(name = "library_id", required = false) libraryId: String?,
|
||||
@RequestParam(name = "collection_id", required = false) collectionId: String?
|
||||
): Set<String> =
|
||||
if (libraryId != null) referentialRepository.findAllGenresByLibrary(libraryId)
|
||||
else referentialRepository.findAllGenres()
|
||||
when {
|
||||
libraryId != null -> referentialRepository.findAllGenresByLibrary(libraryId)
|
||||
collectionId != null -> referentialRepository.findAllGenresByCollection(collectionId)
|
||||
else -> referentialRepository.findAllGenres()
|
||||
}
|
||||
|
||||
@GetMapping("/tags")
|
||||
fun getTags(
|
||||
@RequestParam(name = "library_id", required = false) libraryId: String?,
|
||||
@RequestParam(name = "series_id", required = false) seriesId: String?
|
||||
@RequestParam(name = "series_id", required = false) seriesId: String?,
|
||||
@RequestParam(name = "collection_id", required = false) collectionId: String?
|
||||
): Set<String> =
|
||||
when {
|
||||
libraryId != null -> referentialRepository.findAllTagsByLibrary(libraryId)
|
||||
seriesId != null -> referentialRepository.findAllTagsBySeries(seriesId)
|
||||
collectionId != null -> referentialRepository.findAllTagsByCollection(collectionId)
|
||||
else -> referentialRepository.findAllTags()
|
||||
}
|
||||
|
||||
@GetMapping("/languages")
|
||||
fun getLanguages(
|
||||
@RequestParam(name = "library_id", required = false) libraryId: String?
|
||||
@RequestParam(name = "library_id", required = false) libraryId: String?,
|
||||
@RequestParam(name = "collection_id", required = false) collectionId: String?
|
||||
): Set<String> =
|
||||
if (libraryId != null) referentialRepository.findAllLanguagesByLibrary(libraryId)
|
||||
else referentialRepository.findAllLanguages()
|
||||
when {
|
||||
libraryId != null -> referentialRepository.findAllLanguagesByLibrary(libraryId)
|
||||
collectionId != null -> referentialRepository.findAllLanguagesByCollection(collectionId)
|
||||
else -> referentialRepository.findAllLanguages()
|
||||
}
|
||||
|
||||
@GetMapping("/publishers")
|
||||
fun getPublishers(
|
||||
@RequestParam(name = "library_id", required = false) libraryId: String?
|
||||
@RequestParam(name = "library_id", required = false) libraryId: String?,
|
||||
@RequestParam(name = "collection_id", required = false) collectionId: String?
|
||||
): Set<String> =
|
||||
if (libraryId != null) referentialRepository.findAllPublishersByLibrary(libraryId)
|
||||
else referentialRepository.findAllPublishers()
|
||||
when {
|
||||
libraryId != null -> referentialRepository.findAllPublishersByLibrary(libraryId)
|
||||
collectionId != null -> referentialRepository.findAllPublishersByCollection(collectionId)
|
||||
else -> referentialRepository.findAllPublishers()
|
||||
}
|
||||
|
||||
@GetMapping("/age-ratings")
|
||||
fun getAgeRatings(
|
||||
@RequestParam(name = "library_id", required = false) libraryId: String?
|
||||
@RequestParam(name = "library_id", required = false) libraryId: String?,
|
||||
@RequestParam(name = "collection_id", required = false) collectionId: String?
|
||||
): Set<String> =
|
||||
if (libraryId != null) {
|
||||
referentialRepository.findAllAgeRatingsByLibrary(libraryId)
|
||||
} else {
|
||||
referentialRepository.findAllAgeRatings()
|
||||
when {
|
||||
libraryId != null -> referentialRepository.findAllAgeRatingsByLibrary(libraryId)
|
||||
collectionId != null -> referentialRepository.findAllAgeRatingsByCollection(collectionId)
|
||||
else -> referentialRepository.findAllAgeRatings()
|
||||
}.map { it?.toString() ?: "None" }.toSet()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue