From ec1005aeb6f51a68cca72552ca7a5ad38a4942aa Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:46:04 +0700 Subject: [PATCH 01/22] Use operator to simplify single method --- .../domain/usecases/impl/AddMealToPlanUseCaseImpl.kt | 2 +- .../groceriesstore/presentation/account/AccountViewModel.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/AddMealToPlanUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/AddMealToPlanUseCaseImpl.kt index 889f96c3..e9ad7a36 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/AddMealToPlanUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/AddMealToPlanUseCaseImpl.kt @@ -7,7 +7,7 @@ import javax.inject.Inject class AddMealToPlanUseCaseImpl @Inject constructor( private val mealPlanRepository: MealPlanRepository ) : AddMealToPlanUseCase { - override suspend fun execute(input: AddMealToPlanUseCase.Input): AddMealToPlanUseCase.Output { + override suspend fun invoke(input: AddMealToPlanUseCase.Input): AddMealToPlanUseCase.Output { mealPlanRepository.addMealToPlan( weekDay = input.weekDay, name = input.name, diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/account/AccountViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/account/AccountViewModel.kt index 9f60f1d4..14df78b1 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/account/AccountViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/account/AccountViewModel.kt @@ -26,7 +26,7 @@ class AccountViewModel @Inject constructor( private fun getCurrentUser() { viewModelScope.launch { - getProfileUseCase.execute(GetProfileUseCase.Input()).result.collect { + getProfileUseCase(GetProfileUseCase.Input()).result.collect { _user.value = it } } @@ -34,7 +34,7 @@ class AccountViewModel @Inject constructor( fun signOut() { viewModelScope.launch { - signOutUseCase.execute(SignOutUseCase.Input()) + signOutUseCase(SignOutUseCase.Input()) } } } From 33aa1c836aba73f451ad2b4d61bc47707d3cc7f4 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:46:08 +0700 Subject: [PATCH 02/22] Use operator to simplify single method --- .../domain/usecases/impl/AddToCartUseCaseImpl.kt | 2 +- .../presentation/checkout/CheckOutViewModel.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/AddToCartUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/AddToCartUseCaseImpl.kt index ba4f282c..0452b988 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/AddToCartUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/AddToCartUseCaseImpl.kt @@ -12,7 +12,7 @@ class AddToCartUseCaseImpl @Inject constructor( @IoDispatcher private val ioDispatcher: CoroutineDispatcher, ) : AddToCartUseCase { - override suspend fun execute(input: AddToCartUseCase.Input): AddToCartUseCase.Output { + override suspend fun invoke(input: AddToCartUseCase.Input): AddToCartUseCase.Output { withContext(ioDispatcher) { orderRepository.addLineItem(input.lineItem) } diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/checkout/CheckOutViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/checkout/CheckOutViewModel.kt index 5a0aae5e..27d2544f 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/checkout/CheckOutViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/checkout/CheckOutViewModel.kt @@ -57,7 +57,7 @@ class CheckOutViewModel @Inject constructor( private fun getCurrentCard(): Flow? { var res: Flow? = null viewModelScope.launch { - res = getCurrentCartUseCase.execute(GetCurrentCartUseCase.Input()).result + res = getCurrentCartUseCase(GetCurrentCartUseCase.Input()).result } return res } @@ -65,7 +65,7 @@ class CheckOutViewModel @Inject constructor( private fun getCurrentUser(): Flow? { var res: Flow? = null viewModelScope.launch { - res = getProfileUseCase.execute(GetProfileUseCase.Input()).result + res = getProfileUseCase(GetProfileUseCase.Input()).result } return res } @@ -75,7 +75,7 @@ class CheckOutViewModel @Inject constructor( setOrderAddress() viewModelScope.launch { _isOrderSentSuccessful.value = - submitOrderUseCase.execute(SubmitOrderUseCase.Input(order.value!!)).result + submitOrderUseCase(SubmitOrderUseCase.Input(order.value!!)).result } } } From 627b57317b687c5d6a63de4934bdf015ff357d52 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:46:19 +0700 Subject: [PATCH 03/22] Use operator to simplify single method --- .../usecases/impl/CreateNewOrderUseCaseImpl.kt | 2 +- .../presentation/explore/ExploreViewModel.kt | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/CreateNewOrderUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/CreateNewOrderUseCaseImpl.kt index 8737abae..de24d369 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/CreateNewOrderUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/CreateNewOrderUseCaseImpl.kt @@ -12,7 +12,7 @@ class CreateNewOrderUseCaseImpl @Inject constructor( @IoDispatcher private val ioDispatcher: CoroutineDispatcher, ) : CreateNewOrderUseCase { - override suspend fun execute(input: CreateNewOrderUseCase.Input): CreateNewOrderUseCase.Output { + override suspend fun invoke(input: CreateNewOrderUseCase.Input): CreateNewOrderUseCase.Output { return withContext(ioDispatcher) { val result = orderRepository.createOrUpdate(input.order) CreateNewOrderUseCase.Output(result) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/explore/ExploreViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/explore/ExploreViewModel.kt index a5d2db54..3ce0bb8b 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/explore/ExploreViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/explore/ExploreViewModel.kt @@ -67,7 +67,7 @@ class ExploreViewModel @Inject constructor( if (name.isNotBlank()) { viewModelScope.launch { val res = - searchProductUseCase.execute(SearchProductUseCase.Input(name = name.trim())) + searchProductUseCase(SearchProductUseCase.Input(name = name.trim())) res.result.collect { _productList.value = it } @@ -78,7 +78,7 @@ class ExploreViewModel @Inject constructor( private fun getCurrentCard(): Flow? { var res: Flow? = null viewModelScope.launch { - res = getCurrentCartUseCase.execute(GetCurrentCartUseCase.Input()).result + res = getCurrentCartUseCase(GetCurrentCartUseCase.Input()).result } return res } @@ -86,7 +86,7 @@ class ExploreViewModel @Inject constructor( private fun getCategoriesList(): Flow>? { var res: Flow>? = null viewModelScope.launch { - res = getCategoriesListUseCase.execute(GetCategoriesListUseCase.Input()).result + res = getCategoriesListUseCase(GetCategoriesListUseCase.Input()).result } return res } @@ -102,20 +102,20 @@ class ExploreViewModel @Inject constructor( quantity = 1, subtotal = product.price!! ) - addToCartUseCase.execute(AddToCartUseCase.Input(lineItem = lineItem)) + addToCartUseCase(AddToCartUseCase.Input(lineItem = lineItem)) } } else { val id = UUID.randomUUID().toString() val newOrder = Order(id, OrderStatus.IN_CART.value, "") viewModelScope.launch { - createNewOrderUseCase.execute(CreateNewOrderUseCase.Input(order = newOrder)) + createNewOrderUseCase(CreateNewOrderUseCase.Input(order = newOrder)) val lineItem = LineItem( productId = product.id, orderId = id, quantity = 1, subtotal = product.price!! ) - addToCartUseCase.execute(AddToCartUseCase.Input(lineItem = lineItem)) + addToCartUseCase(AddToCartUseCase.Input(lineItem = lineItem)) } } } From 6850a7b107d85ec7866f574002dcdf97c6cb6980 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:46:23 +0700 Subject: [PATCH 04/22] Use operator to simplify single method --- .../domain/usecases/impl/GetCategoriesListUseCaseImpl.kt | 2 +- .../domain/usecases/impl/GetCategoriesListUseCaseImplTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCategoriesListUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCategoriesListUseCaseImpl.kt index 63d5cbee..cc8c8b64 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCategoriesListUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCategoriesListUseCaseImpl.kt @@ -7,7 +7,7 @@ import javax.inject.Inject class GetCategoriesListUseCaseImpl @Inject constructor( private val categoryRepository: CategoryRepository ) : GetCategoriesListUseCase { - override suspend fun execute(input: GetCategoriesListUseCase.Input): GetCategoriesListUseCase.Output { + override suspend fun invoke(input: GetCategoriesListUseCase.Input): GetCategoriesListUseCase.Output { val result = categoryRepository.getFromLocal() return GetCategoriesListUseCase.Output(result) } diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCategoriesListUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCategoriesListUseCaseImplTest.kt index 7e844fdf..811e1fd8 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCategoriesListUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCategoriesListUseCaseImplTest.kt @@ -41,7 +41,7 @@ class GetCategoriesListUseCaseImplTest { emit(mockCategories) }) runBlocking { - val result = testee.execute(GetCategoriesListUseCase.Input()) + val result = testee(GetCategoriesListUseCase.Input()) result.result.collect { categories -> assertEquals(mockCategories[0], categories[0]) @@ -59,7 +59,7 @@ class GetCategoriesListUseCaseImplTest { emit(listOf()) }) runBlocking { - val result = testee.execute(GetCategoriesListUseCase.Input()) + val result = testee(GetCategoriesListUseCase.Input()) result.result.collect { assertEquals(it.isEmpty(), true) } From 73eaec1d79b04d3746383c0971a34b2fdc344a14 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:46:27 +0700 Subject: [PATCH 05/22] Use operator to simplify single method --- .../domain/usecases/impl/GetCurrentCartUseCaseImpl.kt | 2 +- .../domain/usecases/impl/GetCurrentCartUseCaseImplTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCurrentCartUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCurrentCartUseCaseImpl.kt index 82e47dfc..f6e0b188 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCurrentCartUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCurrentCartUseCaseImpl.kt @@ -9,7 +9,7 @@ class GetCurrentCartUseCaseImpl @Inject constructor( private val orderRepository: OrderRepository, ) : GetCurrentCartUseCase { - override suspend fun execute(input: GetCurrentCartUseCase.Input): GetCurrentCartUseCase.Output { + override suspend fun invoke(input: GetCurrentCartUseCase.Input): GetCurrentCartUseCase.Output { val res = orderRepository.getOneOrderByStatus(OrderStatus.IN_CART) return GetCurrentCartUseCase.Output(res) diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCurrentCartUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCurrentCartUseCaseImplTest.kt index 2eda357e..be0d52ad 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCurrentCartUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetCurrentCartUseCaseImplTest.kt @@ -44,7 +44,7 @@ class GetCurrentCartUseCaseImplTest { emit(mockOrder) }) runBlocking { - val result = testee.execute(GetCurrentCartUseCase.Input()) + val result = testee(GetCurrentCartUseCase.Input()) result.result.collect { order -> assertEquals(order?.id, "") @@ -62,7 +62,7 @@ class GetCurrentCartUseCaseImplTest { null }) runBlocking { - val result = testee.execute(GetCurrentCartUseCase.Input()) + val result = testee(GetCurrentCartUseCase.Input()) result.result.collect { assertNull(it) } From f455c2eb40e8044c0c8dce04777f663e2107bb98 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:46:34 +0700 Subject: [PATCH 06/22] Use operator to simplify single method --- .../domain/usecases/impl/GetOrderListUseCaseImpl.kt | 2 +- .../domain/usecases/impl/GetProfileUseCaseImpl.kt | 2 +- .../domain/usecases/impl/GetProfileUseCaseImplTest.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetOrderListUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetOrderListUseCaseImpl.kt index 39d3b361..90090ba0 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetOrderListUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetOrderListUseCaseImpl.kt @@ -11,7 +11,7 @@ class GetOrderListUseCaseImpl @Inject constructor( private val orderRepository: OrderRepository, @IoDispatcher private val ioDispatcher: CoroutineDispatcher, ) : GetOrderListUseCase { - override suspend fun execute(input: GetOrderListUseCase.Input): GetOrderListUseCase.Output { + override suspend fun invoke(input: GetOrderListUseCase.Input): GetOrderListUseCase.Output { return withContext(ioDispatcher) { val result = orderRepository.getOrders() GetOrderListUseCase.Output.Success(data = result) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProfileUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProfileUseCaseImpl.kt index d56648e7..1525c94d 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProfileUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProfileUseCaseImpl.kt @@ -8,7 +8,7 @@ class GetProfileUseCaseImpl @Inject constructor( private val userRepository: UserRepository, ) : GetProfileUseCase { - override suspend fun execute(input: GetProfileUseCase.Input): GetProfileUseCase.Output { + override suspend fun invoke(input: GetProfileUseCase.Input): GetProfileUseCase.Output { val user = userRepository.getCurrentUser() return GetProfileUseCase.Output(user) } diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProfileUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProfileUseCaseImplTest.kt index e9f8cb97..7fc3c0f5 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProfileUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProfileUseCaseImplTest.kt @@ -47,7 +47,7 @@ class GetProfileUseCaseImplTest { ) }) runBlocking { - val result = testee.execute(GetProfileUseCase.Input()) + val result = testee(GetProfileUseCase.Input()) result.result.collect { assertEquals("", it?.id) @@ -66,7 +66,7 @@ class GetProfileUseCaseImplTest { }) runBlocking { - val result = testee.execute(GetProfileUseCase.Input()) + val result = testee(GetProfileUseCase.Input()) result.result.collect { assertNull(it) } From c08a61937909b2d19921fac6dc081cc47ed858f9 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:46:42 +0700 Subject: [PATCH 07/22] Use operator to simplify single method --- .../notificationsettings/NotificationSettingsViewModel.kt | 4 ++-- .../presentation/onboarding/OnboardingViewModel.kt | 2 +- .../presentation/orderhistory/OrderListViewModel.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/notificationsettings/NotificationSettingsViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/notificationsettings/NotificationSettingsViewModel.kt index 74886508..cd760936 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/notificationsettings/NotificationSettingsViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/notificationsettings/NotificationSettingsViewModel.kt @@ -48,7 +48,7 @@ class NotificationSettingsViewModel @Inject constructor( private fun getCurrentUser() { viewModelScope.launch { - getProfileUseCase.execute(GetProfileUseCase.Input()).result.collect { + getProfileUseCase(GetProfileUseCase.Input()).result.collect { _user.value = it } } @@ -65,7 +65,7 @@ class NotificationSettingsViewModel @Inject constructor( fun updateNotificationSettings() { Timber.d("promo: $isPromotionNotiEnabled, ord: $isOrderCreatedNotiEnabled, db: $isDatabaseRefreshedNotiEnabled") viewModelScope.launch { - userSettingsUseCase.execute( + userSettingsUseCase( UserSettingsUseCase.Input( user.value?.id!!, isOrderCreatedNotiEnabled.value!!, diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/onboarding/OnboardingViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/onboarding/OnboardingViewModel.kt index 6695817e..66cc5d12 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/onboarding/OnboardingViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/onboarding/OnboardingViewModel.kt @@ -28,7 +28,7 @@ class OnboardingViewModel @Inject constructor( } else { try { viewModelScope.launch { - refreshAppDataUseCase.execute(Unit) + refreshAppDataUseCase(Unit) with(sharedPreferences.edit()) { putBoolean("PRODUCT_SYNC_SUCCESS", true) apply() diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/orderhistory/OrderListViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/orderhistory/OrderListViewModel.kt index c5f24dfc..005c382e 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/orderhistory/OrderListViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/orderhistory/OrderListViewModel.kt @@ -24,7 +24,7 @@ class OrderListViewModel @Inject constructor( private fun getOrderList() { viewModelScope.launch { - when (val result = getOrderListUseCase.execute(GetOrderListUseCase.Input())) { + when (val result = getOrderListUseCase(GetOrderListUseCase.Input())) { is GetOrderListUseCase.Output.Success -> { _orderList.emit(result.data) } From 8b516c648470ce09cb5795ed5a718535ccf4c8ca Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:46:54 +0700 Subject: [PATCH 08/22] Use operator to simplify single method --- .../domain/usecases/impl/RefreshAppDataUseCaseImpl.kt | 2 +- .../mealplanning/overview/OverviewViewModel.kt | 10 +++++----- .../presentation/productlist/ProductListViewModel.kt | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RefreshAppDataUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RefreshAppDataUseCaseImpl.kt index 435729d4..d5ce8456 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RefreshAppDataUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RefreshAppDataUseCaseImpl.kt @@ -15,7 +15,7 @@ class RefreshAppDataUseCaseImpl @Inject constructor( private val recipeRepository: RecipeRepository, @IoDispatcher private val ioDispatcher: CoroutineDispatcher, ) : RefreshAppDataUseCase { - override suspend fun execute(input: Unit) { + override suspend fun invoke(input: Unit) { withContext(ioDispatcher) { categoryRepository.refreshDatabase() productRepository.refreshDatabase() diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/mealplanning/overview/OverviewViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/mealplanning/overview/OverviewViewModel.kt index 8a36afec..844fcf73 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/mealplanning/overview/OverviewViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/mealplanning/overview/OverviewViewModel.kt @@ -76,7 +76,7 @@ class OverviewViewModel @Inject constructor( weekDayValue: WeekDayValue, mealType: MealType, ) { - val result = retrieveMealByTypeUseCase.execute( + val result = retrieveMealByTypeUseCase( RetrieveMealByTypeUseCase.Input( dayValue = weekDayValue, mealType = mealType @@ -126,7 +126,7 @@ class OverviewViewModel @Inject constructor( fun onRemoveMeal(id: String) { viewModelScope.launch { - removeMealFromPlanUseCase.execute( + removeMealFromPlanUseCase( RemoveMealFromPlanUseCase.Input( id = id ) @@ -149,7 +149,7 @@ class OverviewViewModel @Inject constructor( private fun onAddBreakfast(name: String, ingredients: List, mealImageUri: ByteArray) { viewModelScope.launch { - addMealToPlanUseCase.execute( + addMealToPlanUseCase( AddMealToPlanUseCase.Input( name = name, weekDay = _days.value[selectedDayIndex].name, @@ -167,7 +167,7 @@ class OverviewViewModel @Inject constructor( private fun onAddLunch(name: String, ingredients: List, mealImageUri: ByteArray) { viewModelScope.launch { - addMealToPlanUseCase.execute( + addMealToPlanUseCase( AddMealToPlanUseCase.Input( name = name, weekDay = _days.value[selectedDayIndex].name, @@ -185,7 +185,7 @@ class OverviewViewModel @Inject constructor( private fun onAddDinner(name: String, ingredients: List, mealImageUri: ByteArray) { viewModelScope.launch { - addMealToPlanUseCase.execute( + addMealToPlanUseCase( AddMealToPlanUseCase.Input( name = name, weekDay = _days.value[selectedDayIndex].name, diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/productlist/ProductListViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/productlist/ProductListViewModel.kt index 5f04f64d..1a57addc 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/productlist/ProductListViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/productlist/ProductListViewModel.kt @@ -63,7 +63,7 @@ class ProductListViewModel @Inject constructor( private fun getCurrentCart(): Flow? { var res: Flow? = null viewModelScope.launch { - res = getCurrentCartUseCase.execute(GetCurrentCartUseCase.Input()).result + res = getCurrentCartUseCase(GetCurrentCartUseCase.Input()).result } return res } @@ -80,7 +80,7 @@ class ProductListViewModel @Inject constructor( viewModelScope.launch { if (currentCart.value != null) { // Add to cart - addToCartUseCase.execute( + addToCartUseCase( AddToCartUseCase.Input( LineItem( productId = product.id, @@ -94,8 +94,8 @@ class ProductListViewModel @Inject constructor( // TODO: Move order creation to repository layer, at this point only pass domain object val id = UUID.randomUUID().toString() val newOrder = Order(id, OrderStatus.IN_CART.value, "") - createNewOrderUseCase.execute(CreateNewOrderUseCase.Input(newOrder)) - addToCartUseCase.execute( + createNewOrderUseCase(CreateNewOrderUseCase.Input(newOrder)) + addToCartUseCase( AddToCartUseCase.Input( LineItem( productId = product.id, From 9bc2d99ce24da10c3ec56ee57c8b6518eaac5e3d Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:47:00 +0700 Subject: [PATCH 09/22] Use operator to simplify single method --- .../java/com/hieuwu/groceriesstore/works/RefreshDatabaseWork.kt | 2 +- .../domain/usecases/impl/RefreshAppDataUseCaseImplTest.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/works/RefreshDatabaseWork.kt b/app/src/main/java/com/hieuwu/groceriesstore/works/RefreshDatabaseWork.kt index 08a97c4e..87942d26 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/works/RefreshDatabaseWork.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/works/RefreshDatabaseWork.kt @@ -15,7 +15,7 @@ class RefreshDatabaseWork(appContext: Context, params: WorkerParameters) : override suspend fun doWork(): Result { return try { Timber.d("Refreshing database") - refreshAppDataUseCase.execute(Unit) + refreshAppDataUseCase(Unit) Result.success() } catch (e: Exception) { Result.retry() diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/RefreshAppDataUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/RefreshAppDataUseCaseImplTest.kt index 436e7cad..c5b667ef 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/RefreshAppDataUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/RefreshAppDataUseCaseImplTest.kt @@ -40,7 +40,7 @@ class RefreshAppDataUseCaseImplTest { @Test fun whenExecute_thenCallRepositories() { runBlocking { - testee.execute(Unit) + testee(Unit) verify(mockedProductRepository).refreshDatabase() verify(mockedCategoryRepository).refreshDatabase() From dd9895eacca62b83bc38b94324b13c949865fec0 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:47:07 +0700 Subject: [PATCH 10/22] Use operator to simplify single method --- .../domain/usecases/impl/RemoveMealFromPlanUseCaseImpl.kt | 2 +- .../domain/usecases/impl/RetrieveMealByTypeUseCaseImpl.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RemoveMealFromPlanUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RemoveMealFromPlanUseCaseImpl.kt index fae7433f..934eb692 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RemoveMealFromPlanUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RemoveMealFromPlanUseCaseImpl.kt @@ -11,7 +11,7 @@ class RemoveMealFromPlanUseCaseImpl @Inject constructor( private val mealPlanRepository: MealPlanRepository, @IoDispatcher private val ioDispatcher: CoroutineDispatcher, ) : RemoveMealFromPlanUseCase { - override suspend fun execute(input: RemoveMealFromPlanUseCase.Input): RemoveMealFromPlanUseCase.Output { + override suspend fun invoke(input: RemoveMealFromPlanUseCase.Input): RemoveMealFromPlanUseCase.Output { return withContext(ioDispatcher) { try { mealPlanRepository.removeMealFromPlan(input.id) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RetrieveMealByTypeUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RetrieveMealByTypeUseCaseImpl.kt index d234d98b..c7711351 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RetrieveMealByTypeUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/RetrieveMealByTypeUseCaseImpl.kt @@ -16,7 +16,7 @@ class RetrieveMealByTypeUseCaseImpl @Inject constructor( private val mealPlanRepository: MealPlanRepository, @IoDispatcher private val ioDispatcher: CoroutineDispatcher, ) : RetrieveMealByTypeUseCase { - override suspend fun execute(input: RetrieveMealByTypeUseCase.Input): RetrieveMealByTypeUseCase.Output { + override suspend fun invoke(input: RetrieveMealByTypeUseCase.Input): RetrieveMealByTypeUseCase.Output { return withContext(ioDispatcher) { try { val result = mealPlanRepository.retrieveMealByType( From 300139aa85a37a5f49250fee41769aa237d05dc6 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:47:11 +0700 Subject: [PATCH 11/22] Use operator to simplify single method --- .../domain/usecases/impl/SearchProductUseCaseImpl.kt | 2 +- .../domain/usecases/impl/SearchProductUseCaseImplTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SearchProductUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SearchProductUseCaseImpl.kt index ebe8687c..5dd03c01 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SearchProductUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SearchProductUseCaseImpl.kt @@ -12,7 +12,7 @@ class SearchProductUseCaseImpl @Inject constructor( @IoDispatcher private val ioDispatcher: CoroutineDispatcher, ) : SearchProductUseCase { - override suspend fun execute(input: SearchProductUseCase.Input): SearchProductUseCase.Output { + override suspend fun invoke(input: SearchProductUseCase.Input): SearchProductUseCase.Output { return withContext(ioDispatcher) { val result = productRepository.searchProductsListByName(input.name) SearchProductUseCase.Output(result) diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SearchProductUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SearchProductUseCaseImplTest.kt index 1f0a2fe8..117acd1b 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SearchProductUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SearchProductUseCaseImplTest.kt @@ -40,7 +40,7 @@ class SearchProductUseCaseImplTest { }) runBlocking { - val result = testee.execute(input) + val result = testee(input) result.result.collect { TestCase.assertTrue(it.isNotEmpty()) TestCase.assertEquals(mockProducts[0], it[0]) @@ -59,7 +59,7 @@ class SearchProductUseCaseImplTest { }) runBlocking { - val result = testee.execute(input) + val result = testee(input) result.result.collect { TestCase.assertTrue(it.isEmpty()) } From 2d5e37adb66528a9b177b3ca5a037c2071bfea55 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:47:16 +0700 Subject: [PATCH 12/22] Use operator to simplify single method --- .../domain/usecases/impl/SignInUseCaseImpl.kt | 2 +- .../groceriesstore/presentation/shop/ShopViewModel.kt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignInUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignInUseCaseImpl.kt index 0a18de6b..a5803d13 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignInUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignInUseCaseImpl.kt @@ -14,7 +14,7 @@ class SignInUseCaseImpl @Inject constructor( @IoDispatcher private val ioDispatcher: CoroutineDispatcher, ) : SignInUseCase { - override suspend fun execute(input: SignInUseCase.Input): SignInUseCase.Output { + override suspend fun invoke(input: SignInUseCase.Input): SignInUseCase.Output { return withContext(ioDispatcher) { try { val res = userRepository.authenticate(input.email, input.password) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/shop/ShopViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/shop/ShopViewModel.kt index 5507dedf..d170cd10 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/shop/ShopViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/shop/ShopViewModel.kt @@ -70,7 +70,7 @@ class ShopViewModel @Inject constructor( private fun getCurrentCart(): Flow? { var res: Flow? = null viewModelScope.launch { - res = getCurrentCartUseCase.execute(GetCurrentCartUseCase.Input()).result + res = getCurrentCartUseCase(GetCurrentCartUseCase.Input()).result } return res } @@ -80,7 +80,7 @@ class ShopViewModel @Inject constructor( // Add to cart val cartId = currentCart.value!!.id viewModelScope.launch { - addToCartUseCase.execute( + addToCartUseCase( AddToCartUseCase.Input( LineItem( productId = product.id, @@ -94,7 +94,7 @@ class ShopViewModel @Inject constructor( } else { val id = UUID.randomUUID().toString() viewModelScope.launch { - createNewOrderUseCase.execute( + createNewOrderUseCase( CreateNewOrderUseCase.Input( Order( id = id, @@ -103,7 +103,7 @@ class ShopViewModel @Inject constructor( ) ) ) - addToCartUseCase.execute( + addToCartUseCase( AddToCartUseCase.Input( LineItem( productId = product.id, From 57c2f1538138c0c079c2a0c840ff05fed066b456 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:47:23 +0700 Subject: [PATCH 13/22] Use operator to simplify single method --- .../presentation/authentication/signin/SignInViewModel.kt | 2 +- .../domain/usecases/impl/SignInUseCaseImplTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/authentication/signin/SignInViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/authentication/signin/SignInViewModel.kt index 5e7751e3..418ff7fd 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/authentication/signin/SignInViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/authentication/signin/SignInViewModel.kt @@ -42,7 +42,7 @@ class SignInViewModel @Inject constructor( fun signIn() { viewModelScope.launch { - when (signInUseCase.execute( + when (signInUseCase( SignInUseCase.Input( email = _email.value, password = _password.value diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignInUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignInUseCaseImplTest.kt index b3b4327c..8b59fcc6 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignInUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignInUseCaseImplTest.kt @@ -41,7 +41,7 @@ class SignInUseCaseImplTest { whenever(mockedUserRepository.authenticate(input.email, input.password)) .thenReturn(authenticationResult) - val output = testee.execute(input) + val output = testee(input) assertEquals(authenticationResult, output.result) } } @@ -57,7 +57,7 @@ class SignInUseCaseImplTest { whenever(mockedUserRepository.authenticate(input.email, input.password)) .thenThrow(RuntimeException()) - val output = testee.execute(input) + val output = testee(input) assertEquals(SignInUseCase.Output.AccountNotExistedError, output) } } From cd09ba41a9ea5404cd3c8accd4857970f304de95 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:47:25 +0700 Subject: [PATCH 14/22] Use operator to simplify single method --- .../groceriesstore/domain/usecases/impl/SignOutUseCaseImpl.kt | 2 +- .../domain/usecases/impl/SignOutUseCaseImplTest.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignOutUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignOutUseCaseImpl.kt index 507662f0..372e21ab 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignOutUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignOutUseCaseImpl.kt @@ -12,7 +12,7 @@ class SignOutUseCaseImpl @Inject constructor( @IoDispatcher private val ioDispatcher: CoroutineDispatcher ) : SignOutUseCase { - override suspend fun execute(input: SignOutUseCase.Input): SignOutUseCase.Output { + override suspend fun invoke(input: SignOutUseCase.Input): SignOutUseCase.Output { return withContext(ioDispatcher) { userRepository.clearUser() SignOutUseCase.Output() diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignOutUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignOutUseCaseImplTest.kt index d2beeeda..0f2df783 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignOutUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SignOutUseCaseImplTest.kt @@ -31,7 +31,7 @@ class SignOutUseCaseImplTest { val input = SignOutUseCase.Input() runBlocking { - testee.execute(input) + testee(input) verify(mockedUserRepository).clearUser() } From ab537d18c492e31fffb525809a70e9ae04bde747 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:47:29 +0700 Subject: [PATCH 15/22] Use operator to simplify single method --- .../domain/usecases/impl/SubmitOrderUseCaseImpl.kt | 2 +- .../domain/usecases/impl/SubmitOrderUseCaseImplTest.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SubmitOrderUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SubmitOrderUseCaseImpl.kt index 42a1a9c8..d1b8433b 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SubmitOrderUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/SubmitOrderUseCaseImpl.kt @@ -11,7 +11,7 @@ class SubmitOrderUseCaseImpl @Inject constructor( private val orderRepository: OrderRepository, @IoDispatcher private val ioDispatcher: CoroutineDispatcher, ) : SubmitOrderUseCase { - override suspend fun execute(input: SubmitOrderUseCase.Input): SubmitOrderUseCase.Output { + override suspend fun invoke(input: SubmitOrderUseCase.Input): SubmitOrderUseCase.Output { return withContext(ioDispatcher) { val result = orderRepository.sendOrderToServer(input.order) SubmitOrderUseCase.Output(result) diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SubmitOrderUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SubmitOrderUseCaseImplTest.kt index c60f93ad..636ae50c 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SubmitOrderUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SubmitOrderUseCaseImplTest.kt @@ -33,7 +33,7 @@ class SubmitOrderUseCaseImplTest { fun whenExecute_thenSubmitOrderSuccessfully() { runBlocking { whenever(mockedOrderRepository.sendOrderToServer(any())).thenReturn(true) - testee.execute( + testee( SubmitOrderUseCase.Input( order = OrderModel( lineItemList = mutableListOf() From 759a7cfaf5933807be1ca0e014e94491396a5c50 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:47:33 +0700 Subject: [PATCH 16/22] Use operator to simplify single method --- .../domain/usecases/impl/UpdateProfileUseCaseImpl.kt | 2 +- .../domain/usecases/impl/UpdateProfileUseCaseImplTest.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/UpdateProfileUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/UpdateProfileUseCaseImpl.kt index 8f987eb3..9e21fc19 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/UpdateProfileUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/UpdateProfileUseCaseImpl.kt @@ -10,7 +10,7 @@ class UpdateProfileUseCaseImpl @Inject constructor( private val userRepository: UserRepository, ) : UpdateProfileUseCase { - override suspend fun execute(input: UpdateProfileUseCase.Input): UpdateProfileUseCase.Output { + override suspend fun invoke(input: UpdateProfileUseCase.Input): UpdateProfileUseCase.Output { userRepository.updateUserProfile( input.userId, input.name, input.email, input.phone, input.address ) diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UpdateProfileUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UpdateProfileUseCaseImplTest.kt index 46a45af8..f183b477 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UpdateProfileUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UpdateProfileUseCaseImplTest.kt @@ -35,7 +35,7 @@ class UpdateProfileUseCaseImplTest { ) runBlocking { - testee.execute(input) + testee(input) verify(mockedUserRepository) .updateUserProfile( From c5fde02aec05fee3d24c812b25ee77bff8e764e6 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:47:38 +0700 Subject: [PATCH 17/22] Use operator to simplify single method --- .../java/com/hieuwu/groceriesstore/domain/usecases/UseCase.kt | 2 +- .../presentation/updateprofile/UpdateProfileViewModel.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/UseCase.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/UseCase.kt index fb2ec2ae..2daedfaf 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/UseCase.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/UseCase.kt @@ -1,7 +1,7 @@ package com.hieuwu.groceriesstore.domain.usecases interface SuspendUseCase { - suspend fun execute(input: Input): Output + suspend operator fun invoke(input: Input): Output } interface UseCase { diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/updateprofile/UpdateProfileViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/updateprofile/UpdateProfileViewModel.kt index b69497a9..5cae7435 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/updateprofile/UpdateProfileViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/updateprofile/UpdateProfileViewModel.kt @@ -39,7 +39,7 @@ class UpdateProfileViewModel @Inject constructor( private fun getCurrentUser() { viewModelScope.launch { - getProfileUseCase.execute(GetProfileUseCase.Input()).result.collect { + getProfileUseCase(GetProfileUseCase.Input()).result.collect { setUserProperties(it) _user.value = it } @@ -57,7 +57,7 @@ class UpdateProfileViewModel @Inject constructor( val id = _user.value!!.id try { viewModelScope.launch { - updateProfileUseCase.execute( + updateProfileUseCase( UpdateProfileUseCase.Input( userId = id, name = name!!, From c3679c031a76171b8eecb915564aacc65ceeb17e Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:47:41 +0700 Subject: [PATCH 18/22] Use operator to simplify single method --- .../domain/usecases/impl/UserSettingsUseCaseImpl.kt | 2 +- .../domain/usecases/impl/UserSettingsUseCaseImplTest.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImpl.kt index df787383..0468c3f5 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImpl.kt @@ -13,7 +13,7 @@ class UserSettingsUseCaseImpl @Inject constructor( ) : UserSettingsUseCase { - override suspend fun execute(input: UserSettingsUseCase.Input): UserSettingsUseCase.Output { + override suspend fun invoke(input: UserSettingsUseCase.Input): UserSettingsUseCase.Output { withContext(ioDispatcher) { userRepository.updateUserSettings( input.id, diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImplTest.kt index 84f7083a..fe567a16 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImplTest.kt @@ -39,7 +39,7 @@ class UserSettingsUseCaseImplTest { ) runBlocking { - testee.execute(input) + testee(input) verify(mockedUserRepository) .updateUserSettings( From aee6c5e37ccdf0e8d0b55ea185a0d0a54612c107 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:48:52 +0700 Subject: [PATCH 19/22] Use operator to simplify single method --- .../java/com/hieuwu/groceriesstore/domain/usecases/UseCase.kt | 2 +- .../presentation/productlist/ProductListViewModel.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/UseCase.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/UseCase.kt index 2daedfaf..5a54e976 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/UseCase.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/UseCase.kt @@ -5,5 +5,5 @@ interface SuspendUseCase { } interface UseCase { - fun execute(input: Input): Output + operator fun invoke(input: Input): Output } diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/productlist/ProductListViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/productlist/ProductListViewModel.kt index 1a57addc..42b08ee1 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/productlist/ProductListViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/productlist/ProductListViewModel.kt @@ -69,11 +69,11 @@ class ProductListViewModel @Inject constructor( } private fun getProductLists(): Flow> { - return getProductsListUseCase.execute(GetProductsListUseCase.Input()).result + return getProductsListUseCase(GetProductsListUseCase.Input()).result } private fun getProductLists(categoryId: String): Flow> { - return getProductsByCategoryUseCase.execute(GetProductsByCategoryUseCase.Input(categoryId)).result + return getProductsByCategoryUseCase(GetProductsByCategoryUseCase.Input(categoryId)).result } fun addToCart(product: ProductModel) { From c298468e945ecb27b6c533a6d9f35ce8f965699d Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:49:02 +0700 Subject: [PATCH 20/22] Use operator to simplify single method --- .../domain/usecases/impl/GetProductsByCategoryUseCaseImpl.kt | 2 +- .../usecases/impl/GetProductsByCategoryUseCaseImplTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsByCategoryUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsByCategoryUseCaseImpl.kt index 5d9c214a..9a32d5e7 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsByCategoryUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsByCategoryUseCaseImpl.kt @@ -8,7 +8,7 @@ import javax.inject.Inject class GetProductsByCategoryUseCaseImpl @Inject constructor(private val productRepository: ProductRepository) : GetProductsByCategoryUseCase { - override fun execute(input: GetProductsByCategoryUseCase.Input): GetProductsByCategoryUseCase.Output { + override fun invoke(input: GetProductsByCategoryUseCase.Input): GetProductsByCategoryUseCase.Output { val result = productRepository.getAllProductsByCategory(input.categoryId) return GetProductsByCategoryUseCase.Output(result) } diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsByCategoryUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsByCategoryUseCaseImplTest.kt index dad923db..44929489 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsByCategoryUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsByCategoryUseCaseImplTest.kt @@ -36,7 +36,7 @@ class GetProductsByCategoryUseCaseImplTest { }) runBlocking { - val result = testee.execute(input) + val result = testee(input) result.result.collect { TestCase.assertTrue(it.isNotEmpty()) TestCase.assertEquals(mockedProducts[0], it[0]) @@ -55,7 +55,7 @@ class GetProductsByCategoryUseCaseImplTest { }) runBlocking { - val result = testee.execute(input) + val result = testee(input) result.result.collect { TestCase.assertTrue(it.isEmpty()) } From 43d16b07708c6acad8728c8c9e0b5d5972faab04 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:49:07 +0700 Subject: [PATCH 21/22] Use operator to simplify single method --- .../domain/usecases/impl/GetProductsListUseCaseImpl.kt | 2 +- .../domain/usecases/impl/GetProductsListUseCaseImplTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsListUseCaseImpl.kt b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsListUseCaseImpl.kt index 381e69ba..557daf00 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsListUseCaseImpl.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsListUseCaseImpl.kt @@ -8,7 +8,7 @@ import javax.inject.Inject class GetProductsListUseCaseImpl @Inject constructor(private val productRepository: ProductRepository) : GetProductsListUseCase { - override fun execute(input: GetProductsListUseCase.Input): GetProductsListUseCase.Output { + override fun invoke(input: GetProductsListUseCase.Input): GetProductsListUseCase.Output { val result = productRepository.products return GetProductsListUseCase.Output(result) } diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsListUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsListUseCaseImplTest.kt index 307f70d0..e4816763 100644 --- a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsListUseCaseImplTest.kt +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/GetProductsListUseCaseImplTest.kt @@ -40,7 +40,7 @@ class GetProductsListUseCaseImplTest { emit(mockedProducts) }) runBlocking { - val result = testee.execute(GetProductsListUseCase.Input()) + val result = testee(GetProductsListUseCase.Input()) result.result.collect { products -> assertEquals(mockedProducts[0], products[0]) @@ -58,7 +58,7 @@ class GetProductsListUseCaseImplTest { }) runBlocking { - val result = testee.execute(GetProductsListUseCase.Input()) + val result = testee(GetProductsListUseCase.Input()) result.result.collect { assertEquals(it.isEmpty(), true) } From fd9dd14b82c1499c5aa0b464d1d5b4c050705663 Mon Sep 17 00:00:00 2001 From: Hieu Vu Date: Mon, 29 Jul 2024 22:49:10 +0700 Subject: [PATCH 22/22] Use operator to simplify single method --- .../hieuwu/groceriesstore/presentation/shop/ShopViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/hieuwu/groceriesstore/presentation/shop/ShopViewModel.kt b/app/src/main/java/com/hieuwu/groceriesstore/presentation/shop/ShopViewModel.kt index d170cd10..540c1b26 100644 --- a/app/src/main/java/com/hieuwu/groceriesstore/presentation/shop/ShopViewModel.kt +++ b/app/src/main/java/com/hieuwu/groceriesstore/presentation/shop/ShopViewModel.kt @@ -62,7 +62,7 @@ class ShopViewModel @Inject constructor( private fun getProductLists(): Flow>? { var res: Flow>? = null viewModelScope.launch { - res = getProductsListUseCase.execute(GetProductsListUseCase.Input()).result + res = getProductsListUseCase(GetProductsListUseCase.Input()).result } return res }