mirror of
https://github.com/gotson/komga.git
synced 2026-05-09 05:10:19 +02:00
fix(api): ignore search parameter when blank
This commit is contained in:
parent
9d9a73f8b2
commit
48637e26e4
7 changed files with 26 additions and 22 deletions
|
|
@ -13,10 +13,10 @@ interface ReferentialRepository {
|
||||||
fun findAllAuthorsNamesByName(search: String, filterOnLibraryIds: Collection<String>?): List<String>
|
fun findAllAuthorsNamesByName(search: String, filterOnLibraryIds: Collection<String>?): List<String>
|
||||||
fun findAllAuthorsRoles(filterOnLibraryIds: Collection<String>?): List<String>
|
fun findAllAuthorsRoles(filterOnLibraryIds: Collection<String>?): List<String>
|
||||||
|
|
||||||
fun findAllAuthorsByName(search: String, role: String?, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author>
|
fun findAllAuthorsByName(search: String?, role: String?, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author>
|
||||||
fun findAllAuthorsByNameAndLibrary(search: String, role: String?, libraryId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author>
|
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 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 findAllAuthorsByNameAndSeries(search: String?, role: String?, seriesId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author>
|
||||||
|
|
||||||
fun findAllGenres(filterOnLibraryIds: Collection<String>?): Set<String>
|
fun findAllGenres(filterOnLibraryIds: Collection<String>?): Set<String>
|
||||||
fun findAllGenresByLibrary(libraryId: String, filterOnLibraryIds: Collection<String>?): Set<String>
|
fun findAllGenresByLibrary(libraryId: String, filterOnLibraryIds: Collection<String>?): Set<String>
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,7 @@ class BookDtoDao(
|
||||||
private fun BookSearchWithReadProgress.toCondition(): Condition {
|
private fun BookSearchWithReadProgress.toCondition(): Condition {
|
||||||
var c: Condition = DSL.trueCondition()
|
var c: Condition = DSL.trueCondition()
|
||||||
|
|
||||||
searchTerm?.let { c = c.and(fts.match(it)) }
|
if (!searchTerm.isNullOrBlank()) c = c.and(fts.match(searchTerm))
|
||||||
if (!libraryIds.isNullOrEmpty()) c = c.and(b.LIBRARY_ID.`in`(libraryIds))
|
if (!libraryIds.isNullOrEmpty()) c = c.and(b.LIBRARY_ID.`in`(libraryIds))
|
||||||
if (!seriesIds.isNullOrEmpty()) c = c.and(b.SERIES_ID.`in`(seriesIds))
|
if (!seriesIds.isNullOrEmpty()) c = c.and(b.SERIES_ID.`in`(seriesIds))
|
||||||
if (!mediaStatus.isNullOrEmpty()) c = c.and(m.STATUS.`in`(mediaStatus))
|
if (!mediaStatus.isNullOrEmpty()) c = c.and(m.STATUS.`in`(mediaStatus))
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ class ReadListDao(
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
|
|
||||||
override fun findAll(search: String?, pageable: Pageable): Page<ReadList> {
|
override fun findAll(search: String?, pageable: Pageable): Page<ReadList> {
|
||||||
val conditions = search?.let { searchCondition(it) }
|
val conditions = if (!search.isNullOrBlank()) searchCondition(search)
|
||||||
?: DSL.trueCondition()
|
else DSL.trueCondition()
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val count = dsl.selectCount()
|
val count = dsl.selectCount()
|
||||||
|
|
@ -87,7 +87,7 @@ class ReadListDao(
|
||||||
|
|
||||||
override fun findAllByLibraryIds(belongsToLibraryIds: Collection<String>, filterOnLibraryIds: Collection<String>?, search: String?, pageable: Pageable): Page<ReadList> {
|
override fun findAllByLibraryIds(belongsToLibraryIds: Collection<String>, filterOnLibraryIds: Collection<String>?, search: String?, pageable: Pageable): Page<ReadList> {
|
||||||
val conditions = b.LIBRARY_ID.`in`(belongsToLibraryIds)
|
val conditions = b.LIBRARY_ID.`in`(belongsToLibraryIds)
|
||||||
.apply { search?.let { and(searchCondition(it)) } }
|
.apply { if (!search.isNullOrBlank()) and(searchCondition(search)) }
|
||||||
.apply { filterOnLibraryIds?.let { and(b.LIBRARY_ID.`in`(it)) } }
|
.apply { filterOnLibraryIds?.let { and(b.LIBRARY_ID.`in`(it)) } }
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import org.jooq.DSLContext
|
||||||
import org.jooq.impl.DSL.field
|
import org.jooq.impl.DSL.field
|
||||||
import org.jooq.impl.DSL.lower
|
import org.jooq.impl.DSL.lower
|
||||||
import org.jooq.impl.DSL.select
|
import org.jooq.impl.DSL.select
|
||||||
|
import org.jooq.impl.DSL.trueCondition
|
||||||
import org.springframework.data.domain.Page
|
import org.springframework.data.domain.Page
|
||||||
import org.springframework.data.domain.PageImpl
|
import org.springframework.data.domain.PageImpl
|
||||||
import org.springframework.data.domain.PageRequest
|
import org.springframework.data.domain.PageRequest
|
||||||
|
|
@ -82,19 +83,19 @@ class ReferentialDao(
|
||||||
.fetchInto(bmaa)
|
.fetchInto(bmaa)
|
||||||
.map { it.toDomain() }
|
.map { it.toDomain() }
|
||||||
|
|
||||||
override fun findAllAuthorsByName(search: String, role: String?, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author> {
|
override fun findAllAuthorsByName(search: String?, role: String?, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author> {
|
||||||
return findAuthorsByName(search, role, filterOnLibraryIds, pageable, null)
|
return findAuthorsByName(search, role, filterOnLibraryIds, pageable, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun findAllAuthorsByNameAndLibrary(search: String, role: String?, libraryId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author> {
|
override fun findAllAuthorsByNameAndLibrary(search: String?, role: String?, libraryId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author> {
|
||||||
return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.LIBRARY, libraryId))
|
return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.LIBRARY, libraryId))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun findAllAuthorsByNameAndCollection(search: String, role: String?, collectionId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author> {
|
override fun findAllAuthorsByNameAndCollection(search: String?, role: String?, collectionId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author> {
|
||||||
return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.COLLECTION, collectionId))
|
return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.COLLECTION, collectionId))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun findAllAuthorsByNameAndSeries(search: String, role: String?, seriesId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author> {
|
override fun findAllAuthorsByNameAndSeries(search: String?, role: String?, seriesId: String, filterOnLibraryIds: Collection<String>?, pageable: Pageable): Page<Author> {
|
||||||
return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.SERIES, seriesId))
|
return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.SERIES, seriesId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,14 +110,15 @@ class ReferentialDao(
|
||||||
val id: String,
|
val id: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun findAuthorsByName(search: String, role: String?, filterOnLibraryIds: Collection<String>?, pageable: Pageable, filterBy: FilterBy?): Page<Author> {
|
private fun findAuthorsByName(search: String?, role: String?, filterOnLibraryIds: Collection<String>?, pageable: Pageable, filterBy: FilterBy?): Page<Author> {
|
||||||
return try {
|
return try {
|
||||||
val query = dsl.selectDistinct(bmaa.NAME, bmaa.ROLE)
|
val query = dsl.selectDistinct(bmaa.NAME, bmaa.ROLE)
|
||||||
.from(bmaa)
|
.from(bmaa)
|
||||||
.join(ftsAuthors).on(ftsAuthors.rowid().eq(bmaa.rowid()))
|
.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 (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.COLLECTION) leftJoin(cs).on(bmaa.SERIES_ID.eq(cs.SERIES_ID)) }
|
||||||
.where(ftsAuthors.match(search))
|
.where(trueCondition())
|
||||||
|
.apply { if (!search.isNullOrBlank()) and(ftsAuthors.match(search)) }
|
||||||
.apply { role?.let { and(bmaa.ROLE.eq(role)) } }
|
.apply { role?.let { and(bmaa.ROLE.eq(role)) } }
|
||||||
.apply { filterOnLibraryIds?.let { and(s.LIBRARY_ID.`in`(it)) } }
|
.apply { filterOnLibraryIds?.let { and(s.LIBRARY_ID.`in`(it)) } }
|
||||||
.apply {
|
.apply {
|
||||||
|
|
@ -130,9 +132,11 @@ class ReferentialDao(
|
||||||
}
|
}
|
||||||
|
|
||||||
val count = dsl.fetchCount(query)
|
val count = dsl.fetchCount(query)
|
||||||
|
val sort = if (!search.isNullOrBlank()) field("rank")
|
||||||
|
else lower(bmaa.NAME.udfStripAccents())
|
||||||
|
|
||||||
val items = query
|
val items = query
|
||||||
.orderBy(field("rank"))
|
.orderBy(sort)
|
||||||
.apply { if (pageable.isPaged) limit(pageable.pageSize).offset(pageable.offset) }
|
.apply { if (pageable.isPaged) limit(pageable.pageSize).offset(pageable.offset) }
|
||||||
.fetchInto(a)
|
.fetchInto(a)
|
||||||
.map { it.toDomain() }
|
.map { it.toDomain() }
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ class SeriesCollectionDao(
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
|
|
||||||
override fun findAll(search: String?, pageable: Pageable): Page<SeriesCollection> {
|
override fun findAll(search: String?, pageable: Pageable): Page<SeriesCollection> {
|
||||||
val conditions = search?.let { searchCondition(search) }
|
val conditions = if (!search.isNullOrBlank()) searchCondition(search)
|
||||||
?: DSL.trueCondition()
|
else DSL.trueCondition()
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val count = dsl.selectCount()
|
val count = dsl.selectCount()
|
||||||
|
|
@ -86,7 +86,7 @@ class SeriesCollectionDao(
|
||||||
|
|
||||||
override fun findAllByLibraryIds(belongsToLibraryIds: Collection<String>, filterOnLibraryIds: Collection<String>?, search: String?, pageable: Pageable): Page<SeriesCollection> {
|
override fun findAllByLibraryIds(belongsToLibraryIds: Collection<String>, filterOnLibraryIds: Collection<String>?, search: String?, pageable: Pageable): Page<SeriesCollection> {
|
||||||
val conditions = s.LIBRARY_ID.`in`(belongsToLibraryIds)
|
val conditions = s.LIBRARY_ID.`in`(belongsToLibraryIds)
|
||||||
.apply { search?.let { and(searchCondition(it)) } }
|
.apply { if (!search.isNullOrBlank()) and(searchCondition(search)) }
|
||||||
.apply { filterOnLibraryIds?.let { and(s.LIBRARY_ID.`in`(it)) } }
|
.apply { filterOnLibraryIds?.let { and(s.LIBRARY_ID.`in`(it)) } }
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
|
|
|
||||||
|
|
@ -251,7 +251,7 @@ class SeriesDtoDao(
|
||||||
private fun SeriesSearchWithReadProgress.toCondition(): Condition {
|
private fun SeriesSearchWithReadProgress.toCondition(): Condition {
|
||||||
var c: Condition = DSL.trueCondition()
|
var c: Condition = DSL.trueCondition()
|
||||||
|
|
||||||
searchTerm?.let { c = c.and(fts.match(it)) }
|
if (!searchTerm.isNullOrBlank()) c = c.and(fts.match(searchTerm))
|
||||||
if (!libraryIds.isNullOrEmpty()) c = c.and(s.LIBRARY_ID.`in`(libraryIds))
|
if (!libraryIds.isNullOrEmpty()) c = c.and(s.LIBRARY_ID.`in`(libraryIds))
|
||||||
if (!collectionIds.isNullOrEmpty()) c = c.and(cs.COLLECTION_ID.`in`(collectionIds))
|
if (!collectionIds.isNullOrEmpty()) c = c.and(cs.COLLECTION_ID.`in`(collectionIds))
|
||||||
searchRegex?.let { c = c.and((it.second.toColumn()).likeRegex(it.first)) }
|
searchRegex?.let { c = c.and((it.second.toColumn()).likeRegex(it.first)) }
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ class ReferentialController(
|
||||||
@GetMapping("v2/authors")
|
@GetMapping("v2/authors")
|
||||||
fun getAuthors(
|
fun getAuthors(
|
||||||
@AuthenticationPrincipal principal: KomgaPrincipal,
|
@AuthenticationPrincipal principal: KomgaPrincipal,
|
||||||
@RequestParam(name = "search", defaultValue = "") search: String,
|
@RequestParam(name = "search", required = false) search: String?,
|
||||||
@RequestParam(name = "role") role: String?,
|
@RequestParam(name = "role", required = false) role: String?,
|
||||||
@RequestParam(name = "library_id", required = false) libraryId: String?,
|
@RequestParam(name = "library_id", required = false) libraryId: String?,
|
||||||
@RequestParam(name = "collection_id", required = false) collectionId: String?,
|
@RequestParam(name = "collection_id", required = false) collectionId: String?,
|
||||||
@RequestParam(name = "series_id", required = false) seriesId: String?,
|
@RequestParam(name = "series_id", required = false) seriesId: String?,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue