From 422876ae2fd676459ae84f54d9bd6878828d714d Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Fri, 30 Jul 2021 17:07:03 +0800 Subject: [PATCH] feat(api): search authors and tags by read list --- .../persistence/ReferentialRepository.kt | 2 ++ .../infrastructure/jooq/ReferentialDao.kt | 22 +++++++++++++++++++ .../interfaces/rest/ReferentialController.kt | 4 ++++ 3 files changed, 28 insertions(+) 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 f7766057..79dac775 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 @@ -17,6 +17,7 @@ interface ReferentialRepository { fun findAllAuthorsByNameAndLibrary(search: String?, role: String?, libraryId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page fun findAllAuthorsByNameAndCollection(search: String?, role: String?, collectionId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page fun findAllAuthorsByNameAndSeries(search: String?, role: String?, seriesId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page + fun findAllAuthorsByNameAndReadList(search: String?, role: String?, readListId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page fun findAllGenres(filterOnLibraryIds: Collection?): Set fun findAllGenresByLibrary(libraryId: String, filterOnLibraryIds: Collection?): Set @@ -30,6 +31,7 @@ interface ReferentialRepository { fun findAllSeriesTagsByCollection(collectionId: String, filterOnLibraryIds: Collection?): Set fun findAllBookTags(filterOnLibraryIds: Collection?): Set fun findAllBookTagsBySeries(seriesId: String, filterOnLibraryIds: Collection?): Set + fun findAllBookTagsByReadList(readListId: String, filterOnLibraryIds: Collection?): Set fun findAllLanguages(filterOnLibraryIds: Collection?): Set fun findAllLanguagesByLibrary(libraryId: String, filterOnLibraryIds: Collection?): 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 bdadebb9..e20392a0 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 @@ -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?): List = @@ -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?, pageable: Pageable): Page { + 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?): Set = + 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?): Set = dsl.select(st.TAG) .from(st) 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 aefb2ec2..fe312994 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 @@ -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 { @@ -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 = 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)) }