коммит
This commit is contained in:
parent
baa2a95145
commit
cb69d513e0
@ -58,29 +58,6 @@ class RestUserRepository(
|
||||
return existUsers.map { it.value }.sortedBy { it.id }
|
||||
}
|
||||
|
||||
// override suspend fun getUserRents(userId: Int): List<Rent> {
|
||||
// Log.d(RestUserRepository::class.simpleName, "Get user's $userId rents")
|
||||
// val existRents = dbUserRepository.getUserRents(userId).associateBy { it.id }.toMutableMap()
|
||||
//
|
||||
// service.getUserRents(userId)
|
||||
// .map { it.toRent() }
|
||||
// .forEach { rent ->
|
||||
// Log.d(RestUserRepository::class.simpleName, "айди брони: ${rent.id}, и пользователя: ${rent.userId}")
|
||||
// if(rent.userId == userId) {
|
||||
//// val existRent = existRents[rent.id]
|
||||
//// if (existRent == null) {
|
||||
//// Log.d(RestUserRepository::class.simpleName, "бронирования нет в бд")
|
||||
//// dbRentRepository.insertRent(rent)
|
||||
//// } else if (existRent != rent) {
|
||||
//// Log.d(RestUserRepository::class.simpleName, "бронирование есть в бд")
|
||||
//// dbRentRepository.updateRent(rent)
|
||||
//// }
|
||||
// existRents[rent.id] = rent
|
||||
// }
|
||||
// }
|
||||
// return existRents.map { it.value }.sortedBy { it.id }
|
||||
// }
|
||||
|
||||
override suspend fun getUserRents(userId: Int): List<Rent> {
|
||||
return try {
|
||||
val usersRents = service.getUserRents(userId)
|
||||
|
@ -27,6 +27,6 @@ fun NavGraphBuilder.authNavGraph(navController: NavHostController, registrationV
|
||||
}
|
||||
|
||||
sealed class AuthScreen(val route: String){
|
||||
object Login: AuthScreen(route = "login")
|
||||
object Registration: AuthScreen(route="registration")
|
||||
}
|
||||
object Login: AuthScreen("login")
|
||||
object Registration: AuthScreen("registration")
|
||||
}
|
||||
|
@ -45,6 +45,8 @@ import ru.ulstu.`is`.airticketrentservice.viewModel.AppViewModelProvider
|
||||
import ru.ulstu.`is`.airticketrentservice.viewModel.CurrentUserViewModel
|
||||
import ru.ulstu.`is`.airticketrentservice.R
|
||||
import ru.ulstu.`is`.airticketrentservice.graphs.AuthScreen
|
||||
import ru.ulstu.`is`.airticketrentservice.graphs.Graph
|
||||
import ru.ulstu.`is`.airticketrentservice.graphs.USERID_ARGUMENT
|
||||
import ru.ulstu.`is`.airticketrentservice.navigation.BottomBarScreen
|
||||
import ru.ulstu.`is`.airticketrentservice.viewModel.toUiState
|
||||
|
||||
@ -167,22 +169,5 @@ fun Profile(
|
||||
Text("Мои бронирования")
|
||||
}
|
||||
)
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 5.dp, bottom = 50.dp),
|
||||
onClick = {
|
||||
navController.navigate(AuthScreen.Login.route)
|
||||
},
|
||||
elevation = ButtonDefaults.buttonElevation(
|
||||
defaultElevation = 10.dp,
|
||||
pressedElevation = 6.dp
|
||||
),
|
||||
shape = RoundedCornerShape(15.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color.Red),
|
||||
content = {
|
||||
Text("Выйти")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
@ -31,6 +31,7 @@ import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
@ -140,6 +141,7 @@ fun Login(navController: NavController, modifier: Modifier = Modifier, loginView
|
||||
defaultElevation = 10.dp,
|
||||
pressedElevation = 6.dp
|
||||
),
|
||||
enabled = (passwordValue.isNotEmpty() && isValidEmail(emailValue)),
|
||||
shape = RoundedCornerShape(15.dp),
|
||||
onClick = {
|
||||
if (passwordValue.isNotEmpty() && isValidEmail(emailValue)) {
|
||||
|
@ -18,13 +18,13 @@ import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Visibility
|
||||
import androidx.compose.material.icons.filled.VisibilityOff
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Divider
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.OutlinedTextFieldDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TextField
|
||||
@ -53,9 +53,9 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavController
|
||||
import androidx.room.ColumnInfo
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.ulstu.`is`.airticketrentservice.database.models.User
|
||||
@ -253,12 +253,6 @@ fun Registration(navController: NavController, modifier: Modifier = Modifier, re
|
||||
}
|
||||
}
|
||||
)
|
||||
Text(
|
||||
text = isValid,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(),
|
||||
)
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -273,7 +267,16 @@ fun Registration(navController: NavController, modifier: Modifier = Modifier, re
|
||||
}
|
||||
}
|
||||
if (!isExist) {
|
||||
val newUser = User(0, surnameValue, nameValue, patronymicValue, dateOfBirthValue, emailValue, passwordValue, RoleEnum.User.name)
|
||||
val newUser = User(
|
||||
0,
|
||||
surnameValue,
|
||||
nameValue,
|
||||
patronymicValue,
|
||||
dateOfBirthValue,
|
||||
emailValue,
|
||||
passwordValue,
|
||||
RoleEnum.User.name
|
||||
)
|
||||
coroutineScope.launch {
|
||||
val insertResult = async {
|
||||
registrationViewModel.insertUser(newUser)
|
||||
@ -294,10 +297,9 @@ fun Registration(navController: NavController, modifier: Modifier = Modifier, re
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isValid = "Данные не корректны"
|
||||
}
|
||||
},
|
||||
enabled = (passwordValue.isNotEmpty() && isValidEmail(emailValue) && surnameValue.isNotEmpty() && nameValue.isNotEmpty() && patronymicValue.isNotEmpty() && dateOfBirthValue.isNotEmpty()),
|
||||
elevation = ButtonDefaults.buttonElevation(
|
||||
defaultElevation = 10.dp,
|
||||
pressedElevation = 6.dp
|
||||
@ -327,4 +329,30 @@ fun Registration(navController: NavController, modifier: Modifier = Modifier, re
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AlertDialog(
|
||||
showDialog: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
text: String = ""
|
||||
) {
|
||||
if (showDialog) {
|
||||
AlertDialog (
|
||||
onDismissRequest = { onDismiss() },
|
||||
title = {
|
||||
Text(text)
|
||||
},
|
||||
confirmButton = {
|
||||
Button(onClick = { onDismiss() }, elevation = ButtonDefaults.buttonElevation(
|
||||
defaultElevation = 10.dp,
|
||||
pressedElevation = 6.dp
|
||||
),
|
||||
shape = RoundedCornerShape(15.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.lightBlue))) {
|
||||
Text("OK")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,4 @@ class CurrentUserViewModel(private val userRepository: UserRepository) : ViewMod
|
||||
user = userRepository.getUserById(userid.intValue)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateUser(user: User) {
|
||||
userRepository.updateUser(user)
|
||||
}
|
||||
}
|
@ -22,21 +22,6 @@ class RentListViewModel (
|
||||
) : ViewModel() {
|
||||
val rentListUiState: Flow<PagingData<Rent>> = rentRepository.getRents()
|
||||
|
||||
// private var userId: Int = 0
|
||||
// fun setUserId(userId: Int) {
|
||||
// this.userId = userId
|
||||
// }
|
||||
// var userRentsUiState by mutableStateOf(UserRentsUiState())
|
||||
// private set
|
||||
//
|
||||
// init {
|
||||
// viewModelScope.launch {
|
||||
// if (userId > 0) {
|
||||
// userRentsUiState = UserRentsUiState(userRepository.getUserRents(userId))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
suspend fun deleteRent(rent: Rent) {
|
||||
rentRepository.deleteRent(rent)
|
||||
}
|
||||
|
276
server/data.json
276
server/data.json
@ -11,6 +11,168 @@
|
||||
"passengers_count": 2,
|
||||
"ticket_cost": 4870,
|
||||
"flightId": 5
|
||||
},
|
||||
{
|
||||
"passengers_count": 5,
|
||||
"ticket_cost": 54000,
|
||||
"flightId": 10,
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"passengers_count": 1,
|
||||
"ticket_cost": 2680,
|
||||
"flightId": 6,
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"passengers_count": 2,
|
||||
"ticket_cost": 17440,
|
||||
"flightId": 8
|
||||
},
|
||||
{
|
||||
"passengers_count": 4,
|
||||
"ticket_cost": 71200,
|
||||
"flightId": 9,
|
||||
"id": 7
|
||||
},
|
||||
{
|
||||
"passengers_count": 6,
|
||||
"ticket_cost": 106800,
|
||||
"flightId": 9,
|
||||
"id": 9
|
||||
},
|
||||
{
|
||||
"passengers_count": 6,
|
||||
"ticket_cost": 106800,
|
||||
"flightId": 9,
|
||||
"id": 10
|
||||
},
|
||||
{
|
||||
"passengers_count": 11,
|
||||
"ticket_cost": 29480,
|
||||
"flightId": 6,
|
||||
"id": 12
|
||||
},
|
||||
{
|
||||
"passengers_count": 3,
|
||||
"ticket_cost": 8040,
|
||||
"flightId": 6,
|
||||
"id": 13
|
||||
},
|
||||
{
|
||||
"passengers_count": 8,
|
||||
"ticket_cost": 142400,
|
||||
"flightId": 9,
|
||||
"id": 14
|
||||
},
|
||||
{
|
||||
"passengers_count": 1,
|
||||
"ticket_cost": 2680,
|
||||
"flightId": 6,
|
||||
"id": 15
|
||||
},
|
||||
{
|
||||
"passengers_count": 1,
|
||||
"ticket_cost": 2680,
|
||||
"flightId": 6,
|
||||
"id": 16
|
||||
},
|
||||
{
|
||||
"passengers_count": 1,
|
||||
"ticket_cost": 2680,
|
||||
"flightId": 6,
|
||||
"id": 17
|
||||
},
|
||||
{
|
||||
"passengers_count": 1,
|
||||
"ticket_cost": 17800,
|
||||
"flightId": 9,
|
||||
"id": 18
|
||||
},
|
||||
{
|
||||
"passengers_count": 5,
|
||||
"ticket_cost": 5000,
|
||||
"flightId": 2,
|
||||
"id": 19
|
||||
},
|
||||
{
|
||||
"passengers_count": 6,
|
||||
"ticket_cost": 6000,
|
||||
"flightId": 2,
|
||||
"id": 20
|
||||
},
|
||||
{
|
||||
"passengers_count": 3,
|
||||
"ticket_cost": 3000,
|
||||
"flightId": 2,
|
||||
"id": 21
|
||||
},
|
||||
{
|
||||
"passengers_count": 10,
|
||||
"ticket_cost": 10000,
|
||||
"flightId": 2,
|
||||
"id": 22
|
||||
},
|
||||
{
|
||||
"passengers_count": 6,
|
||||
"ticket_cost": 6000,
|
||||
"flightId": 2,
|
||||
"id": 23
|
||||
},
|
||||
{
|
||||
"passengers_count": 9,
|
||||
"ticket_cost": 160200,
|
||||
"flightId": 9,
|
||||
"id": 24
|
||||
},
|
||||
{
|
||||
"passengers_count": 8,
|
||||
"ticket_cost": 142400,
|
||||
"flightId": 9,
|
||||
"id": 25
|
||||
},
|
||||
{
|
||||
"passengers_count": 3,
|
||||
"ticket_cost": 53400,
|
||||
"flightId": 9,
|
||||
"id": 26
|
||||
},
|
||||
{
|
||||
"passengers_count": 6,
|
||||
"ticket_cost": 106800,
|
||||
"flightId": 9,
|
||||
"id": 27
|
||||
},
|
||||
{
|
||||
"passengers_count": 5,
|
||||
"ticket_cost": 89000,
|
||||
"flightId": 9,
|
||||
"id": 28
|
||||
},
|
||||
{
|
||||
"passengers_count": 3,
|
||||
"ticket_cost": 20610,
|
||||
"flightId": 7,
|
||||
"id": 29
|
||||
},
|
||||
{
|
||||
"passengers_count": 5,
|
||||
"ticket_cost": 5000,
|
||||
"flightId": 2,
|
||||
"id": 30
|
||||
},
|
||||
{
|
||||
"passengers_count": 2,
|
||||
"ticket_cost": 5360,
|
||||
"flightId": 6,
|
||||
"id": 31
|
||||
},
|
||||
{
|
||||
"passengers_count": 3,
|
||||
"ticket_cost": 7305,
|
||||
"flightId": 5,
|
||||
"id": 32
|
||||
}
|
||||
],
|
||||
"flights": [
|
||||
@ -69,6 +231,38 @@
|
||||
"arrival_date": "15-1-2024",
|
||||
"one_ticket_cost": 10800,
|
||||
"id": 10
|
||||
},
|
||||
{
|
||||
"direction_from": "Москва",
|
||||
"direction_to": "Крым",
|
||||
"departure_date": "24-12-2023",
|
||||
"arrival_date": "31-12-2023",
|
||||
"one_ticket_cost": 3850,
|
||||
"id": 11
|
||||
},
|
||||
{
|
||||
"direction_from": "Кострома",
|
||||
"direction_to": "Хабаровск",
|
||||
"departure_date": "29-12-2023",
|
||||
"arrival_date": "29-12-2023",
|
||||
"one_ticket_cost": 5000,
|
||||
"id": 12
|
||||
},
|
||||
{
|
||||
"direction_from": "Москва",
|
||||
"direction_to": "Кострома",
|
||||
"departure_date": "6-1-2024",
|
||||
"arrival_date": "6-1-2024",
|
||||
"one_ticket_cost": 35740,
|
||||
"id": 13
|
||||
},
|
||||
{
|
||||
"direction_from": "Москва",
|
||||
"direction_to": "Ульяновск",
|
||||
"departure_date": "13-1-2024",
|
||||
"arrival_date": "14-1-2024",
|
||||
"one_ticket_cost": 3570,
|
||||
"id": 14
|
||||
}
|
||||
],
|
||||
"users": [
|
||||
@ -92,6 +286,36 @@
|
||||
"role": "User",
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"surname": "ыщылы",
|
||||
"name": "шчшчгч",
|
||||
"patronymic": "шчшчшч",
|
||||
"date_of_birth": "10-12-2015",
|
||||
"email": "aaa@mail.ru",
|
||||
"password": "aaa",
|
||||
"role": "User",
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"surname": "фффф",
|
||||
"name": "ффф",
|
||||
"patronymic": "ффф",
|
||||
"date_of_birth": "7-5-2005",
|
||||
"email": "userff@mail.ru",
|
||||
"password": "password",
|
||||
"role": "User",
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"surname": "ккк",
|
||||
"name": "ккк",
|
||||
"patronymic": "ккк",
|
||||
"date_of_birth": "23-12-2011",
|
||||
"email": "kkk@mail.ru",
|
||||
"password": "kkk",
|
||||
"role": "User",
|
||||
"id": 7
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"surname": "Артамонова",
|
||||
@ -101,6 +325,16 @@
|
||||
"email": "admin@mail.ru",
|
||||
"password": "admin",
|
||||
"role": "Admin"
|
||||
},
|
||||
{
|
||||
"surname": "user",
|
||||
"name": "user",
|
||||
"patronymic": "user",
|
||||
"date_of_birth": "13-9-2012",
|
||||
"email": "user66@mail.ru",
|
||||
"password": "user66",
|
||||
"role": "User",
|
||||
"id": 9
|
||||
}
|
||||
],
|
||||
"rents": [
|
||||
@ -116,5 +350,47 @@
|
||||
"userId": 2,
|
||||
"ticketId": 2
|
||||
},
|
||||
{
|
||||
"status": "Ожидает подтверждения",
|
||||
"userId": 2,
|
||||
"ticketId": 24,
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"status": "Ожидает подтверждения",
|
||||
"userId": 2,
|
||||
"ticketId": 25,
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"status": "Ожидает подтверждения",
|
||||
"userId": 2,
|
||||
"ticketId": 26,
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"status": "Ожидает подтверждения",
|
||||
"userId": 2,
|
||||
"ticketId": 28,
|
||||
"id": 7
|
||||
},
|
||||
{
|
||||
"status": "Ожидает подтверждения",
|
||||
"userId": 8,
|
||||
"ticketId": 29,
|
||||
"id": 8
|
||||
},
|
||||
{
|
||||
"status": "Ожидает подтверждения",
|
||||
"userId": 9,
|
||||
"ticketId": 30,
|
||||
"id": 9
|
||||
},
|
||||
{
|
||||
"status": "Ожидает подтверждения",
|
||||
"userId": 2,
|
||||
"ticketId": 31,
|
||||
"id": 10
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user