mirror of
https://github.com/gotson/komga.git
synced 2025-12-16 13:33:49 +01:00
feat(api): retrieve all sharing labels
This commit is contained in:
parent
8d4eb68f7d
commit
562c57ccc8
3 changed files with 48 additions and 0 deletions
|
|
@ -49,4 +49,8 @@ interface ReferentialRepository {
|
|||
fun findAllSeriesReleaseDates(filterOnLibraryIds: Collection<String>?): Set<LocalDate>
|
||||
fun findAllSeriesReleaseDatesByLibrary(libraryId: String, filterOnLibraryIds: Collection<String>?): Set<LocalDate>
|
||||
fun findAllSeriesReleaseDatesByCollection(collectionId: String, filterOnLibraryIds: Collection<String>?): Set<LocalDate>
|
||||
|
||||
fun findAllSharingLabels(filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
fun findAllSharingLabelsByLibrary(libraryId: String, filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
fun findAllSharingLabelsByCollection(collectionId: String, filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class ReferentialDao(
|
|||
private val st = Tables.SERIES_METADATA_TAG
|
||||
private val cs = Tables.COLLECTION_SERIES
|
||||
private val rb = Tables.READLIST_BOOK
|
||||
private val sl = Tables.SERIES_METADATA_SHARING
|
||||
|
||||
override fun findAllAuthorsByName(search: String, filterOnLibraryIds: Collection<String>?): List<Author> =
|
||||
dsl.selectDistinct(a.NAME, a.ROLE)
|
||||
|
|
@ -463,6 +464,37 @@ class ReferentialDao(
|
|||
.orderBy(bma.RELEASE_DATE.desc())
|
||||
.fetchSet(bma.RELEASE_DATE)
|
||||
|
||||
override fun findAllSharingLabels(filterOnLibraryIds: Collection<String>?): Set<String> =
|
||||
dsl.selectDistinct(sl.LABEL)
|
||||
.from(sl)
|
||||
.apply {
|
||||
filterOnLibraryIds?.let {
|
||||
leftJoin(s).on(sl.SERIES_ID.eq(s.ID))
|
||||
.where(s.LIBRARY_ID.`in`(it))
|
||||
}
|
||||
}
|
||||
.orderBy(sl.LABEL.collate(SqliteUdfDataSource.collationUnicode3))
|
||||
.fetchSet(sl.LABEL)
|
||||
|
||||
override fun findAllSharingLabelsByLibrary(libraryId: String, filterOnLibraryIds: Collection<String>?): Set<String> =
|
||||
dsl.selectDistinct(sl.LABEL)
|
||||
.from(sl)
|
||||
.leftJoin(s).on(sl.SERIES_ID.eq(s.ID))
|
||||
.where(s.LIBRARY_ID.eq(libraryId))
|
||||
.apply { filterOnLibraryIds?.let { and(s.LIBRARY_ID.`in`(it)) } }
|
||||
.orderBy(sl.LABEL.collate(SqliteUdfDataSource.collationUnicode3))
|
||||
.fetchSet(sl.LABEL)
|
||||
|
||||
override fun findAllSharingLabelsByCollection(collectionId: String, filterOnLibraryIds: Collection<String>?): Set<String> =
|
||||
dsl.selectDistinct(sl.LABEL)
|
||||
.from(sl)
|
||||
.leftJoin(cs).on(sl.SERIES_ID.eq(cs.SERIES_ID))
|
||||
.apply { filterOnLibraryIds?.let { leftJoin(s).on(sl.SERIES_ID.eq(s.ID)) } }
|
||||
.where(cs.COLLECTION_ID.eq(collectionId))
|
||||
.apply { filterOnLibraryIds?.let { and(s.LIBRARY_ID.`in`(it)) } }
|
||||
.orderBy(sl.LABEL.collate(SqliteUdfDataSource.collationUnicode3))
|
||||
.fetchSet(sl.LABEL)
|
||||
|
||||
private fun BookMetadataAuthorRecord.toDomain(): Author =
|
||||
Author(
|
||||
name = name,
|
||||
|
|
|
|||
|
|
@ -92,6 +92,18 @@ class ReferentialController(
|
|||
else -> referentialRepository.findAllGenres(principal.user.getAuthorizedLibraryIds(null))
|
||||
}
|
||||
|
||||
@GetMapping("v1/sharing-labels")
|
||||
fun getSharingLabels(
|
||||
@AuthenticationPrincipal principal: KomgaPrincipal,
|
||||
@RequestParam(name = "library_id", required = false) libraryId: String?,
|
||||
@RequestParam(name = "collection_id", required = false) collectionId: String?,
|
||||
): Set<String> =
|
||||
when {
|
||||
libraryId != null -> referentialRepository.findAllSharingLabelsByLibrary(libraryId, principal.user.getAuthorizedLibraryIds(null))
|
||||
collectionId != null -> referentialRepository.findAllSharingLabelsByCollection(collectionId, principal.user.getAuthorizedLibraryIds(null))
|
||||
else -> referentialRepository.findAllSharingLabels(principal.user.getAuthorizedLibraryIds(null))
|
||||
}
|
||||
|
||||
@GetMapping("v1/tags")
|
||||
fun getTags(
|
||||
@AuthenticationPrincipal principal: KomgaPrincipal,
|
||||
|
|
|
|||
Loading…
Reference in a new issue