Fix/graphql mangas query genre based filtering (#713)

* Filter mangas based on each genre of the genre condition

Genres are stored as a comma separated string in the database.
Thus, unless the correct string was passed in the condition, no manga would match the condition.

* Query mangas based on genre filter
This commit is contained in:
schroda
2023-10-16 02:14:20 +02:00
committed by GitHub
parent c56bdea1e2
commit 0ba6c88d69
2 changed files with 8 additions and 2 deletions

View File

@@ -122,7 +122,7 @@ class MangaQuery {
opAnd.eq(artist, MangaTable.artist)
opAnd.eq(author, MangaTable.author)
opAnd.eq(description, MangaTable.description)
opAnd.eq(genre?.joinToString(), MangaTable.genre)
genre?.forEach { opAnd.like("%$it%", MangaTable.genre) }
opAnd.eq(status?.value, MangaTable.status)
opAnd.eq(inLibrary, MangaTable.inLibrary)
opAnd.eq(inLibraryAt, MangaTable.inLibraryAt)
@@ -172,7 +172,7 @@ class MangaQuery {
val artist: StringFilter? = null,
val author: StringFilter? = null,
val description: StringFilter? = null,
// val genre: List<String>? = null, // todo
val genre: StringFilter? = null,
val status: MangaStatusFilter? = null,
val inLibrary: BooleanFilter? = null,
val inLibraryAt: LongFilter? = null,
@@ -194,6 +194,7 @@ class MangaQuery {
andFilterWithCompareString(MangaTable.artist, artist),
andFilterWithCompareString(MangaTable.author, author),
andFilterWithCompareString(MangaTable.description, description),
andFilterWithCompareString(MangaTable.genre, genre),
andFilterWithCompare(MangaTable.status, status?.asIntFilter()),
andFilterWithCompare(MangaTable.inLibrary, inLibrary),
andFilterWithCompare(MangaTable.inLibraryAt, inLibraryAt),

View File

@@ -391,6 +391,11 @@ class OpAnd(var op: Op<Boolean>? = null) {
value: T?,
column: Column<EntityID<T>>,
) = andWhere(value) { column eq it }
fun like(
value: String?,
column: Column<String?>,
) = andWhere(value) { column like it }
}
fun <T : Comparable<T>> andFilterWithCompare(