diff --git a/app/src/main/java/com/example/myapplication/api/order/OrderRemoteMediator.kt b/app/src/main/java/com/example/myapplication/api/order/OrderRemoteMediator.kt index 2eaf26f..a355b88 100644 --- a/app/src/main/java/com/example/myapplication/api/order/OrderRemoteMediator.kt +++ b/app/src/main/java/com/example/myapplication/api/order/OrderRemoteMediator.kt @@ -53,8 +53,8 @@ class OrderRemoteMediator( try { val orders = service.getOrders( - LiveStore.user.value?.uid ?: 0, - page, state.config.pageSize + userId = LiveStore.user.value?.uid ?: 0, + page = page, limit = state.config.pageSize ).map { it.toOrder() } val endOfPaginationReached = orders.isEmpty() database.withTransaction { diff --git a/app/src/main/java/com/example/myapplication/api/order/RestOrderRepository.kt b/app/src/main/java/com/example/myapplication/api/order/RestOrderRepository.kt index 09dd313..698f223 100644 --- a/app/src/main/java/com/example/myapplication/api/order/RestOrderRepository.kt +++ b/app/src/main/java/com/example/myapplication/api/order/RestOrderRepository.kt @@ -1,5 +1,6 @@ package com.example.myapplication.api.order +import android.util.Log import androidx.paging.ExperimentalPagingApi import androidx.paging.Pager import androidx.paging.PagingConfig @@ -24,9 +25,9 @@ class RestOrderRepository( private val dbRemoteKeyRepository: OfflineRemoteKeyRepository, private val database: AppDatabase ) : OrderRepository { - override fun getAllOrders(userId: Int): Flow> { - val pagingSourceFactory = { dbOrderRepository.getAllOrdersPagingSource(userId) } - + override fun getAllOrders(): Flow> { + val pagingSourceFactory = { dbOrderRepository.getAllOrdersPagingSource() } + Log.d("RestOrderRepository", "?") @OptIn(ExperimentalPagingApi::class) return Pager( config = PagingConfig( diff --git a/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderList.kt b/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderList.kt index a51d0fa..77bedb7 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderList.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderList.kt @@ -15,8 +15,6 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview @@ -26,7 +24,6 @@ import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.itemContentType import androidx.paging.compose.itemKey -import com.example.myapplication.LiveStore import com.example.myapplication.composeui.navigation.Screen import com.example.myapplication.ui.theme.PmudemoTheme import org.threeten.bp.format.DateTimeFormatter @@ -36,11 +33,8 @@ fun OrderList( navController: NavController?, viewModel: OrderListViewModel = viewModel(factory = AppViewModelProvider.Factory) ) { - val user = LiveStore.user.observeAsState() val ordersUiState = viewModel.orderListUiState.collectAsLazyPagingItems() - LaunchedEffect(user.value?.uid) { - viewModel.refreshState(user.value?.uid ?: 0) - } + LazyColumn( modifier = Modifier .fillMaxSize() diff --git a/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderListViewModel.kt b/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderListViewModel.kt index 525ce7a..b1d46bf 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderListViewModel.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderListViewModel.kt @@ -5,16 +5,9 @@ import com.example.myapplication.composeui.MyViewModel import com.example.myapplication.database.entities.model.Order import com.example.myapplication.database.entities.repository.OrderRepository import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.emptyFlow class OrderListViewModel( - private val orderRepository: OrderRepository + orderRepository: OrderRepository ) : MyViewModel() { - var orderListUiState: Flow> = emptyFlow() - - fun refreshState(userId: Int = 0) { - runInScope(actionSuccess = { - orderListUiState = orderRepository.getAllOrders(userId) - }) - } + var orderListUiState: Flow> = orderRepository.getAllOrders() } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderView.kt b/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderView.kt index 6167eeb..4d20949 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderView.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/composeui/OrderView.kt @@ -92,7 +92,7 @@ fun OrderView( Text( text = "${session.cinema.name}, ${session.cinema.year}\n" + "Цена: ${session.frozenPrice}\n" + - "Количество: $count", + "Количество: ${count.intValue}", color = MaterialTheme.colorScheme.onSecondary ) } diff --git a/app/src/main/java/com/example/myapplication/database/entities/repository/OfflineOrderRepository.kt b/app/src/main/java/com/example/myapplication/database/entities/repository/OfflineOrderRepository.kt index 53c7894..804f654 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/repository/OfflineOrderRepository.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/repository/OfflineOrderRepository.kt @@ -4,6 +4,7 @@ import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData import androidx.paging.PagingSource +import com.example.myapplication.LiveStore import com.example.myapplication.database.AppContainer import com.example.myapplication.database.entities.dao.OrderDao import com.example.myapplication.database.entities.model.Order @@ -11,19 +12,21 @@ import com.example.myapplication.database.entities.model.SessionFromOrder import kotlinx.coroutines.flow.Flow class OfflineOrderRepository(private val orderDao: OrderDao) : OrderRepository { - override fun getAllOrders(userId: Int): Flow> = Pager( + override fun getAllOrders(): Flow> = Pager( config = PagingConfig( pageSize = AppContainer.LIMIT, enablePlaceholders = false ), - pagingSourceFactory = { orderDao.getAll(userId) } + pagingSourceFactory = { orderDao.getAll(LiveStore.user.value?.uid ?: 0) } ).flow override suspend fun getOrder(uid: Int): List = orderDao.getByUid(uid) override suspend fun insertOrder(order: Order): Long = orderDao.insert(order).first() - fun getAllOrdersPagingSource(userId: Int?): PagingSource = orderDao.getAll(userId) + fun getAllOrdersPagingSource(): PagingSource { + return orderDao.getAll(LiveStore.user.value?.uid ?: 0) + } suspend fun clearOrders() = orderDao.deleteAll() diff --git a/app/src/main/java/com/example/myapplication/database/entities/repository/OrderRepository.kt b/app/src/main/java/com/example/myapplication/database/entities/repository/OrderRepository.kt index 573cb70..19ccd9c 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/repository/OrderRepository.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/repository/OrderRepository.kt @@ -6,7 +6,7 @@ import com.example.myapplication.database.entities.model.SessionFromOrder import kotlinx.coroutines.flow.Flow interface OrderRepository { - fun getAllOrders(userId: Int): Flow> + fun getAllOrders(): Flow> suspend fun getOrder(uid: Int): List suspend fun insertOrder(order: Order): Long } \ No newline at end of file diff --git a/server/data.json b/server/data.json index 218380a..2ad1a19 100644 --- a/server/data.json +++ b/server/data.json @@ -24,19 +24,13 @@ "id": 1, "userId": 3, "sessionId": 1, - "count": 5 - }, - { - "userId": 2, - "sessionId": 1, - "count": 1, - "id": 2 + "count": 3 }, { + "id": 3, "userId": 2, "sessionId": 2, - "count": 1, - "id": 3 + "count": 3 } ], "orders": [ diff --git a/server/reportRouter.js b/server/reportRouter.js index 7864dc6..1229dd6 100644 --- a/server/reportRouter.js +++ b/server/reportRouter.js @@ -44,7 +44,7 @@ module.exports = (req, res, next) => { const cinema = cinemas.find(cinema => cinema.id === session.cinemaId) return { - cinema_name: cinema ? cinema.name : "Unknown", + cinema_name: cinema ? cinema.name : "Неизвестно", current_ticket_date_time: session.dateTime, current_ticket_price: session.price, max_ticket_quantity: session.maxCount,