diff --git a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/RestaurantsPagingSource.kt b/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/RestaurantsPagingSource.kt deleted file mode 100644 index c91a9d12e..000000000 --- a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/RestaurantsPagingSource.kt +++ /dev/null @@ -1,15 +0,0 @@ -package data.gateway.remote.pagesource - -import domain.entity.PaginationItems -import domain.entity.Restaurant -import domain.gateway.IRestaurantGateway - -class RestaurantsPagingSource( - private val remoteGateway: IRestaurantGateway, -) : BasePagingSource() { - - override suspend fun fetchData(page: Int, limit: Int ): PaginationItems { - return remoteGateway.getRestaurants(page, 10) - } - -} diff --git a/client_end_user/shared/src/commonMain/kotlin/di/AppModule.kt b/client_end_user/shared/src/commonMain/kotlin/di/AppModule.kt index 3869dcd79..0433135cf 100644 --- a/client_end_user/shared/src/commonMain/kotlin/di/AppModule.kt +++ b/client_end_user/shared/src/commonMain/kotlin/di/AppModule.kt @@ -8,6 +8,7 @@ fun appModule() = module { localStorageModule, gatewayModule, useCaseModule, - screenModelsModule + screenModelsModule, + pagingDataSourceModule ) } diff --git a/client_end_user/shared/src/commonMain/kotlin/di/GatewayModule.kt b/client_end_user/shared/src/commonMain/kotlin/di/GatewayModule.kt index 9195f8589..be00cb2c6 100644 --- a/client_end_user/shared/src/commonMain/kotlin/di/GatewayModule.kt +++ b/client_end_user/shared/src/commonMain/kotlin/di/GatewayModule.kt @@ -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 @@ -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() } // fake @@ -30,11 +25,7 @@ val gatewayModule = module { singleOf(::UserGateway) { bind() } singleOf(::LocalConfigurationGateway) { bind() } singleOf(::LocalRestaurantGateway) { bind() } - singleOf(::FoodOrderPagingSource) - singleOf(::TaxiOrderPagingSource) singleOf(::LocalConfigurationGateway) { bind() } singleOf(::LocationGateway) { bind() } - singleOf(::MealsPagingSource) - singleOf(::RestaurantsPagingSource) - singleOf(::NotificationPagingSource) + } diff --git a/client_end_user/shared/src/commonMain/kotlin/di/PagingDataSourceModule.kt b/client_end_user/shared/src/commonMain/kotlin/di/PagingDataSourceModule.kt new file mode 100644 index 000000000..e5719db56 --- /dev/null +++ b/client_end_user/shared/src/commonMain/kotlin/di/PagingDataSourceModule.kt @@ -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() } +} \ No newline at end of file diff --git a/client_end_user/shared/src/commonMain/kotlin/domain/usecase/ExploreRestaurantUseCase.kt b/client_end_user/shared/src/commonMain/kotlin/domain/usecase/ExploreRestaurantUseCase.kt index 30782f2e1..74e14d757 100644 --- a/client_end_user/shared/src/commonMain/kotlin/domain/usecase/ExploreRestaurantUseCase.kt +++ b/client_end_user/shared/src/commonMain/kotlin/domain/usecase/ExploreRestaurantUseCase.kt @@ -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> + suspend fun getRestaurants(page:Int,limit:Int): PaginationItems suspend fun getRestaurantDetails(restaurantId: String): Restaurant suspend fun getMealById(mealId: String): Meal suspend fun getCuisines(): List suspend fun getPreferredCuisines(): List - suspend fun getMealsInCuisine(cuisineId: String): Flow> + suspend fun getMealsInCuisine(cuisineId: String,page:Int,limit:Int): PaginationItems suspend fun getCuisinesWithMealsInRestaurant(restaurantId: String): List } class ExploreRestaurantUseCase( private val restaurantGateway: IRestaurantGateway, - private val mealDataSource: MealsPagingSource, - private val restaurants: RestaurantsPagingSource, private val localGateway: ILocalConfigurationGateway ) : IExploreRestaurantUseCase { @@ -48,18 +41,12 @@ class ExploreRestaurantUseCase( return cuisines.filter { preferredFood.contains(it.id) } } - override suspend fun getRestaurants(): Flow> { - return Pager( - config = PagingConfig(pageSize = 10), - pagingSourceFactory = { restaurants }, - ).flow + override suspend fun getRestaurants(page:Int,limit:Int): PaginationItems { + return restaurantGateway.getRestaurants(page = page, limit = limit) } - override suspend fun getMealsInCuisine(cuisineId: String): Flow> { - mealDataSource.initCuisine(cuisineId) - return Pager(config = PagingConfig(pageSize = 5), - pagingSourceFactory = { mealDataSource } - ).flow + override suspend fun getMealsInCuisine(cuisineId: String,page:Int,limit:Int): PaginationItems { + return restaurantGateway.getMealsInCuisine(cuisineId,page= page,limit= limit) } override suspend fun getCuisinesWithMealsInRestaurant(restaurantId: String): List { diff --git a/client_end_user/shared/src/commonMain/kotlin/domain/usecase/GetTransactionHistoryUseCase.kt b/client_end_user/shared/src/commonMain/kotlin/domain/usecase/GetTransactionHistoryUseCase.kt index 5650dec01..443dd567a 100644 --- a/client_end_user/shared/src/commonMain/kotlin/domain/usecase/GetTransactionHistoryUseCase.kt +++ b/client_end_user/shared/src/commonMain/kotlin/domain/usecase/GetTransactionHistoryUseCase.kt @@ -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> - suspend fun getTripsHistory(): Flow> - suspend fun getNotificationHistory(): Flow> + suspend fun getOrdersHistory(page: Int, limit: Int): PaginationItems + suspend fun getTripsHistory(page: Int, limit: Int): PaginationItems + suspend fun getNotificationHistory(page: Int, limit: Int): PaginationItems suspend fun getNotificationHistoryInLast24Hours(): List } 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> { - return Pager(config = PagingConfig(pageSize = 10, enablePlaceholders = true), - pagingSourceFactory = { foodOrderDataSource } - ).flow + override suspend fun getOrdersHistory(page: Int, limit: Int): PaginationItems { + return transactionsGateway.getOrderHistoryGateway(page, limit) } - override suspend fun getTripsHistory(): Flow> { - return Pager(config = PagingConfig(pageSize = 10, enablePlaceholders = true), - pagingSourceFactory = { taxiOrder } - ).flow + override suspend fun getTripsHistory(page: Int, limit: Int): PaginationItems { + return transactionsGateway.getTripHistory(page, limit) } - override suspend fun getNotificationHistory(): Flow> { - return Pager(config = PagingConfig(pageSize = 10, enablePlaceholders = true), - pagingSourceFactory = { notificationPagingSource } - ).flow + override suspend fun getNotificationHistory(page: Int, limit: Int): PaginationItems { + return userGateway.getNotificationHistory(page, limit) } override suspend fun getNotificationHistoryInLast24Hours(): List { diff --git a/client_end_user/shared/src/commonMain/kotlin/presentation/meals/MealsScreenModel.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/meals/MealsScreenModel.kt index 213061de1..54d586b6b 100644 --- a/client_end_user/shared/src/commonMain/kotlin/presentation/meals/MealsScreenModel.kt +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/meals/MealsScreenModel.kt @@ -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 @@ -21,6 +22,7 @@ class MealsScreenModel( private val manageRestaurant: IExploreRestaurantUseCase, private val manageAuthentication: IManageAuthenticationUseCase, private val manageCart: IManageCartUseCase, + private val paginationSource: IPagingSource ) : BaseScreenModel(MealsUiState()), MealsInteractionListener, MealInteractionListener { @@ -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 ) diff --git a/client_end_user/shared/src/commonMain/kotlin/presentation/notification/NotificationScreenModel.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/notification/NotificationScreenModel.kt index 49c2f1508..5d064ae9a 100644 --- a/client_end_user/shared/src/commonMain/kotlin/presentation/notification/NotificationScreenModel.kt +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/notification/NotificationScreenModel.kt @@ -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()), NotificationInteractionListener { @@ -58,7 +60,7 @@ class NotificationScreenModel( ).join() tryToExecute( - function = transaction::getNotificationHistory, + function = transactionDatasource::getNotificationHistory, onSuccess = ::onGetNotificationHistorySuccess, onError = ::onGetNotificationHistoryError ).join() diff --git a/client_end_user/shared/src/commonMain/kotlin/presentation/orderHistory/OrderHistoryScreenModel.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/orderHistory/OrderHistoryScreenModel.kt index 4c7ef86c2..bbdfd654d 100644 --- a/client_end_user/shared/src/commonMain/kotlin/presentation/orderHistory/OrderHistoryScreenModel.kt +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/orderHistory/OrderHistoryScreenModel.kt @@ -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()), OrderHistoryScreenInteractionListener { @@ -55,7 +53,7 @@ class OrderHistoryScreenModel( private fun getOrdersHistory() { tryToExecute( - { orderHistoryUseCase.getOrdersHistory() }, + { orderHistory.getOrdersHistory() }, ::onGetOrdersHistorySuccess, ::onError ) @@ -63,7 +61,7 @@ class OrderHistoryScreenModel( private fun getTripsHistory() { tryToExecute( - { orderHistoryUseCase.getTripsHistory() }, + { orderHistory.getTripsHistory() }, ::onGetTripsHistorySuccess, ::onError ) diff --git a/client_end_user/shared/src/commonMain/kotlin/presentation/restaurants/RestaurantsScreenModel.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/restaurants/RestaurantsScreenModel.kt index 4cce9bf58..042f1c54a 100644 --- a/client_end_user/shared/src/commonMain/kotlin/presentation/restaurants/RestaurantsScreenModel.kt +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/restaurants/RestaurantsScreenModel.kt @@ -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()), RestaurantsListener { override val viewModelScope: CoroutineScope = coroutineScope diff --git a/client_end_user/shared/src/commonMain/kotlin/presentation/util/IPagingSource.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/util/IPagingSource.kt new file mode 100644 index 000000000..df0c12910 --- /dev/null +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/util/IPagingSource.kt @@ -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> + suspend fun getRestaurants(): Flow> + suspend fun getNotificationHistory(): Flow> + suspend fun getOrdersHistory(): Flow> + suspend fun getTripsHistory(): Flow> + +} \ No newline at end of file diff --git a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/BasePagingSource.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/BasePagingSource.kt similarity index 96% rename from client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/BasePagingSource.kt rename to client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/BasePagingSource.kt index 15a85f3ca..993573f2d 100644 --- a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/BasePagingSource.kt +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/BasePagingSource.kt @@ -1,4 +1,4 @@ -package data.gateway.remote.pagesource +package presentation.util.pagesource import app.cash.paging.PagingSource diff --git a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/FoodOrderPagingSource.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/FoodOrderPagingSource.kt similarity index 51% rename from client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/FoodOrderPagingSource.kt rename to client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/FoodOrderPagingSource.kt index 6f2b47031..74981dbee 100644 --- a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/FoodOrderPagingSource.kt +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/FoodOrderPagingSource.kt @@ -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(), KoinComponent { override suspend fun fetchData(page: Int, limit: Int): PaginationItems { - return transactionsGateway.getOrderHistoryGateway(page, limit) + return transactionHistory.getOrdersHistory(page, limit) } } diff --git a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/MealsPagingSource.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/MealsPagingSource.kt similarity index 53% rename from client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/MealsPagingSource.kt rename to client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/MealsPagingSource.kt index 53d827c1e..ec52aa3cb 100644 --- a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/MealsPagingSource.kt +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/MealsPagingSource.kt @@ -1,16 +1,15 @@ -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() { + private var cuisineId by Delegates.notNull() fun initCuisine(id: String) { @@ -18,7 +17,7 @@ class MealsPagingSource( } override suspend fun fetchData(page: Int, limit: Int): PaginationItems { - return remoteGateway.getMealsInCuisine(cuisineId, page, limit) + return exploreRestaurant.getMealsInCuisine(cuisineId, page, limit) } } diff --git a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/NotificationPagingSource.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/NotificationPagingSource.kt similarity index 60% rename from client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/NotificationPagingSource.kt rename to client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/NotificationPagingSource.kt index 7a4fea577..0a4cb2c1a 100644 --- a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/NotificationPagingSource.kt +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/NotificationPagingSource.kt @@ -1,14 +1,14 @@ -package data.gateway.remote.pagesource +package presentation.util.pagesource import domain.entity.NotificationHistory import domain.entity.PaginationItems -import domain.gateway.IUserGateway +import domain.usecase.IGetTransactionHistoryUseCase import org.koin.core.component.KoinComponent class NotificationPagingSource( - private val userGateway: IUserGateway, + private val transaction: IGetTransactionHistoryUseCase, ) : BasePagingSource(), KoinComponent { override suspend fun fetchData(page: Int, limit: Int): PaginationItems { - return userGateway.getNotificationHistory(page, limit) + return transaction.getNotificationHistory(page, limit) } } \ No newline at end of file diff --git a/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/PagingSource.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/PagingSource.kt new file mode 100644 index 000000000..6c00c3032 --- /dev/null +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/PagingSource.kt @@ -0,0 +1,60 @@ +package presentation.util.pagesource + +import app.cash.paging.Pager +import app.cash.paging.PagingConfig +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 +import presentation.util.IPagingSource + +class PagingSource( + private val mealDataSource: MealsPagingSource, + private val restaurantDataSource: RestaurantsPagingSource, + private val foodOrderPagingSource: FoodOrderPagingSource, + private val notificationPagingSource: NotificationPagingSource, + private val taxiOrderPagingSource: TaxiOrderPagingSource, +) : IPagingSource { + override fun getMealsInCuisine(cuisineId: String): Flow> { + mealDataSource.initCuisine(cuisineId) + return Pager(config = PagingConfig(pageSize = 5), pagingSourceFactory = { mealDataSource } + ).flow + } + + override suspend fun getRestaurants(): Flow> { + return Pager( + config = PagingConfig(pageSize = 10), pagingSourceFactory = { restaurantDataSource }, + ).flow + } + + override suspend fun getNotificationHistory(): Flow> { + return Pager(config = androidx.paging.PagingConfig( + pageSize = 10, + enablePlaceholders = true + ), + pagingSourceFactory = { notificationPagingSource } + ).flow + } + + override suspend fun getOrdersHistory(): Flow> { + return androidx.paging.Pager(config = androidx.paging.PagingConfig( + pageSize = 10, + enablePlaceholders = true + ), + pagingSourceFactory = { foodOrderPagingSource } + ).flow + } + + override suspend fun getTripsHistory(): Flow> { + return androidx.paging.Pager(config = androidx.paging.PagingConfig( + pageSize = 10, + enablePlaceholders = true + ), + pagingSourceFactory = { taxiOrderPagingSource } + ).flow + } + +} \ No newline at end of file diff --git a/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/RestaurantsPagingSource.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/RestaurantsPagingSource.kt new file mode 100644 index 000000000..a4aea95cf --- /dev/null +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/RestaurantsPagingSource.kt @@ -0,0 +1,15 @@ +package presentation.util.pagesource + +import domain.entity.PaginationItems +import domain.entity.Restaurant +import domain.usecase.IExploreRestaurantUseCase + +class RestaurantsPagingSource( + private val exploreRestaurant: IExploreRestaurantUseCase +) : BasePagingSource() { + + override suspend fun fetchData(page: Int, limit: Int): PaginationItems { + return exploreRestaurant.getRestaurants(page, limit) + } + +} diff --git a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/TaxiOrderPagingSource.kt b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/TaxiOrderPagingSource.kt similarity index 57% rename from client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/TaxiOrderPagingSource.kt rename to client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/TaxiOrderPagingSource.kt index 1708e9961..30df6a71a 100644 --- a/client_end_user/shared/src/commonMain/kotlin/data/gateway/remote/pagesource/TaxiOrderPagingSource.kt +++ b/client_end_user/shared/src/commonMain/kotlin/presentation/util/pagesource/TaxiOrderPagingSource.kt @@ -1,16 +1,15 @@ -package data.gateway.remote.pagesource +package presentation.util.pagesource import domain.entity.PaginationItems import domain.entity.Trip -import domain.gateway.ITransactionsGateway +import domain.usecase.IGetTransactionHistoryUseCase import org.koin.core.component.KoinComponent class TaxiOrderPagingSource( - private val transactionsGateway: ITransactionsGateway, + private val transaction: IGetTransactionHistoryUseCase, ) : BasePagingSource(), KoinComponent { override suspend fun fetchData(page: Int, limit: Int): PaginationItems { - return transactionsGateway.getTripHistory(page, limit) + return transaction.getTripsHistory(page, limit) } - }