Skip to content

Commit

Permalink
Fix/graphql mangas query genre based filtering (#713)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
schroda authored Oct 16, 2023
1 parent c56bdea commit 0ba6c88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0ba6c88

Please sign in to comment.