-
Notifications
You must be signed in to change notification settings - Fork 0
Change something #2
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
Changes from all commits
ec6e500
8d2712b
194b270
4ef532d
54c7fd8
d1a0173
432d653
5e31d36
aa671e8
dc94e15
332ddbb
98cff50
77b9eb1
d8115e9
a304e7e
26a1236
56cafe5
3e11c22
d8194ea
3c29eae
8c9c32b
17d8d0a
fa83c30
b8414e7
ba0ebb9
8db9697
acd251d
6afadd7
ac0fb71
bd31843
42433af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.mychefassistant.core.data.datasource | ||
|
||
import com.mychefassistant.core.domain.Grocery | ||
import com.mychefassistant.core.domain.Kitchen | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface GroceryDataSource { | ||
suspend fun add(kitchen: Kitchen, grocery: Grocery) | ||
|
||
fun getAll(kitchen: Kitchen): Flow<List<Grocery>> | ||
|
||
suspend fun remove(kitchen: Kitchen, grocery: Grocery) | ||
|
||
suspend fun update(kitchen: Kitchen, grocery: Grocery) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.mychefassistant.core.data.repository | ||
|
||
import com.mychefassistant.core.data.datasource.GroceryDataSource | ||
import com.mychefassistant.core.domain.Grocery | ||
import com.mychefassistant.core.domain.Kitchen | ||
|
||
class GroceryRepository(private val dataSource: GroceryDataSource) { | ||
suspend fun addGrocery(kitchen: Kitchen, grocery: Grocery) = dataSource.add(kitchen, grocery) | ||
|
||
fun getGroceries(kitchen: Kitchen) = dataSource.getAll(kitchen) | ||
|
||
suspend fun removeGrocery(kitchen: Kitchen, grocery: Grocery) = | ||
dataSource.remove(kitchen, grocery) | ||
|
||
suspend fun updateGrocery(kitchen: Kitchen, grocery: Grocery) = | ||
dataSource.update(kitchen, grocery) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.mychefassistant.core.domain | ||
|
||
data class Grocery( | ||
val id: Int = 0, | ||
val kitchen: Int, | ||
val title: String, | ||
val value: String = "", | ||
val status: Boolean = false | ||
) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mychefassistant.core.interactors | ||
|
||
import com.mychefassistant.core.data.repository.GroceryRepository | ||
import com.mychefassistant.core.domain.Grocery | ||
import com.mychefassistant.core.domain.Kitchen | ||
import com.mychefassistant.core.utils.BaseSuspendUseCase | ||
|
||
class AddGroceryUseCase(private val groceryRepository: GroceryRepository) : | ||
BaseSuspendUseCase<Pair<Kitchen, Grocery>, Unit>() { | ||
override suspend fun execute(parameter: Pair<Kitchen, Grocery>): Result<Unit> { | ||
return Result.success(groceryRepository.addGrocery(parameter.first, parameter.second)) | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mychefassistant.core.interactors | ||
|
||
import com.mychefassistant.core.data.repository.KitchenRepository | ||
import com.mychefassistant.core.domain.Kitchen | ||
import com.mychefassistant.core.utils.BaseSuspendUseCase | ||
|
||
class AddKitchenUseCase(private val kitchenRepository: KitchenRepository) : | ||
BaseSuspendUseCase<Kitchen, Unit>() { | ||
override suspend fun execute(parameter: Kitchen): Result<Unit> { | ||
return Result.success(kitchenRepository.addKitchen(parameter)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mychefassistant.core.interactors | ||
|
||
import com.mychefassistant.core.data.repository.KitchenRepository | ||
import com.mychefassistant.core.domain.Kitchen | ||
import com.mychefassistant.core.utils.BaseSuspendUseCase | ||
|
||
class FindKitchenUseCase(private val kitchenRepository: KitchenRepository) : | ||
BaseSuspendUseCase<Kitchen, List<Kitchen>>() { | ||
override suspend fun execute(parameter: Kitchen): Result<List<Kitchen>> { | ||
return Result.success(kitchenRepository.findKitchen(parameter)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.mychefassistant.core.interactors | ||
|
||
import com.mychefassistant.core.data.repository.GroceryRepository | ||
import com.mychefassistant.core.domain.Grocery | ||
import com.mychefassistant.core.domain.Kitchen | ||
import com.mychefassistant.core.utils.BaseSuspendUseCase | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class GetGroceriesUseCase(private val groceryRepository: GroceryRepository) : | ||
BaseSuspendUseCase<Kitchen, Flow<List<Grocery>>>() { | ||
override suspend fun execute(parameter: Kitchen): Result<Flow<List<Grocery>>> { | ||
return Result.success(groceryRepository.getGroceries(parameter)) | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mychefassistant.core.interactors | ||
|
||
import com.mychefassistant.core.data.repository.KitchenRepository | ||
import com.mychefassistant.core.domain.Kitchen | ||
import com.mychefassistant.core.utils.BaseSuspendUseCase | ||
|
||
class GetKitchenByIdUseCase(private val kitchenRepository: KitchenRepository) : | ||
BaseSuspendUseCase<Int, Kitchen>() { | ||
override suspend fun execute(parameter: Int): Result<Kitchen> { | ||
return Result.success(kitchenRepository.getKitchenById(parameter)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mychefassistant.core.interactors | ||
|
||
import com.mychefassistant.core.data.repository.KitchenRepository | ||
import com.mychefassistant.core.domain.Kitchen | ||
import com.mychefassistant.core.utils.BaseUseCase | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class GetKitchensUseCase(private val kitchenRepository: KitchenRepository) : | ||
BaseUseCase<Boolean, Flow<List<Kitchen>>>() { | ||
override fun execute(parameter: Boolean): Result<Flow<List<Kitchen>>> { | ||
return Result.success(kitchenRepository.getKitchens()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mychefassistant.core.interactors | ||
|
||
import com.mychefassistant.core.data.repository.GroceryRepository | ||
import com.mychefassistant.core.domain.Grocery | ||
import com.mychefassistant.core.domain.Kitchen | ||
import com.mychefassistant.core.utils.BaseSuspendUseCase | ||
|
||
class RemoveGroceryUseCase(private val groceryRepository: GroceryRepository) : | ||
BaseSuspendUseCase<Pair<Kitchen, Grocery>, Unit>() { | ||
override suspend fun execute(parameter: Pair<Kitchen, Grocery>): Result<Unit> { | ||
return Result.success(groceryRepository.removeGrocery(parameter.first, parameter.second)) | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mychefassistant.core.interactors | ||
|
||
import com.mychefassistant.core.data.repository.KitchenRepository | ||
import com.mychefassistant.core.domain.Kitchen | ||
import com.mychefassistant.core.utils.BaseSuspendUseCase | ||
|
||
class RemoveKitchenUseCase(private val kitchenRepository: KitchenRepository) : | ||
BaseSuspendUseCase<Kitchen, Unit>() { | ||
override suspend fun execute(parameter: Kitchen): Result<Unit> { | ||
return Result.success(kitchenRepository.removeKitchen(parameter)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mychefassistant.core.interactors | ||
|
||
import com.mychefassistant.core.data.repository.GroceryRepository | ||
import com.mychefassistant.core.domain.Grocery | ||
import com.mychefassistant.core.domain.Kitchen | ||
import com.mychefassistant.core.utils.BaseSuspendUseCase | ||
|
||
class UpdateGroceryUseCase(private val groceryRepository: GroceryRepository) : | ||
BaseSuspendUseCase<Pair<Kitchen, Grocery>, Unit>() { | ||
override suspend fun execute(parameter: Pair<Kitchen, Grocery>): Result<Unit> { | ||
return Result.success(groceryRepository.updateGrocery(parameter.first, parameter.second)) | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mychefassistant.core.interactors | ||
|
||
import com.mychefassistant.core.data.repository.KitchenRepository | ||
import com.mychefassistant.core.domain.Kitchen | ||
import com.mychefassistant.core.utils.BaseSuspendUseCase | ||
|
||
class UpdateKitchenUseCase(private val kitchenRepository: KitchenRepository) : | ||
BaseSuspendUseCase<Kitchen, Unit>() { | ||
override suspend fun execute(parameter: Kitchen): Result<Unit> { | ||
return Result.success(kitchenRepository.updateKitchen(parameter)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mychefassistant.core.utils | ||
|
||
abstract class BaseSuspendUseCase<in Request, Response> { | ||
suspend operator fun invoke(parameter: Request): Result<Response> = try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The execute function returns a Result. This means that the function is pure and will always return a value even if there is an error in the execution. So there is no need to wrap it in try-catch block. And since invoke function is just calling the execute function and returning it's value, one of them is redundant. remove one and keep the other. |
||
execute(parameter) | ||
} catch (e: Exception) { | ||
Result.failure(e) | ||
} | ||
|
||
@Throws(RuntimeException::class) | ||
protected abstract suspend fun execute(parameter: Request): Result<Response> | ||
} |
Uh oh!
There was an error while loading. Please reload this page.