хотфикс сеансов
This commit is contained in:
parent
d35ee4907d
commit
93f4af21a9
@ -40,11 +40,6 @@ class RestSessionRepository(
|
||||
service.deleteUserSession(userSessionRemote.id)
|
||||
}
|
||||
}
|
||||
val orders = service.getOrders()
|
||||
orders.forEach { orderRemote ->
|
||||
orderRemote.sessions = orderRemote.sessions.filter { x -> x.id != session.uid }
|
||||
service.updateOrder(orderRemote.id, orderRemote)
|
||||
}
|
||||
service.deleteSession(session.uid)
|
||||
dbUserSessionRepository.deleteSessionsByUid(session.uid)
|
||||
dbOrderSessionRepository.deleteSessionsByUid(session.uid)
|
||||
|
@ -27,10 +27,6 @@ object AppViewModelProvider {
|
||||
CinemaViewModel(
|
||||
this.createSavedStateHandle(),
|
||||
cinemaApplication().container.cinemaRestRepository,
|
||||
)
|
||||
}
|
||||
initializer {
|
||||
SessionListViewModel(
|
||||
cinemaApplication().container.sessionRestRepository,
|
||||
cinemaApplication().container.userSessionRestRepository,
|
||||
)
|
||||
|
@ -4,12 +4,20 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import com.example.myapplication.LiveStore
|
||||
import com.example.myapplication.composeui.MyViewModel
|
||||
import com.example.myapplication.database.entities.model.CinemaWithSessions
|
||||
import com.example.myapplication.database.entities.model.Session
|
||||
import com.example.myapplication.database.entities.model.SessionFromCinema
|
||||
import com.example.myapplication.database.entities.model.UserSessionCrossRef
|
||||
import com.example.myapplication.database.entities.repository.CinemaRepository
|
||||
import com.example.myapplication.database.entities.repository.SessionRepository
|
||||
import com.example.myapplication.database.entities.repository.UserSessionRepository
|
||||
|
||||
class CinemaViewModel(
|
||||
savedStateHandle: SavedStateHandle, private val cinemaRepository: CinemaRepository
|
||||
savedStateHandle: SavedStateHandle, private val cinemaRepository: CinemaRepository,
|
||||
private val sessionRepository: SessionRepository,
|
||||
private val userSessionRepository: UserSessionRepository
|
||||
) : MyViewModel() {
|
||||
private val cinemaUid: Int = checkNotNull(savedStateHandle["id"])
|
||||
|
||||
@ -25,6 +33,34 @@ class CinemaViewModel(
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteSession(session: SessionFromCinema) {
|
||||
runInScope(actionSuccess = {
|
||||
sessionRepository.deleteSession(
|
||||
Session(
|
||||
uid = session.uid,
|
||||
dateTime = session.dateTime,
|
||||
price = session.price,
|
||||
maxCount = 0,
|
||||
cinemaId = 0
|
||||
)
|
||||
)
|
||||
refreshState()
|
||||
})
|
||||
}
|
||||
|
||||
suspend fun addSessionInCart(sessionId: Int, count: Int = 1) {
|
||||
val userId: Int = LiveStore.user.value?.uid ?: return
|
||||
runInScope(actionSuccess = {
|
||||
userSessionRepository.insertUserSession(
|
||||
UserSessionCrossRef(
|
||||
userId,
|
||||
sessionId,
|
||||
count
|
||||
)
|
||||
)
|
||||
}, actionError = {}, needLoadingScreen = false)
|
||||
}
|
||||
}
|
||||
|
||||
data class CinemaUiState(val cinemaWithSessions: CinemaWithSessions? = null)
|
@ -30,7 +30,6 @@ import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavController
|
||||
import com.example.myapplication.LiveStore
|
||||
import com.example.myapplication.R
|
||||
@ -42,8 +41,7 @@ import org.threeten.bp.format.DateTimeFormatter
|
||||
@Composable
|
||||
fun SessionList(
|
||||
cinemaWithSessionsViewModel: CinemaViewModel,
|
||||
navController: NavController,
|
||||
viewModel: SessionListViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
||||
navController: NavController
|
||||
) {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val cinemaWithSessions = cinemaWithSessionsViewModel.cinemaUiState.cinemaWithSessions!!
|
||||
@ -113,7 +111,7 @@ fun SessionList(
|
||||
IconButton(
|
||||
onClick = {
|
||||
coroutineScope.launch {
|
||||
viewModel.addSessionInCart(sessionId = session.uid)
|
||||
cinemaWithSessionsViewModel.addSessionInCart(sessionId = session.uid)
|
||||
}
|
||||
},
|
||||
) {
|
||||
@ -129,8 +127,7 @@ fun SessionList(
|
||||
IconButton(
|
||||
onClick = {
|
||||
coroutineScope.launch {
|
||||
viewModel.deleteSession(session = session)
|
||||
cinemaWithSessionsViewModel.refreshState()
|
||||
cinemaWithSessionsViewModel.deleteSession(session = session)
|
||||
}
|
||||
},
|
||||
) {
|
||||
|
@ -1,41 +0,0 @@
|
||||
package com.example.myapplication.database.entities.composeui
|
||||
|
||||
import com.example.myapplication.LiveStore
|
||||
import com.example.myapplication.composeui.MyViewModel
|
||||
import com.example.myapplication.database.entities.model.Session
|
||||
import com.example.myapplication.database.entities.model.SessionFromCinema
|
||||
import com.example.myapplication.database.entities.model.UserSessionCrossRef
|
||||
import com.example.myapplication.database.entities.repository.SessionRepository
|
||||
import com.example.myapplication.database.entities.repository.UserSessionRepository
|
||||
|
||||
class SessionListViewModel(
|
||||
private val sessionRepository: SessionRepository,
|
||||
private val userSessionRepository: UserSessionRepository
|
||||
) : MyViewModel() {
|
||||
suspend fun deleteSession(session: SessionFromCinema) {
|
||||
runInScope(actionSuccess = {
|
||||
sessionRepository.deleteSession(
|
||||
Session(
|
||||
uid = session.uid,
|
||||
dateTime = session.dateTime,
|
||||
price = session.price,
|
||||
maxCount = 0,
|
||||
cinemaId = 0
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
suspend fun addSessionInCart(sessionId: Int, count: Int = 1) {
|
||||
val userId: Int = LiveStore.user.value?.uid ?: return
|
||||
runInScope(actionSuccess = {
|
||||
userSessionRepository.insertUserSession(
|
||||
UserSessionCrossRef(
|
||||
userId,
|
||||
sessionId,
|
||||
count
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user