хотфикс сеансов
This commit is contained in:
parent
d35ee4907d
commit
93f4af21a9
@ -40,11 +40,6 @@ class RestSessionRepository(
|
|||||||
service.deleteUserSession(userSessionRemote.id)
|
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)
|
service.deleteSession(session.uid)
|
||||||
dbUserSessionRepository.deleteSessionsByUid(session.uid)
|
dbUserSessionRepository.deleteSessionsByUid(session.uid)
|
||||||
dbOrderSessionRepository.deleteSessionsByUid(session.uid)
|
dbOrderSessionRepository.deleteSessionsByUid(session.uid)
|
||||||
|
@ -27,10 +27,6 @@ object AppViewModelProvider {
|
|||||||
CinemaViewModel(
|
CinemaViewModel(
|
||||||
this.createSavedStateHandle(),
|
this.createSavedStateHandle(),
|
||||||
cinemaApplication().container.cinemaRestRepository,
|
cinemaApplication().container.cinemaRestRepository,
|
||||||
)
|
|
||||||
}
|
|
||||||
initializer {
|
|
||||||
SessionListViewModel(
|
|
||||||
cinemaApplication().container.sessionRestRepository,
|
cinemaApplication().container.sessionRestRepository,
|
||||||
cinemaApplication().container.userSessionRestRepository,
|
cinemaApplication().container.userSessionRestRepository,
|
||||||
)
|
)
|
||||||
|
@ -4,12 +4,20 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.lifecycle.SavedStateHandle
|
import androidx.lifecycle.SavedStateHandle
|
||||||
|
import com.example.myapplication.LiveStore
|
||||||
import com.example.myapplication.composeui.MyViewModel
|
import com.example.myapplication.composeui.MyViewModel
|
||||||
import com.example.myapplication.database.entities.model.CinemaWithSessions
|
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.CinemaRepository
|
||||||
|
import com.example.myapplication.database.entities.repository.SessionRepository
|
||||||
|
import com.example.myapplication.database.entities.repository.UserSessionRepository
|
||||||
|
|
||||||
class CinemaViewModel(
|
class CinemaViewModel(
|
||||||
savedStateHandle: SavedStateHandle, private val cinemaRepository: CinemaRepository
|
savedStateHandle: SavedStateHandle, private val cinemaRepository: CinemaRepository,
|
||||||
|
private val sessionRepository: SessionRepository,
|
||||||
|
private val userSessionRepository: UserSessionRepository
|
||||||
) : MyViewModel() {
|
) : MyViewModel() {
|
||||||
private val cinemaUid: Int = checkNotNull(savedStateHandle["id"])
|
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)
|
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.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.example.myapplication.LiveStore
|
import com.example.myapplication.LiveStore
|
||||||
import com.example.myapplication.R
|
import com.example.myapplication.R
|
||||||
@ -42,8 +41,7 @@ import org.threeten.bp.format.DateTimeFormatter
|
|||||||
@Composable
|
@Composable
|
||||||
fun SessionList(
|
fun SessionList(
|
||||||
cinemaWithSessionsViewModel: CinemaViewModel,
|
cinemaWithSessionsViewModel: CinemaViewModel,
|
||||||
navController: NavController,
|
navController: NavController
|
||||||
viewModel: SessionListViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
|
||||||
) {
|
) {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
val cinemaWithSessions = cinemaWithSessionsViewModel.cinemaUiState.cinemaWithSessions!!
|
val cinemaWithSessions = cinemaWithSessionsViewModel.cinemaUiState.cinemaWithSessions!!
|
||||||
@ -113,7 +111,7 @@ fun SessionList(
|
|||||||
IconButton(
|
IconButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
viewModel.addSessionInCart(sessionId = session.uid)
|
cinemaWithSessionsViewModel.addSessionInCart(sessionId = session.uid)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
@ -129,8 +127,7 @@ fun SessionList(
|
|||||||
IconButton(
|
IconButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
viewModel.deleteSession(session = session)
|
cinemaWithSessionsViewModel.deleteSession(session = session)
|
||||||
cinemaWithSessionsViewModel.refreshState()
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
@ -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