Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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

This file was deleted.

3 changes: 2 additions & 1 deletion client_end_user/shared/src/commonMain/kotlin/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fun appModule() = module {
localStorageModule,
gatewayModule,
useCaseModule,
screenModelsModule
screenModelsModule,
pagingDataSourceModule
)
}
11 changes: 1 addition & 10 deletions client_end_user/shared/src/commonMain/kotlin/di/GatewayModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import data.gateway.local.LocationGateway
import data.gateway.remote.RestaurantGateway
import data.gateway.remote.TransactionsGateway
import data.gateway.remote.UserGateway
import data.gateway.remote.pagesource.FoodOrderPagingSource
import data.gateway.remote.pagesource.MealsPagingSource
import data.gateway.remote.pagesource.NotificationPagingSource
import data.gateway.remote.pagesource.TaxiOrderPagingSource
import domain.gateway.IChatGateway
import domain.gateway.IRestaurantGateway
import domain.gateway.ITransactionsGateway
Expand All @@ -21,7 +17,6 @@ import domain.gateway.local.ILocationGateway
import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import data.gateway.remote.pagesource.RestaurantsPagingSource

val gatewayModule = module {
singleOf(::FakeChatGateway) { bind<IChatGateway>() } // fake
Expand All @@ -30,11 +25,7 @@ val gatewayModule = module {
singleOf(::UserGateway) { bind<IUserGateway>() }
singleOf(::LocalConfigurationGateway) { bind<ILocalConfigurationGateway>() }
singleOf(::LocalRestaurantGateway) { bind<ILocalRestaurantGateway>() }
singleOf(::FoodOrderPagingSource)
singleOf(::TaxiOrderPagingSource)
singleOf(::LocalConfigurationGateway) { bind<ILocalConfigurationGateway>() }
singleOf(::LocationGateway) { bind<ILocationGateway>() }
singleOf(::MealsPagingSource)
singleOf(::RestaurantsPagingSource)
singleOf(::NotificationPagingSource)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package di

import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import presentation.util.IPagingSource
import presentation.util.pagesource.FoodOrderPagingSource
import presentation.util.pagesource.MealsPagingSource
import presentation.util.pagesource.NotificationPagingSource
import presentation.util.pagesource.PagingSource
import presentation.util.pagesource.RestaurantsPagingSource
import presentation.util.pagesource.TaxiOrderPagingSource

val pagingDataSourceModule = module {
singleOf(::MealsPagingSource)
singleOf(::FoodOrderPagingSource)
singleOf(::TaxiOrderPagingSource)
singleOf(::RestaurantsPagingSource)
singleOf(::NotificationPagingSource)
singleOf(::PagingSource) { bind<IPagingSource>() }
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
package domain.usecase

import app.cash.paging.Pager
import app.cash.paging.PagingConfig
import app.cash.paging.PagingData
import data.gateway.remote.pagesource.MealsPagingSource
import data.gateway.remote.pagesource.RestaurantsPagingSource
import domain.entity.Cuisine
import domain.entity.Meal
import domain.entity.PaginationItems
import domain.entity.Restaurant
import domain.gateway.IRestaurantGateway
import domain.gateway.local.ILocalConfigurationGateway
import kotlinx.coroutines.flow.Flow

interface IExploreRestaurantUseCase {
suspend fun getRestaurants(): Flow<PagingData<Restaurant>>
suspend fun getRestaurants(page:Int,limit:Int): PaginationItems<Restaurant>
suspend fun getRestaurantDetails(restaurantId: String): Restaurant
suspend fun getMealById(mealId: String): Meal
suspend fun getCuisines(): List<Cuisine>
suspend fun getPreferredCuisines(): List<Cuisine>
suspend fun getMealsInCuisine(cuisineId: String): Flow<PagingData<Meal>>
suspend fun getMealsInCuisine(cuisineId: String,page:Int,limit:Int): PaginationItems<Meal>
suspend fun getCuisinesWithMealsInRestaurant(restaurantId: String): List<Cuisine>
}

class ExploreRestaurantUseCase(
private val restaurantGateway: IRestaurantGateway,
private val mealDataSource: MealsPagingSource,
private val restaurants: RestaurantsPagingSource,
private val localGateway: ILocalConfigurationGateway
) : IExploreRestaurantUseCase {

Expand All @@ -48,18 +41,12 @@ class ExploreRestaurantUseCase(
return cuisines.filter { preferredFood.contains(it.id) }
}

override suspend fun getRestaurants(): Flow<PagingData<Restaurant>> {
return Pager(
config = PagingConfig(pageSize = 10),
pagingSourceFactory = { restaurants },
).flow
override suspend fun getRestaurants(page:Int,limit:Int): PaginationItems<Restaurant> {
return restaurantGateway.getRestaurants(page = page, limit = limit)
}

override suspend fun getMealsInCuisine(cuisineId: String): Flow<PagingData<Meal>> {
mealDataSource.initCuisine(cuisineId)
return Pager(config = PagingConfig(pageSize = 5),
pagingSourceFactory = { mealDataSource }
).flow
override suspend fun getMealsInCuisine(cuisineId: String,page:Int,limit:Int): PaginationItems<Meal> {
return restaurantGateway.getMealsInCuisine(cuisineId,page= page,limit= limit)
}

override suspend fun getCuisinesWithMealsInRestaurant(restaurantId: String): List<Cuisine> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
package domain.usecase

import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import data.gateway.remote.pagesource.FoodOrderPagingSource
import data.gateway.remote.pagesource.NotificationPagingSource
import data.gateway.remote.pagesource.TaxiOrderPagingSource
import domain.entity.FoodOrder
import domain.entity.NotificationHistory
import domain.entity.PaginationItems
import domain.entity.Trip
import domain.gateway.ITransactionsGateway
import domain.gateway.IUserGateway
import kotlinx.coroutines.flow.Flow

interface IGetTransactionHistoryUseCase {
suspend fun getOrdersHistory(): Flow<PagingData<FoodOrder>>
suspend fun getTripsHistory(): Flow<PagingData<Trip>>
suspend fun getNotificationHistory(): Flow<PagingData<NotificationHistory>>
suspend fun getOrdersHistory(page: Int, limit: Int): PaginationItems<FoodOrder>
suspend fun getTripsHistory(page: Int, limit: Int): PaginationItems<Trip>
suspend fun getNotificationHistory(page: Int, limit: Int): PaginationItems<NotificationHistory>
suspend fun getNotificationHistoryInLast24Hours(): List<NotificationHistory>
}

class GetTransactionHistoryUseCase(
private val taxiOrder: TaxiOrderPagingSource,
private val foodOrderDataSource: FoodOrderPagingSource,
private val userGateway: IUserGateway,
private val notificationPagingSource: NotificationPagingSource,
) : IGetTransactionHistoryUseCase {
private val transactionsGateway: ITransactionsGateway,
) : IGetTransactionHistoryUseCase {

override suspend fun getOrdersHistory(): Flow<PagingData<FoodOrder>> {
return Pager(config = PagingConfig(pageSize = 10, enablePlaceholders = true),
pagingSourceFactory = { foodOrderDataSource }
).flow
override suspend fun getOrdersHistory(page: Int, limit: Int): PaginationItems<FoodOrder> {
return transactionsGateway.getOrderHistoryGateway(page, limit)
}

override suspend fun getTripsHistory(): Flow<PagingData<Trip>> {
return Pager(config = PagingConfig(pageSize = 10, enablePlaceholders = true),
pagingSourceFactory = { taxiOrder }
).flow
override suspend fun getTripsHistory(page: Int, limit: Int): PaginationItems<Trip> {
return transactionsGateway.getTripHistory(page, limit)
}

override suspend fun getNotificationHistory(): Flow<PagingData<NotificationHistory>> {
return Pager(config = PagingConfig(pageSize = 10, enablePlaceholders = true),
pagingSourceFactory = { notificationPagingSource }
).flow
override suspend fun getNotificationHistory(page: Int, limit: Int): PaginationItems<NotificationHistory> {
return userGateway.getNotificationHistory(page, limit)
}

override suspend fun getNotificationHistoryInLast24Hours(): List<NotificationHistory> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package presentation.meals

import app.cash.paging.PagingData
import cafe.adriel.voyager.core.model.coroutineScope
import presentation.util.IPagingSource
import domain.entity.Meal
import domain.usecase.IExploreRestaurantUseCase
import domain.usecase.IManageAuthenticationUseCase
Expand All @@ -21,6 +22,7 @@ class MealsScreenModel(
private val manageRestaurant: IExploreRestaurantUseCase,
private val manageAuthentication: IManageAuthenticationUseCase,
private val manageCart: IManageCartUseCase,
private val paginationSource: IPagingSource
) : BaseScreenModel<MealsUiState, MealsUiEffect>(MealsUiState()), MealsInteractionListener,
MealInteractionListener {

Expand All @@ -34,7 +36,7 @@ class MealsScreenModel(
private fun getData() {
updateState { it.copy(isLoading = true, cuisineName = cuisineName) }
tryToExecute(
{ manageRestaurant.getMealsInCuisine(cuisineId) },
{ paginationSource.getMealsInCuisine(cuisineId) },
::onGetMealsSuccess,
::onError
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import presentation.base.BaseScreenModel
import presentation.base.ErrorState
import presentation.util.IPagingSource

class NotificationScreenModel(
private val transaction: IGetTransactionHistoryUseCase,
private val transactionDatasource: IPagingSource,
private val manageAuthentication: IManageAuthenticationUseCase,
) : BaseScreenModel<NotificationsUiState, NotificationUiEffect>(NotificationsUiState()),
NotificationInteractionListener {
Expand Down Expand Up @@ -58,7 +60,7 @@ class NotificationScreenModel(
).join()

tryToExecute(
function = transaction::getNotificationHistory,
function = transactionDatasource::getNotificationHistory,
onSuccess = ::onGetNotificationHistorySuccess,
onError = ::onGetNotificationHistoryError
).join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ package presentation.orderHistory
import androidx.paging.PagingData
import cafe.adriel.voyager.core.model.coroutineScope
import domain.entity.FoodOrder
import domain.entity.Meal
import domain.entity.Trip
import domain.usecase.GetTransactionHistoryUseCase
import domain.usecase.IManageAuthenticationUseCase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import presentation.base.BaseScreenModel
import presentation.base.ErrorState
import presentation.resturantDetails.toUIState
import presentation.util.IPagingSource

class OrderHistoryScreenModel(
private val orderHistoryUseCase: GetTransactionHistoryUseCase,
private val orderHistory: IPagingSource,
private val manageAuthentication: IManageAuthenticationUseCase,
) : BaseScreenModel<OrderScreenUiState, OrderHistoryScreenUiEffect>(OrderScreenUiState()),
OrderHistoryScreenInteractionListener {
Expand Down Expand Up @@ -55,15 +53,15 @@ class OrderHistoryScreenModel(

private fun getOrdersHistory() {
tryToExecute(
{ orderHistoryUseCase.getOrdersHistory() },
{ orderHistory.getOrdersHistory() },
::onGetOrdersHistorySuccess,
::onError
)
}

private fun getTripsHistory() {
tryToExecute(
{ orderHistoryUseCase.getTripsHistory() },
{ orderHistory.getTripsHistory() },
::onGetTripsHistorySuccess,
::onError
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package presentation.restaurants
import androidx.paging.PagingData
import cafe.adriel.voyager.core.model.coroutineScope
import domain.entity.Restaurant
import domain.usecase.IExploreRestaurantUseCase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import presentation.base.BaseScreenModel
import presentation.base.ErrorState
import presentation.util.IPagingSource


class RestaurantsScreenModel(
private val offerId: String? = null,
private val manageRestaurant: IExploreRestaurantUseCase,
private val manageRestaurant: IPagingSource,
) : BaseScreenModel<RestaurantsUIState, RestaurantsUIEffect>(RestaurantsUIState()),
RestaurantsListener {
override val viewModelScope: CoroutineScope = coroutineScope
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package presentation.util

import app.cash.paging.PagingData
import domain.entity.FoodOrder
import domain.entity.Meal
import domain.entity.NotificationHistory
import domain.entity.Restaurant
import domain.entity.Trip
import kotlinx.coroutines.flow.Flow

interface IPagingSource {

fun getMealsInCuisine(cuisineId: String): Flow<PagingData<Meal>>
suspend fun getRestaurants(): Flow<PagingData<Restaurant>>
suspend fun getNotificationHistory(): Flow<PagingData<NotificationHistory>>
suspend fun getOrdersHistory(): Flow<PagingData<FoodOrder>>
suspend fun getTripsHistory(): Flow<PagingData<Trip>>

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package data.gateway.remote.pagesource
package presentation.util.pagesource


import app.cash.paging.PagingSource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package data.gateway.remote.pagesource
package presentation.util.pagesource

import domain.entity.FoodOrder
import domain.entity.PaginationItems
import domain.gateway.ITransactionsGateway
import domain.usecase.IGetTransactionHistoryUseCase
import org.koin.core.component.KoinComponent
import presentation.util.pagesource.BasePagingSource

class FoodOrderPagingSource(
private val transactionsGateway: ITransactionsGateway,
private val transactionHistory: IGetTransactionHistoryUseCase
) : BasePagingSource<FoodOrder>(), KoinComponent {

override suspend fun fetchData(page: Int, limit: Int): PaginationItems<FoodOrder> {
return transactionsGateway.getOrderHistoryGateway(page, limit)
return transactionHistory.getOrdersHistory(page, limit)
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package data.gateway.remote.pagesource
package presentation.util.pagesource

import domain.entity.Meal
import domain.entity.PaginationItems
import domain.gateway.IRestaurantGateway
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import org.koin.core.parameter.parametersOf
import domain.usecase.IExploreRestaurantUseCase
import presentation.util.pagesource.BasePagingSource
import kotlin.properties.Delegates

class MealsPagingSource(
private val remoteGateway: IRestaurantGateway,
private val exploreRestaurant: IExploreRestaurantUseCase
) : BasePagingSource<Meal>() {

private var cuisineId by Delegates.notNull<String>()

fun initCuisine(id: String) {
cuisineId = id
}

override suspend fun fetchData(page: Int, limit: Int): PaginationItems<Meal> {
return remoteGateway.getMealsInCuisine(cuisineId, page, limit)
return exploreRestaurant.getMealsInCuisine(cuisineId, page, limit)
}

}
Loading