исправление багов в медиаторе заказов
This commit is contained in:
parent
30f50e94c7
commit
baf333dea1
@ -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 {
|
||||
|
@ -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<PagingData<Order>> {
|
||||
val pagingSourceFactory = { dbOrderRepository.getAllOrdersPagingSource(userId) }
|
||||
|
||||
override fun getAllOrders(): Flow<PagingData<Order>> {
|
||||
val pagingSourceFactory = { dbOrderRepository.getAllOrdersPagingSource() }
|
||||
Log.d("RestOrderRepository", "?")
|
||||
@OptIn(ExperimentalPagingApi::class)
|
||||
return Pager(
|
||||
config = PagingConfig(
|
||||
|
@ -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()
|
||||
|
@ -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<PagingData<Order>> = emptyFlow()
|
||||
|
||||
fun refreshState(userId: Int = 0) {
|
||||
runInScope(actionSuccess = {
|
||||
orderListUiState = orderRepository.getAllOrders(userId)
|
||||
})
|
||||
}
|
||||
var orderListUiState: Flow<PagingData<Order>> = orderRepository.getAllOrders()
|
||||
}
|
@ -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
|
||||
)
|
||||
}
|
||||
|
@ -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<PagingData<Order>> = Pager(
|
||||
override fun getAllOrders(): Flow<PagingData<Order>> = 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<SessionFromOrder> = orderDao.getByUid(uid)
|
||||
|
||||
override suspend fun insertOrder(order: Order): Long = orderDao.insert(order).first()
|
||||
|
||||
fun getAllOrdersPagingSource(userId: Int?): PagingSource<Int, Order> = orderDao.getAll(userId)
|
||||
fun getAllOrdersPagingSource(): PagingSource<Int, Order> {
|
||||
return orderDao.getAll(LiveStore.user.value?.uid ?: 0)
|
||||
}
|
||||
|
||||
suspend fun clearOrders() = orderDao.deleteAll()
|
||||
|
||||
|
@ -6,7 +6,7 @@ import com.example.myapplication.database.entities.model.SessionFromOrder
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface OrderRepository {
|
||||
fun getAllOrders(userId: Int): Flow<PagingData<Order>>
|
||||
fun getAllOrders(): Flow<PagingData<Order>>
|
||||
suspend fun getOrder(uid: Int): List<SessionFromOrder>
|
||||
suspend fun insertOrder(order: Order): Long
|
||||
}
|
@ -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": [
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user