mirror of
https://github.com/gotson/komga.git
synced 2026-05-09 05:10:19 +02:00
feat(api): search authors and tags by read list
This commit is contained in:
parent
c06f89ffc2
commit
422876ae2f
3 changed files with 28 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ interface ReferentialRepository {
|
|||
fun findAllAuthorsByNameAndLibrary(search: String?, role: String?, libraryId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author>
|
||||
fun findAllAuthorsByNameAndCollection(search: String?, role: String?, collectionId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author>
|
||||
fun findAllAuthorsByNameAndSeries(search: String?, role: String?, seriesId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author>
|
||||
fun findAllAuthorsByNameAndReadList(search: String?, role: String?, readListId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author>
|
||||
|
||||
fun findAllGenres(filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
fun findAllGenresByLibrary(libraryId: String, filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
|
|
@ -30,6 +31,7 @@ interface ReferentialRepository {
|
|||
fun findAllSeriesTagsByCollection(collectionId: String, filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
fun findAllBookTags(filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
fun findAllBookTagsBySeries(seriesId: String, filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
fun findAllBookTagsByReadList(readListId: String, filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
|
||||
fun findAllLanguages(filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
fun findAllLanguagesByLibrary(libraryId: String, filterOnLibraryIds: Collection<String>?): Set<String>
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ class ReferentialDao(
|
|||
private val bt = Tables.BOOK_METADATA_TAG
|
||||
private val st = Tables.SERIES_METADATA_TAG
|
||||
private val cs = Tables.COLLECTION_SERIES
|
||||
private val rb = Tables.READLIST_BOOK
|
||||
private val ftsAuthors = Tables.FTS_BOOK_METADATA_AGGREGATION_AUTHOR
|
||||
|
||||
override fun findAllAuthorsByName(search: String, filterOnLibraryIds: Collection<String>?): List<Author> =
|
||||
|
|
@ -100,10 +101,15 @@ class ReferentialDao(
|
|||
return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.SERIES, seriesId))
|
||||
}
|
||||
|
||||
override fun findAllAuthorsByNameAndReadList(search: String?, role: String?, readListId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author> {
|
||||
return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.READLIST, readListId))
|
||||
}
|
||||
|
||||
private enum class FilterByType {
|
||||
LIBRARY,
|
||||
COLLECTION,
|
||||
SERIES,
|
||||
READLIST,
|
||||
}
|
||||
|
||||
private data class FilterBy(
|
||||
|
|
@ -118,6 +124,11 @@ class ReferentialDao(
|
|||
.apply { if (!search.isNullOrBlank()) join(ftsAuthors).on(ftsAuthors.rowid().eq(bmaa.rowid())) }
|
||||
.apply { if (filterOnLibraryIds != null || filterBy?.type == FilterByType.LIBRARY) leftJoin(s).on(bmaa.SERIES_ID.eq(s.ID)) }
|
||||
.apply { if (filterBy?.type == FilterByType.COLLECTION) leftJoin(cs).on(bmaa.SERIES_ID.eq(cs.SERIES_ID)) }
|
||||
.apply {
|
||||
if (filterBy?.type == FilterByType.READLIST)
|
||||
leftJoin(b).on(bmaa.SERIES_ID.eq(b.SERIES_ID))
|
||||
.leftJoin(rb).on(b.ID.eq(rb.BOOK_ID))
|
||||
}
|
||||
.where(trueCondition())
|
||||
.apply { if (!search.isNullOrBlank()) and(ftsAuthors.match(search)) }
|
||||
.apply { role?.let { and(bmaa.ROLE.eq(role)) } }
|
||||
|
|
@ -128,6 +139,7 @@ class ReferentialDao(
|
|||
FilterByType.LIBRARY -> and(s.LIBRARY_ID.eq(it.id))
|
||||
FilterByType.COLLECTION -> and(cs.COLLECTION_ID.eq(it.id))
|
||||
FilterByType.SERIES -> and(bmaa.SERIES_ID.eq(it.id))
|
||||
FilterByType.READLIST -> and(rb.READLIST_ID.eq(it.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -289,6 +301,16 @@ class ReferentialDao(
|
|||
.orderBy(lower(bt.TAG.udfStripAccents()))
|
||||
.fetchSet(bt.TAG)
|
||||
|
||||
override fun findAllBookTagsByReadList(readListId: String, filterOnLibraryIds: Collection<String>?): Set<String> =
|
||||
dsl.select(bt.TAG)
|
||||
.from(bt)
|
||||
.leftJoin(b).on(bt.BOOK_ID.eq(b.ID))
|
||||
.leftJoin(rb).on(bt.BOOK_ID.eq(rb.BOOK_ID))
|
||||
.where(rb.READLIST_ID.eq(readListId))
|
||||
.apply { filterOnLibraryIds?.let { and(b.LIBRARY_ID.`in`(it)) } }
|
||||
.orderBy(lower(bt.TAG.udfStripAccents()))
|
||||
.fetchSet(bt.TAG)
|
||||
|
||||
override fun findAllSeriesTagsByCollection(collectionId: String, filterOnLibraryIds: Collection<String>?): Set<String> =
|
||||
dsl.select(st.TAG)
|
||||
.from(st)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class ReferentialController(
|
|||
@RequestParam(name = "library_id", required = false) libraryId: String?,
|
||||
@RequestParam(name = "collection_id", required = false) collectionId: String?,
|
||||
@RequestParam(name = "series_id", required = false) seriesId: String?,
|
||||
@RequestParam(name = "readlist_id", required = false) readListId: String?,
|
||||
@RequestParam(name = "unpaged", required = false) unpaged: Boolean = false,
|
||||
@Parameter(hidden = true) page: Pageable,
|
||||
): Page<AuthorDto> {
|
||||
|
|
@ -61,6 +62,7 @@ class ReferentialController(
|
|||
libraryId != null -> referentialRepository.findAllAuthorsByNameAndLibrary(search, role, libraryId, principal.user.getAuthorizedLibraryIds(null), pageRequest)
|
||||
collectionId != null -> referentialRepository.findAllAuthorsByNameAndCollection(search, role, collectionId, principal.user.getAuthorizedLibraryIds(null), pageRequest)
|
||||
seriesId != null -> referentialRepository.findAllAuthorsByNameAndSeries(search, role, seriesId, principal.user.getAuthorizedLibraryIds(null), pageRequest)
|
||||
readListId != null -> referentialRepository.findAllAuthorsByNameAndReadList(search, role, readListId, principal.user.getAuthorizedLibraryIds(null), pageRequest)
|
||||
else -> referentialRepository.findAllAuthorsByName(search, role, principal.user.getAuthorizedLibraryIds(null), pageRequest)
|
||||
}.map { it.toDto() }
|
||||
}
|
||||
|
|
@ -106,9 +108,11 @@ class ReferentialController(
|
|||
fun getBookTags(
|
||||
@AuthenticationPrincipal principal: KomgaPrincipal,
|
||||
@RequestParam(name = "series_id", required = false) seriesId: String?,
|
||||
@RequestParam(name = "readlist_id", required = false) readListId: String?,
|
||||
): Set<String> =
|
||||
when {
|
||||
seriesId != null -> referentialRepository.findAllBookTagsBySeries(seriesId, principal.user.getAuthorizedLibraryIds(null))
|
||||
readListId != null -> referentialRepository.findAllBookTagsByReadList(readListId, principal.user.getAuthorizedLibraryIds(null))
|
||||
else -> referentialRepository.findAllBookTags(principal.user.getAuthorizedLibraryIds(null))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue