Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularize domain layer including usecase, repository and domain model #255

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0cabd33
Extract model to core
hieuwu Aug 3, 2024
3e65eee
Extract model to core
hieuwu Aug 3, 2024
ea2f0be
Extract model to core
hieuwu Aug 3, 2024
3d5c582
Extract model to core
hieuwu Aug 3, 2024
508ae87
Extract model to core
hieuwu Aug 3, 2024
2dfd743
Remove unused lib
hieuwu Aug 3, 2024
8efe384
Create shared module for models
hieuwu Aug 3, 2024
9c6fcd7
Move models to module
hieuwu Aug 3, 2024
83f610f
Update package
hieuwu Aug 3, 2024
01c8bd8
Update package
hieuwu Aug 3, 2024
09727ba
Update package
hieuwu Aug 3, 2024
7f644f8
Update package
hieuwu Aug 3, 2024
d306625
Update package
hieuwu Aug 3, 2024
8b0a9b1
Update package
hieuwu Aug 3, 2024
2c72531
Update package
hieuwu Aug 3, 2024
93a18d2
Update package
hieuwu Aug 3, 2024
b2724a5
Update package
hieuwu Aug 3, 2024
3b875c6
Update package
hieuwu Aug 3, 2024
9f4a4ca
Update package
hieuwu Aug 3, 2024
eec3a6d
Move dependencies module to top
hieuwu Aug 3, 2024
8f11c71
Move repository interface to domain
hieuwu Aug 4, 2024
53dd623
Restructure
hieuwu Aug 4, 2024
4de51f3
Update package
hieuwu Aug 4, 2024
1b873fa
Restructure package
hieuwu Aug 4, 2024
de0a521
Update imports
hieuwu Aug 4, 2024
303c404
Update package
hieuwu Aug 4, 2024
eb1e1c4
Refactor use case and repository
hieuwu Aug 4, 2024
1f0d664
Refactor use case and repository
hieuwu Aug 4, 2024
e28d06c
Refactor use case and repository
hieuwu Aug 4, 2024
6db2132
Remove unused imports
hieuwu Aug 4, 2024
5a70fcf
Move repository interface to domain
hieuwu Aug 4, 2024
097bfad
Add dependency for lib
hieuwu Aug 4, 2024
ebd968f
Update tests
hieuwu Aug 4, 2024
e9b5759
Refactor use case to use new repository
hieuwu Aug 4, 2024
4752608
Update idea
hieuwu Aug 4, 2024
0e2b843
Update test
hieuwu Aug 4, 2024
1cd25d7
Extract use case interfaces
hieuwu Aug 4, 2024
084f2e0
Update code
hieuwu Aug 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ android {
}

dependencies {
implementation project(':models')

implementation fileTree(dir: "libs", include: ["*.jar"])
implementation libs.bundles.androidx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import androidx.annotation.NonNull
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.hieuwu.groceriesstore.domain.models.CategoryModel
import com.hieuwu.groceriesstore.models.CategoryModel
import com.hieuwu.groceriesstore.utilities.CATEGORY_TABLE

@Entity(tableName = CATEGORY_TABLE)
data class Category(
@PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.hieuwu.groceriesstore.data.database.entities

import androidx.room.Embedded
import androidx.room.Relation
import com.hieuwu.groceriesstore.domain.models.OrderModel
import com.hieuwu.groceriesstore.models.OrderModel

data class OrderWithLineItems(
@Embedded var order: Order,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.annotation.NonNull
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.hieuwu.groceriesstore.domain.models.ProductModel
import com.hieuwu.groceriesstore.models.ProductModel
import com.hieuwu.groceriesstore.utilities.PRODUCT_TABLE

@Entity(tableName = PRODUCT_TABLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.hieuwu.groceriesstore.data.database.entities

import androidx.room.Embedded
import androidx.room.Relation
import com.hieuwu.groceriesstore.domain.models.LineItemModel
import com.hieuwu.groceriesstore.models.LineItemModel

data class ProductAndLineItem(
@Embedded val lineItem: LineItem?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.hieuwu.groceriesstore.data.database.entities
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.hieuwu.groceriesstore.domain.models.RecipeModel
import com.hieuwu.groceriesstore.models.RecipeModel
import com.hieuwu.groceriesstore.utilities.RECIPE_TABLE

@Entity(tableName = RECIPE_TABLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.hieuwu.groceriesstore.data.database.entities
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.hieuwu.groceriesstore.domain.models.UserModel
import com.hieuwu.groceriesstore.models.UserModel
import com.hieuwu.groceriesstore.utilities.USER_TABLE

@Entity(tableName = USER_TABLE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
package com.hieuwu.groceriesstore.data.repository.impl
import com.hieuwu.groceriesstore.data.database.dao.CategoryDao
import com.hieuwu.groceriesstore.data.database.entities.Category
import com.hieuwu.groceriesstore.data.database.entities.asDomainModel
import com.hieuwu.groceriesstore.data.network.RemoteTable
import com.hieuwu.groceriesstore.data.network.dto.CategoriesDto
import com.hieuwu.groceriesstore.data.repository.CategoryRepository
import io.github.jan.supabase.postgrest.Postgrest
import kotlinx.coroutines.flow.map
import timber.log.Timber
import javax.inject.Inject
class CategoryRepositoryImpl @Inject constructor(
private val categoryDao: CategoryDao,
private val supabasePostgrest: Postgrest
) :
CategoryRepository {
override suspend fun refreshDatabase() {
try {
val result = supabasePostgrest[RemoteTable.Categories.tableName]
.select()
val res = result.decodeList<CategoriesDto>()
val categories = res.map { it.asEntity() }
categoryDao.insertAll(categories)
} catch (e: Exception) {
Timber.e(e.message)
}
}
override fun getFromLocal() = categoryDao.getAll().map { it.asDomainModel() }
private fun CategoriesDto.asEntity(): Category = Category(
id = id,
name = name,
image = image,
)
}
package com.hieuwu.groceriesstore.data.repository

import com.hieuwu.groceriesstore.data.database.dao.CategoryDao
import com.hieuwu.groceriesstore.data.database.entities.Category
import com.hieuwu.groceriesstore.data.database.entities.asDomainModel
import com.hieuwu.groceriesstore.data.network.RemoteTable
import com.hieuwu.groceriesstore.data.network.dto.CategoriesDto
import com.hieuwu.groceriesstore.repository.CategoryRepository
import io.github.jan.supabase.postgrest.Postgrest
import kotlinx.coroutines.flow.map
import timber.log.Timber
import javax.inject.Inject

class CategoryRepositoryImpl @Inject constructor(
private val categoryDao: CategoryDao,
private val supabasePostgrest: Postgrest
) :
CategoryRepository {

override suspend fun refreshDatabase() {
try {
val result = supabasePostgrest[RemoteTable.Categories.tableName]
.select()
val res = result.decodeList<CategoriesDto>()
val categories = res.map { it.asEntity() }
categoryDao.insertAll(categories)
} catch (e: Exception) {
Timber.e(e.message)
}
}

override fun getFromLocal() = categoryDao.getAll().map { it.asDomainModel() }

private fun CategoriesDto.asEntity(): Category = Category(
id = id,
name = name,
image = image,
)

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.hieuwu.groceriesstore.data.repository.impl
package com.hieuwu.groceriesstore.data.repository

import com.hieuwu.groceriesstore.data.network.dto.Meal
import com.hieuwu.groceriesstore.data.repository.MealPlanRepository
import com.hieuwu.groceriesstore.data.repository.UserRepository
import com.hieuwu.groceriesstore.domain.models.MealModel
import com.hieuwu.groceriesstore.repository.MealPlanRepository
import com.hieuwu.groceriesstore.repository.UserRepository
import com.hieuwu.groceriesstore.models.MealModel
import com.hieuwu.groceriesstore.utilities.SupabaseHelper
import io.github.jan.supabase.postgrest.Postgrest
import io.github.jan.supabase.storage.Storage
Expand Down

This file was deleted.

Loading
Loading