Skip to content

Commit

Permalink
Add number of mangas in category to data class
Browse files Browse the repository at this point in the history
Makes it possible to display the size of a category to the user
  • Loading branch information
schroda committed Mar 12, 2023
1 parent ec1d65f commit be75f87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ object Category {
const val DEFAULT_CATEGORY_NAME = "Default"
private fun addDefaultIfNecessary(categories: List<CategoryDataClass>): List<CategoryDataClass> =
if (MangaTable.select { (MangaTable.inLibrary eq true) and (MangaTable.defaultCategory eq true) }.isNotEmpty()) {
listOf(CategoryDataClass(DEFAULT_CATEGORY_ID, 0, DEFAULT_CATEGORY_NAME, true)) + categories
listOf(CategoryDataClass(DEFAULT_CATEGORY_ID, 0, DEFAULT_CATEGORY_NAME, true, 0)) + categories
} else {
categories
}
Expand All @@ -123,6 +123,14 @@ object Category {
}
}

fun getCategorySize(categoryId: Int): Int {
return transaction {
CategoryMangaTable.select {
CategoryMangaTable.category eq categoryId
}.count().toInt()
}
}

fun getCategoryMetaMap(categoryId: Int): Map<String, String> {
return transaction {
CategoryMetaTable.select { CategoryMetaTable.ref eq categoryId }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ data class CategoryDataClass(
val order: Int,
val name: String,
val default: Boolean,
val size: Int,
val meta: Map<String, String> = emptyMap()
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ fun CategoryTable.toDataClass(categoryEntry: ResultRow) = CategoryDataClass(
categoryEntry[order],
categoryEntry[name],
categoryEntry[isDefault],
Category.getCategorySize(categoryEntry[id].value),
Category.getCategoryMetaMap(categoryEntry[id].value)
)

0 comments on commit be75f87

Please sign in to comment.