mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-25 18:47:51 +02:00
Move Category model
and repository
to domain and data layer (#8967)
To keep the commit from being 100+ files the interactors wasn't moved. The domain module like the data module uses `tachiyomi` instead of `eu.kanade.tachiyomi` for package names
This commit is contained in:
@ -21,6 +21,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation(project(":source-api"))
|
||||
implementation(project(":domain"))
|
||||
api(libs.sqldelight.android.driver)
|
||||
api(libs.sqldelight.coroutines)
|
||||
api(libs.sqldelight.android.paging)
|
||||
|
@ -1,4 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
<manifest />
|
12
data/src/main/java/tachiyomi/data/category/CategoryMapper.kt
Normal file
12
data/src/main/java/tachiyomi/data/category/CategoryMapper.kt
Normal file
@ -0,0 +1,12 @@
|
||||
package tachiyomi.data.category
|
||||
|
||||
import tachiyomi.domain.category.model.Category
|
||||
|
||||
val categoryMapper: (Long, String, Long, Long) -> Category = { id, name, order, flags ->
|
||||
Category(
|
||||
id = id,
|
||||
name = name,
|
||||
order = order,
|
||||
flags = flags,
|
||||
)
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package tachiyomi.data.category
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import tachiyomi.data.Database
|
||||
import tachiyomi.data.DatabaseHandler
|
||||
import tachiyomi.domain.category.model.Category
|
||||
import tachiyomi.domain.category.model.CategoryUpdate
|
||||
import tachiyomi.domain.category.repository.CategoryRepository
|
||||
|
||||
class CategoryRepositoryImpl(
|
||||
private val handler: DatabaseHandler,
|
||||
) : CategoryRepository {
|
||||
|
||||
override suspend fun get(id: Long): Category? {
|
||||
return handler.awaitOneOrNull { categoriesQueries.getCategory(id, categoryMapper) }
|
||||
}
|
||||
|
||||
override suspend fun getAll(): List<Category> {
|
||||
return handler.awaitList { categoriesQueries.getCategories(categoryMapper) }
|
||||
}
|
||||
|
||||
override fun getAllAsFlow(): Flow<List<Category>> {
|
||||
return handler.subscribeToList { categoriesQueries.getCategories(categoryMapper) }
|
||||
}
|
||||
|
||||
override suspend fun getCategoriesByMangaId(mangaId: Long): List<Category> {
|
||||
return handler.awaitList {
|
||||
categoriesQueries.getCategoriesByMangaId(mangaId, categoryMapper)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCategoriesByMangaIdAsFlow(mangaId: Long): Flow<List<Category>> {
|
||||
return handler.subscribeToList {
|
||||
categoriesQueries.getCategoriesByMangaId(mangaId, categoryMapper)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun insert(category: Category) {
|
||||
handler.await {
|
||||
categoriesQueries.insert(
|
||||
name = category.name,
|
||||
order = category.order,
|
||||
flags = category.flags,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updatePartial(update: CategoryUpdate) {
|
||||
handler.await {
|
||||
updatePartialBlocking(update)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updatePartial(updates: List<CategoryUpdate>) {
|
||||
handler.await(inTransaction = true) {
|
||||
for (update in updates) {
|
||||
updatePartialBlocking(update)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Database.updatePartialBlocking(update: CategoryUpdate) {
|
||||
categoriesQueries.update(
|
||||
name = update.name,
|
||||
order = update.order,
|
||||
flags = update.flags,
|
||||
categoryId = update.id,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun updateAllFlags(flags: Long?) {
|
||||
handler.await {
|
||||
categoriesQueries.updateAllFlags(flags)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun delete(categoryId: Long) {
|
||||
handler.await {
|
||||
categoriesQueries.delete(
|
||||
categoryId = categoryId,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user