поиск и бронирования пользователя работают

This commit is contained in:
Татьяна Артамонова 2023-12-25 06:43:35 +04:00
parent f67c6d76be
commit a270794281
39 changed files with 552 additions and 367 deletions

View File

@ -24,22 +24,22 @@ interface AppService {
@GET("users") @GET("users")
suspend fun getAllUsers(): List<UserRemote> suspend fun getAllUsers(): List<UserRemote>
@GET("rents") @GET("rents")
suspend fun getAllRents(): List<RentRemote>
@GET("rents")
suspend fun getRents( suspend fun getRents(
@Query("_page") page: Int, @Query("_page") page: Int,
@Query("_limit") limit: Int, @Query("_limit") limit: Int,
): List<RentRemote> ): List<RentRemote>
@GET("searchFlights") @GET("flights")
suspend fun foundFlights( suspend fun findFlights(
@Query("direction_from") direction_from: String,
@Query("direction_to") direction_to: String,
@Query("departure_date") departure_date: String
): List<FlightRemote> ): List<FlightRemote>
// suspend fun findFlights(
// @Path("direction_from") from: String,
// @Path("direction_to") to: String,
// @Path("departure_date") departureDate: String
// ): List<FlightRemote>
@GET("tickets") @GET("tickets")
suspend fun getAllTickets(): List<TicketRemote> suspend fun getAllTickets(): List<TicketRemote>
@GET("foundFlights") @GET("flights")
suspend fun getAllFlights(): List<FlightRemote> suspend fun getAllFlights(): List<FlightRemote>
@GET("tickets") @GET("tickets")
suspend fun getTickets( suspend fun getTickets(
@ -55,8 +55,8 @@ interface AppService {
@GET("tickets") @GET("tickets")
suspend fun getFlightsTickets(@Query("flightId") flightId: Int): List<TicketRemote> suspend fun getFlightsTickets(@Query("flightId") flightId: Int): List<TicketRemote>
@GET("userrents/{userId}") @GET("rents")
suspend fun getUserRents(@Path("userId") userId: Int): List<RentRemote> suspend fun getUserRents(@Query("userId") userId: Int): List<RentRemote>
@GET("users/{id}") @GET("users/{id}")
suspend fun getUser( suspend fun getUser(
@ -131,7 +131,7 @@ interface AppService {
@Path("id") id: Int, @Path("id") id: Int,
): TicketRemote ): TicketRemote
companion object : AppService { companion object {
private const val BASE_URL = "http://192.168.1.100:8079/" private const val BASE_URL = "http://192.168.1.100:8079/"
@Volatile @Volatile

View File

@ -9,6 +9,7 @@ import retrofit2.HttpException
import ru.ulstu.`is`.airticketrentservice.api.AppService import ru.ulstu.`is`.airticketrentservice.api.AppService
import ru.ulstu.`is`.airticketrentservice.api.model.toRent import ru.ulstu.`is`.airticketrentservice.api.model.toRent
import ru.ulstu.`is`.airticketrentservice.api.repository.RestTicketRepository import ru.ulstu.`is`.airticketrentservice.api.repository.RestTicketRepository
import ru.ulstu.`is`.airticketrentservice.api.repository.RestUserRepository
import ru.ulstu.`is`.airticketrentservice.database.AppDatabase import ru.ulstu.`is`.airticketrentservice.database.AppDatabase
import ru.ulstu.`is`.airticketrentservice.database.repository.OfflineRemoteKeyRepository import ru.ulstu.`is`.airticketrentservice.database.repository.OfflineRemoteKeyRepository
import ru.ulstu.`is`.airticketrentservice.database.repository.OfflineRentRepository import ru.ulstu.`is`.airticketrentservice.database.repository.OfflineRentRepository
@ -22,6 +23,7 @@ class RentRemoteMediator(
private val service: AppService, private val service: AppService,
private val dbRentRepository: OfflineRentRepository, private val dbRentRepository: OfflineRentRepository,
private val dbRemoteKeyRepository: OfflineRemoteKeyRepository, private val dbRemoteKeyRepository: OfflineRemoteKeyRepository,
private val userRestRepository: RestUserRepository,
private val ticketRestRepository: RestTicketRepository, private val ticketRestRepository: RestTicketRepository,
private val database: AppDatabase private val database: AppDatabase
) : RemoteMediator<Int, Rent>() { ) : RemoteMediator<Int, Rent>() {
@ -71,8 +73,9 @@ class RentRemoteMediator(
nextKey = nextKey nextKey = nextKey
) )
} }
userRestRepository.getAllUsers()
ticketRestRepository.getAllTickets()
dbRemoteKeyRepository.createRemoteKeys(keys) dbRemoteKeyRepository.createRemoteKeys(keys)
ticketRestRepository.getTickets()
dbRentRepository.insertRents(rents) dbRentRepository.insertRents(rents)
} }
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached)

View File

@ -9,6 +9,7 @@ import retrofit2.HttpException
import ru.ulstu.`is`.airticketrentservice.api.AppService import ru.ulstu.`is`.airticketrentservice.api.AppService
import ru.ulstu.`is`.airticketrentservice.api.model.toTicket import ru.ulstu.`is`.airticketrentservice.api.model.toTicket
import ru.ulstu.`is`.airticketrentservice.api.repository.RestFlightRepository import ru.ulstu.`is`.airticketrentservice.api.repository.RestFlightRepository
import ru.ulstu.`is`.airticketrentservice.api.repository.RestUserRepository
import ru.ulstu.`is`.airticketrentservice.database.AppDatabase import ru.ulstu.`is`.airticketrentservice.database.AppDatabase
import ru.ulstu.`is`.airticketrentservice.database.models.RemoteKeyType import ru.ulstu.`is`.airticketrentservice.database.models.RemoteKeyType
import ru.ulstu.`is`.airticketrentservice.database.models.RemoteKeys import ru.ulstu.`is`.airticketrentservice.database.models.RemoteKeys
@ -71,7 +72,7 @@ class TicketRemoteMediator(
nextKey = nextKey nextKey = nextKey
) )
} }
flightRestRepository.getFlights() flightRestRepository.getAllFlights()
dbRemoteKeyRepository.createRemoteKeys(keys) dbRemoteKeyRepository.createRemoteKeys(keys)
dbTicketRepository.insertTickets(tickets) dbTicketRepository.insertTickets(tickets)
} }

View File

@ -34,22 +34,4 @@ fun Flight.toFlightRemote(): FlightRemote = FlightRemote(
arrival_date, arrival_date,
tickets_count, tickets_count,
one_ticket_cost one_ticket_cost
) )
fun foundFlights(
from: String,
to: String,
departureDate: String
): List<Flight> {
val json = File("C:\\Users\\User\\AndroidStudioProjects\\AirTicketRentService\\server").readText()
val flights = Json.decodeFromString<List<Flight>>(json)
val matchingFlights = flights.filter { flight ->
flight.direction_from == from ||
flight.direction_to == to ||
flight.departure_date == departureDate
}
return matchingFlights
}

View File

@ -61,26 +61,61 @@ class RestFlightRepository(
override suspend fun getFlightById(flightId: Int): Flight = override suspend fun getFlightById(flightId: Int): Flight =
service.getFlight(flightId).toFlight() service.getFlight(flightId).toFlight()
override suspend fun foundFlights( // override suspend fun findFlights(
// from: String,
// to: String,
// departureDate: String
// ): List<Flight> {
// val existFlights = dbFlightRepository.getAllFlights().associateBy { it.id }.toMutableMap()
//
// service.findFlights(from, to, departureDate)
// .map { it.toFlight() }
// .forEach { flight ->
// existFlights[flight.id] = flight
// }
// return existFlights.map { it.value }.sortedBy { it.id }
// }
override suspend fun findFlights(
from: String, from: String,
to: String, to: String,
departureDate: String departureDate: String
): List<Flight> { ): List<Flight> {
return try {
val foundFlights = service.findFlights(from, to, departureDate)
if (foundFlights.isNotEmpty()) {
foundFlights.map { it.toFlight() }
} else {
emptyList()
}
} catch (e: Exception) {
e.message?.let { Log.d(RestFlightRepository::class.simpleName, it) }
emptyList()
}
}
override suspend fun getAllFlights(): List<Flight> {
Log.d(RestFlightRepository::class.simpleName, "Get all flights")
val existFlights = dbFlightRepository.getAllFlights().associateBy { it.id }.toMutableMap() val existFlights = dbFlightRepository.getAllFlights().associateBy { it.id }.toMutableMap()
service.foundFlights() service.getAllFlights()
.map { it.toFlight() } .map { it.toFlight() }
.forEach { flight -> .forEach { flight ->
flight.direction_from == from || val existFlight = existFlights[flight.id]
flight.direction_to == to || if (existFlight == null) {
flight.departure_date == departureDate dbFlightRepository.insertFlight(flight)
} else if (existFlight != flight) {
dbFlightRepository.updateFlight(flight)
}
existFlights[flight.id] = flight existFlights[flight.id] = flight
} }
return existFlights.map { it.value }.sortedBy { it.id } return existFlights.map { it.value }.sortedBy { it.id }
} }
// flight.direction_from == from ||
// flight.direction_to == to ||
// flight.departure_date == departureDate
// override suspend fun findFlights( // override suspend fun findFlights(
// from: String, // from: String,

View File

@ -21,6 +21,7 @@ class RestRentRepository(
private val service: AppService, private val service: AppService,
private val dbRentRepository: OfflineRentRepository, private val dbRentRepository: OfflineRentRepository,
private val dbRemoteKeyRepository: OfflineRemoteKeyRepository, private val dbRemoteKeyRepository: OfflineRemoteKeyRepository,
private val userRestRepository: RestUserRepository,
private val ticketRestRepository: RestTicketRepository, private val ticketRestRepository: RestTicketRepository,
private val database: AppDatabase private val database: AppDatabase
) : RentRepository { ) : RentRepository {
@ -39,6 +40,7 @@ class RestRentRepository(
service, service,
dbRentRepository, dbRentRepository,
dbRemoteKeyRepository, dbRemoteKeyRepository,
userRestRepository,
ticketRestRepository, ticketRestRepository,
database database
), ),
@ -61,21 +63,21 @@ class RestRentRepository(
rent.id.let { service.deleteRent(it).toRent() } rent.id.let { service.deleteRent(it).toRent() }
} }
// override suspend fun getAllRents(): List<Rent> { override suspend fun getAllRents(): List<Rent> {
// val existRents = dbRentRepository.getAllRents().associateBy { it.id }.toMutableMap() val existRents = dbRentRepository.getAllRents().associateBy { it.id }.toMutableMap()
//
// service.getAllRents() service.getAllRents()
// .map { it.toRent() } .map { it.toRent() }
// .forEach { rent -> .forEach { rent ->
// val existRent = existRents[rent.id] val existRent = existRents[rent.id]
// if (existRent == null) { if (existRent == null) {
// dbRentRepository.insertRent(rent) dbRentRepository.insertRent(rent)
// } else if (existRent != rent) { } else if (existRent != rent) {
// dbRentRepository.updateRent(rent) dbRentRepository.updateRent(rent)
// } }
// existRents[rent.id] = rent existRents[rent.id] = rent
// } }
//
// return existRents.map { it.value }.sortedBy { it.id } return existRents.map { it.value }.sortedBy { it.id }
// } }
} }

View File

@ -2,9 +2,11 @@ package ru.ulstu.`is`.airticketrentservice.api.repository
import android.util.Log import android.util.Log
import ru.ulstu.`is`.airticketrentservice.api.AppService import ru.ulstu.`is`.airticketrentservice.api.AppService
import ru.ulstu.`is`.airticketrentservice.api.model.toFlight
import ru.ulstu.`is`.airticketrentservice.api.model.toRent import ru.ulstu.`is`.airticketrentservice.api.model.toRent
import ru.ulstu.`is`.airticketrentservice.api.model.toUser import ru.ulstu.`is`.airticketrentservice.api.model.toUser
import ru.ulstu.`is`.airticketrentservice.api.model.toUserRemote import ru.ulstu.`is`.airticketrentservice.api.model.toUserRemote
import ru.ulstu.`is`.airticketrentservice.database.models.Flight
import ru.ulstu.`is`.airticketrentservice.database.models.Rent import ru.ulstu.`is`.airticketrentservice.database.models.Rent
import ru.ulstu.`is`.airticketrentservice.database.models.User import ru.ulstu.`is`.airticketrentservice.database.models.User
import ru.ulstu.`is`.airticketrentservice.database.repository.OfflineRentRepository import ru.ulstu.`is`.airticketrentservice.database.repository.OfflineRentRepository
@ -56,26 +58,40 @@ class RestUserRepository(
return existUsers.map { it.value }.sortedBy { it.id } return existUsers.map { it.value }.sortedBy { it.id }
} }
override suspend fun getUserRents(id: Int): List<Rent> { // override suspend fun getUserRents(userId: Int): List<Rent> {
Log.d(RestUserRepository::class.simpleName, "Get users $id rents") // Log.d(RestUserRepository::class.simpleName, "Get user's $userId rents")
val existRents = dbUserRepository.getUserRents(id).associateBy { it.id }.toMutableMap() // 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 }
// }
service.getUserRents(id) override suspend fun getUserRents(userId: Int): List<Rent> {
.map { it.toRent() } return try {
.forEach { rent -> val usersRents = service.getUserRents(userId)
Log.d(RestUserRepository::class.simpleName, "айди брони: ${rent.id}, и пользователя: ${rent.userId}") if (usersRents.isNotEmpty()) {
if(rent.userId == id) { usersRents.map { it.toRent() }
val existRent = existRents[rent.id] } else {
if (existRent == null) { emptyList()
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 } } catch (e: Exception) {
e.message?.let { Log.d(RestUserRepository::class.simpleName, it) }
emptyList()
}
} }
} }

View File

@ -68,6 +68,7 @@ class AppDataContainer(private val context: Context) : AppContainer {
AppService.getInstance(), AppService.getInstance(),
rentRepository, rentRepository,
remoteKeyRepository, remoteKeyRepository,
userRestRepository,
ticketRestRepository, ticketRestRepository,
AppDatabase.getInstance(context) AppDatabase.getInstance(context)
) )

View File

@ -24,7 +24,7 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun remoteKeysDao(): RemoteKeysDao abstract fun remoteKeysDao(): RemoteKeysDao
companion object { companion object {
private const val DB_NAME: String = "ticketservicedatabase" private const val DB_NAME: String = "ticketservicedatabase5"
@Volatile @Volatile
private var INSTANCE: AppDatabase? = null private var INSTANCE: AppDatabase? = null

View File

@ -12,7 +12,7 @@ import ru.ulstu.`is`.airticketrentservice.database.models.Flight
@Dao @Dao
interface FlightDao { interface FlightDao {
@Query("select * from flights") @Query("select * from flights")
fun getAll(): List<Flight> suspend fun getAll(): List<Flight>
@Query("select * from flights where flights.id = :flightId") @Query("select * from flights where flights.id = :flightId")
fun getFlightById(flightId: Int): Flow<Flight> fun getFlightById(flightId: Int): Flow<Flight>

View File

@ -11,8 +11,8 @@ import ru.ulstu.`is`.airticketrentservice.database.models.Rent
@Dao @Dao
interface RentDao { interface RentDao {
// @Query("select * from rents") @Query("select * from rents")
// fun getAll(): List<Rent> fun getAll(): List<Rent>
@Query("select * from rents where rents.id = :rentId") @Query("select * from rents where rents.id = :rentId")
fun getRentById(rentId: Int): Flow<Rent> fun getRentById(rentId: Int): Flow<Rent>

View File

@ -3,6 +3,7 @@ package ru.ulstu.`is`.airticketrentservice.database.models
import androidx.room.ColumnInfo import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity
import androidx.room.ForeignKey import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
@Entity(tableName = "rents", @Entity(tableName = "rents",
@ -11,14 +12,17 @@ import androidx.room.PrimaryKey
entity = User::class, entity = User::class,
parentColumns = ["id"], parentColumns = ["id"],
childColumns = ["user_id"], childColumns = ["user_id"],
onDelete = ForeignKey.RESTRICT, onDelete = ForeignKey.CASCADE,
onUpdate = ForeignKey.RESTRICT), onUpdate = ForeignKey.CASCADE),
ForeignKey( ForeignKey(
entity = Ticket::class, entity = Ticket::class,
parentColumns = ["id"], parentColumns = ["id"],
childColumns = ["ticket_id"], childColumns = ["ticket_id"],
onDelete = ForeignKey.RESTRICT, onDelete = ForeignKey.CASCADE,
onUpdate = ForeignKey.RESTRICT) onUpdate = ForeignKey.CASCADE)
],
indices = [
Index(value = ["ticket_id"], unique = true)
]) ])
data class Rent( data class Rent(
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)

View File

@ -3,6 +3,7 @@ package ru.ulstu.`is`.airticketrentservice.database.models
import androidx.room.ColumnInfo import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity
import androidx.room.ForeignKey import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
@Entity(tableName = "tickets", @Entity(tableName = "tickets",

View File

@ -5,10 +5,11 @@ import kotlinx.coroutines.flow.Flow
import ru.ulstu.`is`.airticketrentservice.database.models.Flight import ru.ulstu.`is`.airticketrentservice.database.models.Flight
interface FlightRepository { interface FlightRepository {
suspend fun getAllFlights(): List<Flight>
suspend fun insertFlight(flight: Flight) suspend fun insertFlight(flight: Flight)
suspend fun updateFlight(flight: Flight) suspend fun updateFlight(flight: Flight)
suspend fun deleteFlight(flight: Flight) suspend fun deleteFlight(flight: Flight)
suspend fun getFlightById(flightId: Int): Flight suspend fun getFlightById(flightId: Int): Flight
suspend fun foundFlights(from: String, to: String, departureDate: String): List<Flight> suspend fun findFlights(from: String, to: String, departureDate: String): List<Flight>
fun getFlights(): Flow<PagingData<Flight>> fun getFlights(): Flow<PagingData<Flight>>
} }

View File

@ -11,7 +11,7 @@ import ru.ulstu.`is`.airticketrentservice.database.models.Flight
import ru.ulstu.`is`.airticketrentservice.database.models.Rent import ru.ulstu.`is`.airticketrentservice.database.models.Rent
class OfflineFlightRepository(private val flightDao: FlightDao) : FlightRepository{ class OfflineFlightRepository(private val flightDao: FlightDao) : FlightRepository{
suspend fun getAllFlights(): List<Flight> = flightDao.getAll() override suspend fun getAllFlights(): List<Flight> = flightDao.getAll()
override suspend fun insertFlight(flight: Flight) = flightDao.insert(flight) override suspend fun insertFlight(flight: Flight) = flightDao.insert(flight)
override suspend fun updateFlight(flight: Flight) = flightDao.update(flight) override suspend fun updateFlight(flight: Flight) = flightDao.update(flight)
override suspend fun deleteFlight(flight: Flight) = flightDao.delete(flight) override suspend fun deleteFlight(flight: Flight) = flightDao.delete(flight)
@ -25,7 +25,7 @@ class OfflineFlightRepository(private val flightDao: FlightDao) : FlightReposito
).flow ).flow
fun getAllFlightsPagingSource(): PagingSource<Int, Flight> = flightDao.getFlights() fun getAllFlightsPagingSource(): PagingSource<Int, Flight> = flightDao.getFlights()
override suspend fun foundFlights(from: String, to: String, departureDate: String): List<Flight> = flightDao.findFlights(from, to, departureDate) override suspend fun findFlights(from: String, to: String, departureDate: String): List<Flight> = flightDao.findFlights(from, to, departureDate)
suspend fun clearFlights() = flightDao.deleteAll() suspend fun clearFlights() = flightDao.deleteAll()
suspend fun insertFlights(flights: List<Flight>) = suspend fun insertFlights(flights: List<Flight>) =
flightDao.insert(*flights.toTypedArray()) flightDao.insert(*flights.toTypedArray())

View File

@ -14,7 +14,7 @@ class OfflineRentRepository(private val rentDao: RentDao) : RentRepository{
override suspend fun insertRent(rent: Rent) = rentDao.insert(rent) override suspend fun insertRent(rent: Rent) = rentDao.insert(rent)
override suspend fun updateRent(rent: Rent) = rentDao.update(rent) override suspend fun updateRent(rent: Rent) = rentDao.update(rent)
override suspend fun deleteRent(rent: Rent) = rentDao.delete(rent) override suspend fun deleteRent(rent: Rent) = rentDao.delete(rent)
// override suspend fun getAllRents(): List<Rent> = rentDao.getAll() override suspend fun getAllRents(): List<Rent> = rentDao.getAll()
override suspend fun getRentById(rentId: Int): Rent = rentDao.getRentById(rentId).first() override suspend fun getRentById(rentId: Int): Rent = rentDao.getRentById(rentId).first()
override fun getRents(): Flow<PagingData<Rent>> = Pager( override fun getRents(): Flow<PagingData<Rent>> = Pager(
config = PagingConfig( config = PagingConfig(

View File

@ -9,7 +9,7 @@ interface RentRepository {
suspend fun insertRent(rent: Rent) suspend fun insertRent(rent: Rent)
suspend fun updateRent(rent: Rent) suspend fun updateRent(rent: Rent)
suspend fun deleteRent(rent: Rent) suspend fun deleteRent(rent: Rent)
// suspend fun getAllRents(): List<Rent> suspend fun getAllRents(): List<Rent>
suspend fun getRentById(rentId: Int): Rent suspend fun getRentById(rentId: Int): Rent
fun getRents(): Flow<PagingData<Rent>> fun getRents(): Flow<PagingData<Rent>>
} }

View File

@ -9,5 +9,5 @@ interface UserRepository {
suspend fun deleteUser(user: User) suspend fun deleteUser(user: User)
suspend fun getAllUsers(): List<User> suspend fun getAllUsers(): List<User>
suspend fun getUserById(userId: Int): User suspend fun getUserById(userId: Int): User
suspend fun getUserRents(id: Int): List<Rent> suspend fun getUserRents(userId: Int): List<Rent>
} }

View File

@ -10,6 +10,7 @@ import androidx.navigation.navArgument
import ru.ulstu.`is`.airticketrentservice.navigation.BottomBarScreen import ru.ulstu.`is`.airticketrentservice.navigation.BottomBarScreen
import ru.ulstu.`is`.airticketrentservice.screen.Admin import ru.ulstu.`is`.airticketrentservice.screen.Admin
import ru.ulstu.`is`.airticketrentservice.screen.FlightEdit import ru.ulstu.`is`.airticketrentservice.screen.FlightEdit
import ru.ulstu.`is`.airticketrentservice.screen.FlightInfo
import ru.ulstu.`is`.airticketrentservice.screen.FlightList import ru.ulstu.`is`.airticketrentservice.screen.FlightList
import ru.ulstu.`is`.airticketrentservice.screen.FoundFlights import ru.ulstu.`is`.airticketrentservice.screen.FoundFlights
import ru.ulstu.`is`.airticketrentservice.screen.MainPage import ru.ulstu.`is`.airticketrentservice.screen.MainPage
@ -18,6 +19,8 @@ import ru.ulstu.`is`.airticketrentservice.screen.Profile
import ru.ulstu.`is`.airticketrentservice.screen.RentEdit import ru.ulstu.`is`.airticketrentservice.screen.RentEdit
import ru.ulstu.`is`.airticketrentservice.screen.RentList import ru.ulstu.`is`.airticketrentservice.screen.RentList
import ru.ulstu.`is`.airticketrentservice.screen.TicketEdit import ru.ulstu.`is`.airticketrentservice.screen.TicketEdit
import ru.ulstu.`is`.airticketrentservice.screen.TicketList
import ru.ulstu.`is`.airticketrentservice.screen.TicketView
import ru.ulstu.`is`.airticketrentservice.screen.UserEdit import ru.ulstu.`is`.airticketrentservice.screen.UserEdit
import ru.ulstu.`is`.airticketrentservice.screen.UserList import ru.ulstu.`is`.airticketrentservice.screen.UserList
import ru.ulstu.`is`.airticketrentservice.viewModel.AppViewModelProvider import ru.ulstu.`is`.airticketrentservice.viewModel.AppViewModelProvider
@ -61,12 +64,17 @@ fun HomeNavGraph(
composable( composable(
route = BottomBarScreen.UserList.route route = BottomBarScreen.UserList.route
){ ){
UserList(navController) UserList(navController, userListViewModel)
}
composable(
route = BottomBarScreen.TicketList.route
){
TicketList(navController, flightListViewModel, ticketListViewModel)
} }
composable( composable(
route = BottomBarScreen.RentList.route route = BottomBarScreen.RentList.route
){ ){
RentList(navController, rentListViewModel, ticketListViewModel) RentList(navController, userListViewModel, currentUserViewModel, ticketListViewModel, rentListViewModel)
} }
composable( composable(
route = BottomBarScreen.Admin.route route = BottomBarScreen.Admin.route
@ -113,6 +121,16 @@ fun HomeNavGraph(
){ ){
FlightEdit(navController) FlightEdit(navController)
} }
composable(
route = BottomBarScreen.FlightInfo.route,
arguments = listOf(
navArgument("id") {
type = NavType.IntType
}
)
){
FlightInfo(navController)
}
composable( composable(
route = BottomBarScreen.MyRents.route, route = BottomBarScreen.MyRents.route,
arguments = listOf( arguments = listOf(
@ -131,5 +149,13 @@ fun HomeNavGraph(
) { ) {
TicketEdit(navController) TicketEdit(navController)
} }
composable(
route = BottomBarScreen.TicketView.route,
arguments = listOf(
navArgument("id") { type = NavType.IntType }
)
) {
TicketView(navController)
}
} }
} }

View File

@ -14,6 +14,7 @@ import ru.ulstu.`is`.airticketrentservice.viewModel.FlightListViewModel
import ru.ulstu.`is`.airticketrentservice.viewModel.LoginViewModel import ru.ulstu.`is`.airticketrentservice.viewModel.LoginViewModel
import ru.ulstu.`is`.airticketrentservice.viewModel.RegistrationViewModel import ru.ulstu.`is`.airticketrentservice.viewModel.RegistrationViewModel
import ru.ulstu.`is`.airticketrentservice.viewModel.RentListViewModel import ru.ulstu.`is`.airticketrentservice.viewModel.RentListViewModel
import ru.ulstu.`is`.airticketrentservice.viewModel.TicketListViewModel
//import ru.ulstu.`is`.airticketrentservice.viewModel.TicketEditViewModel //import ru.ulstu.`is`.airticketrentservice.viewModel.TicketEditViewModel
import ru.ulstu.`is`.airticketrentservice.viewModel.UserListViewModel import ru.ulstu.`is`.airticketrentservice.viewModel.UserListViewModel
@ -22,11 +23,12 @@ const val USERID_ARGUMENT="userId"
@Composable @Composable
fun RootNavigationGraph( fun RootNavigationGraph(
navController: NavHostController, navController: NavHostController,
userListViewModel: UserListViewModel = viewModel(factory = AppViewModelProvider.Factory),
currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory), currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory),
registrationViewModel: RegistrationViewModel= viewModel(factory = AppViewModelProvider.Factory), registrationViewModel: RegistrationViewModel= viewModel(factory = AppViewModelProvider.Factory),
loginViewModel: LoginViewModel = viewModel(factory = AppViewModelProvider.Factory), loginViewModel: LoginViewModel = viewModel(factory = AppViewModelProvider.Factory),
flightListViewModel: FlightListViewModel = viewModel(factory = AppViewModelProvider.Factory), flightListViewModel: FlightListViewModel = viewModel(factory = AppViewModelProvider.Factory),
userListViewModel: UserListViewModel = viewModel(factory = AppViewModelProvider.Factory), ticketListViewModel: TicketListViewModel = viewModel(factory = AppViewModelProvider.Factory),
rentListViewModel: RentListViewModel = viewModel(factory = AppViewModelProvider.Factory) rentListViewModel: RentListViewModel = viewModel(factory = AppViewModelProvider.Factory)
){ ){
NavHost( NavHost(
@ -43,6 +45,7 @@ fun RootNavigationGraph(
currentUserViewModel = currentUserViewModel, currentUserViewModel = currentUserViewModel,
flightListViewModel = flightListViewModel, flightListViewModel = flightListViewModel,
userListViewModel = userListViewModel, userListViewModel = userListViewModel,
ticketListViewModel = ticketListViewModel,
rentListViewModel = rentListViewModel rentListViewModel = rentListViewModel
) )
} }

View File

@ -39,6 +39,11 @@ sealed class BottomBarScreen(
title ="", title ="",
icon = Icons.Filled.AccountCircle icon = Icons.Filled.AccountCircle
) )
object TicketList: BottomBarScreen(
route = "ticket-list",
title ="",
icon = Icons.Filled.AccountCircle
)
object RentList: BottomBarScreen( object RentList: BottomBarScreen(
route = "rent-list", route = "rent-list",
title ="", title ="",
@ -80,6 +85,15 @@ sealed class BottomBarScreen(
return "flight-edit/$id" return "flight-edit/$id"
} }
} }
object TicketView: BottomBarScreen(
route = "ticket-view/{id}",
title ="",
icon = Icons.Filled.AccountCircle
) {
fun passId(id: String): String{
return "ticket-view/$id"
}
}
object FlightInfo: BottomBarScreen( object FlightInfo: BottomBarScreen(
route = "flight-info/{id}", route = "flight-info/{id}",
title ="", title ="",

View File

@ -79,5 +79,22 @@ fun Admin (
) { ) {
Text("Бронирования") Text("Бронирования")
} }
Button(
onClick = { navController.navigate(BottomBarScreen.TicketList.route)},
colors = ButtonDefaults.buttonColors(
containerColor = (colorResource(id = R.color.lightBlue)),
contentColor = Color.White
),
elevation = ButtonDefaults.buttonElevation(
defaultElevation = 10.dp,
pressedElevation = 6.dp
),
shape = RoundedCornerShape(15.dp),
modifier = Modifier
.fillMaxWidth()
.padding(all = 10.dp),
) {
Text("Билеты")
}
} }
} }

View File

@ -40,12 +40,14 @@ import java.util.Date
@Composable @Composable
fun FlightInfo( fun FlightInfo(
navController: NavController, navController: NavController,
flightViewModel: FlightEditViewModel = viewModel(factory = AppViewModelProvider.Factory) flightViewModel: FlightEditViewModel = viewModel(factory = AppViewModelProvider.Factory),
ticketViewModel: TicketEditViewModel = viewModel(factory = AppViewModelProvider.Factory)
) { ) {
FlightInfo( FlightInfo(
flightUiState = flightViewModel.flightUiState, flightUiState = flightViewModel.flightUiState,
onClick = { onClick = {
val route = BottomBarScreen.TicketEdit.passId(0.toString()) flightViewModel.setCurrentFlight(ticketViewModel.ticketUiState.ticketDetails.flightId)
val route = BottomBarScreen.TicketView.passId(0.toString())
navController.navigate(route) navController.navigate(route)
} }
) )
@ -78,7 +80,8 @@ private fun FlightInfo(
), ),
shape = RoundedCornerShape(15.dp), shape = RoundedCornerShape(15.dp),
label = { Text(stringResource(id = R.string.ticket_from)) }, label = { Text(stringResource(id = R.string.ticket_from)) },
singleLine = true singleLine = true,
readOnly = true
) )
TextField( TextField(
modifier = Modifier modifier = Modifier
@ -93,12 +96,43 @@ private fun FlightInfo(
), ),
shape = RoundedCornerShape(15.dp), shape = RoundedCornerShape(15.dp),
label = { Text(stringResource(id = R.string.ticket_to)) }, label = { Text(stringResource(id = R.string.ticket_to)) },
singleLine = true singleLine = true,
readOnly = true
) )
Text(text = " ${flightUiState.flightDetails.departure_date}", fontSize = 15.sp, color = Color.DarkGray) TextField(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
value = flightUiState.flightDetails.departure_date,
onValueChange = { },
colors = TextFieldDefaults.textFieldColors(
containerColor = Color.LightGray.copy(.2f),
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent
),
shape = RoundedCornerShape(15.dp),
label = { Text(stringResource(id = R.string.ticket_arrivalDate)) },
singleLine = true,
readOnly = true
)
Text(text = flightUiState.flightDetails.arrival_date, fontSize = 15.sp, color = Color.DarkGray) TextField(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
value = flightUiState.flightDetails.arrival_date,
onValueChange = { },
colors = TextFieldDefaults.textFieldColors(
containerColor = Color.LightGray.copy(.2f),
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent
),
shape = RoundedCornerShape(15.dp),
label = { Text(stringResource(id = R.string.ticket_departureDate)) },
singleLine = true,
readOnly = true
)
TextField( TextField(
modifier = Modifier modifier = Modifier
@ -113,7 +147,8 @@ private fun FlightInfo(
), ),
shape = RoundedCornerShape(15.dp), shape = RoundedCornerShape(15.dp),
label = { Text("Количество билетов") }, label = { Text("Количество билетов") },
singleLine = true singleLine = true,
readOnly = true
) )
TextField( TextField(
@ -129,7 +164,8 @@ private fun FlightInfo(
), ),
shape = RoundedCornerShape(15.dp), shape = RoundedCornerShape(15.dp),
label = { Text("Стоимость одного билета") }, label = { Text("Стоимость одного билета") },
singleLine = true singleLine = true,
readOnly = true
) )
Button( Button(
onClick = onClick, onClick = onClick,

View File

@ -46,7 +46,7 @@ fun FoundFlights(
navController: NavController, navController: NavController,
viewModel: FindFlightsViewModel = viewModel(factory = AppViewModelProvider.Factory) viewModel: FindFlightsViewModel = viewModel(factory = AppViewModelProvider.Factory)
) { ) {
val foundFlightsUiState = viewModel.foundFlightsList val foundFlightsUiState = viewModel.foundFlightsUiState
Scaffold( Scaffold(
topBar = {} topBar = {}
@ -55,7 +55,7 @@ fun FoundFlights(
modifier = Modifier modifier = Modifier
.padding(innerPadding) .padding(innerPadding)
.fillMaxSize(), .fillMaxSize(),
flightList = foundFlightsUiState, flightList = foundFlightsUiState.flightList,
onClick = { uid: Int -> onClick = { uid: Int ->
val route = BottomBarScreen.FlightInfo.passId(uid.toString()) val route = BottomBarScreen.FlightInfo.passId(uid.toString())
navController.navigate(route) navController.navigate(route)

View File

@ -54,7 +54,6 @@ fun Profile(
currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory) currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory)
) { ) {
val getUser by remember { mutableStateOf(currentUserViewModel.user) } val getUser by remember { mutableStateOf(currentUserViewModel.user) }
val userUiState = getUser?.toUiState(true)
Log.d("CurrentUserViewModel1", "Текущий пользователь: $getUser") Log.d("CurrentUserViewModel1", "Текущий пользователь: $getUser")
val state = rememberScrollState() val state = rememberScrollState()
LaunchedEffect(Unit) { state.animateScrollTo(100) } LaunchedEffect(Unit) { state.animateScrollTo(100) }
@ -150,40 +149,40 @@ fun Profile(
Text("Изменить") Text("Изменить")
} }
) )
// Button( Button(
// modifier = Modifier modifier = Modifier
// .fillMaxWidth() .fillMaxWidth()
// .padding(5.dp), .padding(5.dp),
// onClick = { onClick = {
// val route = BottomBarScreen.MyRents.passId(getUser?.id.toString()) val route = BottomBarScreen.MyRents.passId(getUser?.id.toString())
// navController.navigate(route) navController.navigate(route)
// }, },
// elevation = ButtonDefaults.buttonElevation( elevation = ButtonDefaults.buttonElevation(
// defaultElevation = 10.dp, defaultElevation = 10.dp,
// pressedElevation = 6.dp pressedElevation = 6.dp
// ), ),
// shape = RoundedCornerShape(15.dp), shape = RoundedCornerShape(15.dp),
// colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.lightBlue)), colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.lightBlue)),
// content = { content = {
// Text("Мои бронирования") Text("Мои бронирования")
// } }
// ) )
// Button( Button(
// modifier = Modifier modifier = Modifier
// .fillMaxWidth() .fillMaxWidth()
// .padding(5.dp), .padding(5.dp),
// onClick = { onClick = {
// navController.navigate(AuthScreen.Login.route) navController.navigate(AuthScreen.Login.route)
// }, },
// elevation = ButtonDefaults.buttonElevation( elevation = ButtonDefaults.buttonElevation(
// defaultElevation = 10.dp, defaultElevation = 10.dp,
// pressedElevation = 6.dp pressedElevation = 6.dp
// ), ),
// shape = RoundedCornerShape(15.dp), shape = RoundedCornerShape(15.dp),
// colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.lightBlue)), colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.lightBlue)),
// content = { content = {
// Text("Выйти") Text("Выйти")
// } }
// ) )
} }
} }

View File

@ -88,11 +88,43 @@ private fun RentEdit(
.fillMaxWidth() .fillMaxWidth()
.padding(all = 10.dp) .padding(all = 10.dp)
) { ) {
TextField(
value = rentUiState.rentDetails.userId.toString(),
onValueChange = { onUpdate(rentUiState.rentDetails.copy(userId = it.toInt())) },
modifier = Modifier.fillMaxWidth().padding(all = 5.dp),
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.LightGray.copy(.2f),
unfocusedContainerColor = Color.LightGray.copy(.2f),
disabledContainerColor = Color.LightGray.copy(.2f),
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
),
shape = RoundedCornerShape(15.dp),
label = {
Text("Номер пользователя")
}
)
TextField(
value = rentUiState.rentDetails.ticketId.toString(),
onValueChange = { onUpdate(rentUiState.rentDetails.copy(ticketId = it.toInt())) },
modifier = Modifier.fillMaxWidth().padding(all = 5.dp),
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.LightGray.copy(.2f),
unfocusedContainerColor = Color.LightGray.copy(.2f),
disabledContainerColor = Color.LightGray.copy(.2f),
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
),
shape = RoundedCornerShape(15.dp),
label = {
Text("Номер билета")
}
)
TextField( TextField(
value = "${userUiState.userDetails.surname} ${userUiState.userDetails.name} ${userUiState.userDetails.patronymic}", value = "${userUiState.userDetails.surname} ${userUiState.userDetails.name} ${userUiState.userDetails.patronymic}",
onValueChange = {}, onValueChange = {},
readOnly = true, readOnly = true,
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth().padding(all = 5.dp),
colors = TextFieldDefaults.colors( colors = TextFieldDefaults.colors(
focusedContainerColor = Color.LightGray.copy(.2f), focusedContainerColor = Color.LightGray.copy(.2f),
unfocusedContainerColor = Color.LightGray.copy(.2f), unfocusedContainerColor = Color.LightGray.copy(.2f),
@ -110,7 +142,7 @@ private fun RentEdit(
value = "${ticketUiState.ticketDetails.ticket_cost}", value = "${ticketUiState.ticketDetails.ticket_cost}",
onValueChange = {}, onValueChange = {},
readOnly = true, readOnly = true,
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth().padding(all = 5.dp),
colors = TextFieldDefaults.colors( colors = TextFieldDefaults.colors(
focusedContainerColor = Color.LightGray.copy(.2f), focusedContainerColor = Color.LightGray.copy(.2f),
unfocusedContainerColor = Color.LightGray.copy(.2f), unfocusedContainerColor = Color.LightGray.copy(.2f),
@ -128,7 +160,7 @@ private fun RentEdit(
value = "${ticketUiState.ticketDetails.passengers_count}", value = "${ticketUiState.ticketDetails.passengers_count}",
onValueChange = {}, onValueChange = {},
readOnly = true, readOnly = true,
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth().padding(all = 5.dp),
colors = TextFieldDefaults.colors( colors = TextFieldDefaults.colors(
focusedContainerColor = Color.LightGray.copy(.2f), focusedContainerColor = Color.LightGray.copy(.2f),
unfocusedContainerColor = Color.LightGray.copy(.2f), unfocusedContainerColor = Color.LightGray.copy(.2f),
@ -141,91 +173,91 @@ private fun RentEdit(
Text("Количество пассажиров") Text("Количество пассажиров")
} }
) )
TextField(
value = "Ожидает подтверждения",
onValueChange = { onUpdate(rentUiState.rentDetails.copy(status = it)) },
readOnly = true,
modifier = Modifier.fillMaxWidth(),
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.LightGray.copy(.2f),
unfocusedContainerColor = Color.LightGray.copy(.2f),
disabledContainerColor = Color.LightGray.copy(.2f),
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
),
shape = RoundedCornerShape(15.dp),
label = {
Text(stringResource(id = R.string.rent_status))
}
)
// var expanded by remember { mutableStateOf(false) }
// //
// Box( // TextField(
// modifier = Modifier.fillMaxWidth().padding(all = 5.dp).clip(RoundedCornerShape(15.dp)) // value = "Ожидает подтверждения",
// ) { // onValueChange = { onUpdate(rentUiState.rentDetails.copy(status = it)) },
// ExposedDropdownMenuBox( // readOnly = true,
// modifier = Modifier.fillMaxWidth(), // modifier = Modifier.fillMaxWidth(),
// expanded = expanded, // colors = TextFieldDefaults.colors(
// onExpandedChange = { expanded = !expanded }, // focusedContainerColor = Color.LightGray.copy(.2f),
// ) // unfocusedContainerColor = Color.LightGray.copy(.2f),
// { // disabledContainerColor = Color.LightGray.copy(.2f),
// TextField( // focusedIndicatorColor = Color.Transparent,
// value = rentUiState.rentDetails.status, // unfocusedIndicatorColor = Color.Transparent,
// onValueChange = {}, // ),
// readOnly = true, // shape = RoundedCornerShape(15.dp),
// trailingIcon = { // label = {
// TrailingIcon(expanded = expanded) // Text(stringResource(id = R.string.rent_status))
// },
// modifier = Modifier.menuAnchor().fillMaxWidth(),
// colors = TextFieldDefaults.colors(
// focusedContainerColor = Color.LightGray.copy(.2f),
// unfocusedContainerColor = Color.LightGray.copy(.2f),
// disabledContainerColor = Color.LightGray.copy(.2f),
// focusedIndicatorColor = Color.Transparent,
// unfocusedIndicatorColor = Color.Transparent,
// ),
// shape = RoundedCornerShape(15.dp),
// label = {
// Text(stringResource(id = R.string.rent_status))
// }
// )
// ExposedDropdownMenu(
// expanded = expanded,
// onDismissRequest = { expanded = false },
// modifier = Modifier
// .background(Color.LightGray.copy(.2f))
// .exposedDropdownSize()
// .fillMaxWidth()
// ) {
// DropdownMenuItem(
// modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(15.dp)),
// text = { Text("Подтверждено") },
// onClick = {
// onUpdate(rentUiState.rentDetails.copy(status = "Подтверждено"))
// expanded = false
// }
// )
// DropdownMenuItem(
// modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(15.dp)),
// text = { Text("Ожидает подтверждения") },
// onClick = {
// onUpdate(rentUiState.rentDetails.copy(status = "Ожидает подтверждения"))
// expanded = false
// }
// )
// DropdownMenuItem(
// modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(15.dp)),
// text = { Text("Отклонено") },
// onClick = {
// onUpdate(rentUiState.rentDetails.copy(status = "Отклонено"))
// expanded = false
// }
// )
// }
// } // }
// } // )
var expanded by remember { mutableStateOf(false) }
Box(
modifier = Modifier.fillMaxWidth().padding(all = 5.dp).clip(RoundedCornerShape(15.dp))
) {
ExposedDropdownMenuBox(
modifier = Modifier.fillMaxWidth(),
expanded = expanded,
onExpandedChange = { expanded = !expanded },
)
{
TextField(
value = rentUiState.rentDetails.status,
onValueChange = {},
readOnly = true,
trailingIcon = {
TrailingIcon(expanded = expanded)
},
modifier = Modifier.menuAnchor().fillMaxWidth(),
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.LightGray.copy(.2f),
unfocusedContainerColor = Color.LightGray.copy(.2f),
disabledContainerColor = Color.LightGray.copy(.2f),
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
),
shape = RoundedCornerShape(15.dp),
label = {
Text(stringResource(id = R.string.rent_status))
}
)
ExposedDropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false },
modifier = Modifier
.background(Color.LightGray.copy(.2f))
.exposedDropdownSize()
.fillMaxWidth()
) {
DropdownMenuItem(
modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(15.dp)),
text = { Text("Подтверждено") },
onClick = {
onUpdate(rentUiState.rentDetails.copy(status = "Подтверждено"))
expanded = false
}
)
DropdownMenuItem(
modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(15.dp)),
text = { Text("Ожидает подтверждения") },
onClick = {
onUpdate(rentUiState.rentDetails.copy(status = "Ожидает подтверждения"))
expanded = false
}
)
DropdownMenuItem(
modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(15.dp)),
text = { Text("Отклонено") },
onClick = {
onUpdate(rentUiState.rentDetails.copy(status = "Отклонено"))
expanded = false
}
)
}
}
}
Button( Button(
enabled = rentUiState.isEntryValid, enabled = rentUiState.isEntryValid,

View File

@ -68,14 +68,18 @@ import kotlinx.coroutines.launch
import ru.ulstu.`is`.airticketrentservice.database.models.Rent import ru.ulstu.`is`.airticketrentservice.database.models.Rent
import ru.ulstu.`is`.airticketrentservice.navigation.BottomBarScreen import ru.ulstu.`is`.airticketrentservice.navigation.BottomBarScreen
import ru.ulstu.`is`.airticketrentservice.viewModel.AppViewModelProvider import ru.ulstu.`is`.airticketrentservice.viewModel.AppViewModelProvider
import ru.ulstu.`is`.airticketrentservice.viewModel.CurrentUserViewModel
import ru.ulstu.`is`.airticketrentservice.viewModel.RentListViewModel import ru.ulstu.`is`.airticketrentservice.viewModel.RentListViewModel
import ru.ulstu.`is`.airticketrentservice.viewModel.TicketListViewModel import ru.ulstu.`is`.airticketrentservice.viewModel.TicketListViewModel
import ru.ulstu.`is`.airticketrentservice.viewModel.UserListViewModel
@Composable @Composable
fun RentList( fun RentList(
navController: NavController, navController: NavController,
viewModel: RentListViewModel = viewModel(factory = AppViewModelProvider.Factory), userListViewModel: UserListViewModel = viewModel(factory = AppViewModelProvider.Factory),
ticketListViewModel: TicketListViewModel = viewModel(factory = AppViewModelProvider.Factory) currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory),
ticketListViewModel: TicketListViewModel = viewModel(factory = AppViewModelProvider.Factory),
viewModel: RentListViewModel = viewModel(factory = AppViewModelProvider.Factory)
) { ) {
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
val rentListUiState = viewModel.rentListUiState.collectAsLazyPagingItems() val rentListUiState = viewModel.rentListUiState.collectAsLazyPagingItems()

View File

@ -38,13 +38,14 @@ fun TicketEdit(
flightViewModel: FlightEditViewModel = viewModel(factory = AppViewModelProvider.Factory) flightViewModel: FlightEditViewModel = viewModel(factory = AppViewModelProvider.Factory)
) { ) {
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
flightViewModel.setCurrentFlight(viewModel.ticketUiState.ticketDetails.flightId)
TicketEdit( TicketEdit(
ticketUiState = viewModel.ticketUiState, ticketUiState = viewModel.ticketUiState,
flightUiState = flightViewModel.flightUiState, flightUiState = flightViewModel.flightUiState,
onClick = { onClick = {
coroutineScope.launch { coroutineScope.launch {
viewModel.saveTicket() viewModel.saveTicket()
navController.navigate(BottomBarScreen.RentEdit.passId(0.toString())) navController.popBackStack()
} }
}, },
onUpdate = viewModel::updateUiState, onUpdate = viewModel::updateUiState,
@ -70,6 +71,21 @@ private fun TicketEdit(
.padding(vertical = 32.dp), .padding(vertical = 32.dp),
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
TextField(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
value = ticketUiState.ticketDetails.flightId.toString(),
onValueChange = { onUpdate(ticketUiState.ticketDetails.copy(flightId = it.toInt())) },
colors = TextFieldDefaults.textFieldColors(
containerColor = Color.LightGray.copy(.2f),
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent
),
shape = RoundedCornerShape(15.dp),
label = { Text("Номер рейса") },
singleLine = true
)
TextField( TextField(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -106,33 +122,16 @@ private fun TicketEdit(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(10.dp), .padding(10.dp),
value = flightUiState.flightDetails.departure_date, value = ticketUiState.ticketDetails.passengers_count.toString(),
onValueChange = {}, onValueChange = { onUpdate(ticketUiState.ticketDetails.copy(passengers_count = it.toInt())) },
colors = TextFieldDefaults.textFieldColors( colors = TextFieldDefaults.textFieldColors(
containerColor = Color.LightGray.copy(.2f), containerColor = Color.LightGray.copy(.2f),
unfocusedIndicatorColor = Color.Transparent, unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent focusedIndicatorColor = Color.Transparent
), ),
shape = RoundedCornerShape(15.dp), shape = RoundedCornerShape(15.dp),
label = { Text(stringResource(id = R.string.ticket_arrivalDate)) }, label = { Text("Количество пассажиров") },
singleLine = true, singleLine = true
readOnly = true
)
TextField(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
value = flightUiState.flightDetails.arrival_date,
onValueChange = {},
colors = TextFieldDefaults.textFieldColors(
containerColor = Color.LightGray.copy(.2f),
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent
),
shape = RoundedCornerShape(15.dp),
label = { Text(stringResource(id = R.string.ticket_departureDate)) },
singleLine = true,
readOnly = true
) )
TextField( TextField(
modifier = Modifier modifier = Modifier
@ -150,21 +149,6 @@ private fun TicketEdit(
singleLine = true, singleLine = true,
readOnly = true readOnly = true
) )
TextField(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
value = ticketUiState.ticketDetails.passengers_count.toString(),
onValueChange = { onUpdate(ticketUiState.ticketDetails.copy(passengers_count = it.toInt())) },
colors = TextFieldDefaults.textFieldColors(
containerColor = Color.LightGray.copy(.2f),
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent
),
shape = RoundedCornerShape(15.dp),
label = { Text("Количество пассажиров") },
singleLine = true
)
// TextField( // TextField(
// modifier = Modifier // modifier = Modifier
// .fillMaxWidth() // .fillMaxWidth()
@ -192,7 +176,7 @@ private fun TicketEdit(
colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.lightBlue)), colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.lightBlue)),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
Text(text = "Забронировать") Text(text = "Сохранить")
} }
} }
} }

View File

@ -51,7 +51,6 @@ fun UserEdit(
onClick = { onClick = {
coroutineScope.launch { coroutineScope.launch {
viewModel.saveUser() viewModel.saveUser()
currentUserViewModel.user = viewModel.userUiState.user
navController.popBackStack() navController.popBackStack()
} }
}, },

View File

@ -6,11 +6,13 @@ import androidx.compose.runtime.setValue
import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import ru.ulstu.`is`.airticketrentservice.api.AppService import ru.ulstu.`is`.airticketrentservice.api.AppService
import ru.ulstu.`is`.airticketrentservice.api.model.toFlight import ru.ulstu.`is`.airticketrentservice.api.model.toFlight
import ru.ulstu.`is`.airticketrentservice.database.AppContainer import ru.ulstu.`is`.airticketrentservice.database.AppContainer
@ -19,30 +21,29 @@ import ru.ulstu.`is`.airticketrentservice.database.repository.FlightRepository
class FindFlightsViewModel( class FindFlightsViewModel(
savedStateHandle: SavedStateHandle, savedStateHandle: SavedStateHandle,
private val flightRepository: FlightRepository, private val flightRepository: FlightRepository
) : ViewModel() { ) : ViewModel() {
private val from: String = checkNotNull(savedStateHandle["direction_from"]) private val from: String = checkNotNull(savedStateHandle["direction_from"])
private val to: String = checkNotNull(savedStateHandle["direction_to"]) private val to: String = checkNotNull(savedStateHandle["direction_to"])
private val departureDate: String = checkNotNull(savedStateHandle["departure_date"]) private val departureDate: String = checkNotNull(savedStateHandle["departure_date"])
// private val appService: AppService
// get() {
// return AppService
// }
var foundFlightsList: List<Flight> by mutableStateOf(emptyList())
private set
var foundFlightsUiState by mutableStateOf(FoundFlightsUiState()) var foundFlightsUiState by mutableStateOf(FoundFlightsUiState())
private set private set
init { init {
viewModelScope.launch { viewModelScope.launch {
//foundFlightsList = appService.foundFlights().map { it.toFlight() } withContext(Dispatchers.IO) {
foundFlightsUiState = FoundFlightsUiState(flightRepository.foundFlights(from, to, departureDate)) val flights = flightRepository.findFlights(from, to, departureDate)
launch(Dispatchers.Main) {
foundFlightsUiState = FoundFlightsUiState(flights)
}
}
} }
} }
} }
data class FoundFlightsUiState(val flightList: List<Flight> = listOf()) data class FoundFlightsUiState(val flightList: List<Flight> = listOf())
// var foundFlightsList: List<Flight> by mutableStateOf(emptyList())
// private set
//foundFlightsList = appService.foundFlights().map { it.toFlight() }

View File

@ -17,6 +17,9 @@ class FlightEditViewModel(
private val flightRepository: FlightRepository private val flightRepository: FlightRepository
) : ViewModel() { ) : ViewModel() {
var flightsListUiState by mutableStateOf(FlightsListUiState())
private set
var flightUiState by mutableStateOf(FlightUiState()) var flightUiState by mutableStateOf(FlightUiState())
private set private set
@ -25,16 +28,23 @@ class FlightEditViewModel(
init { init {
viewModelScope.launch { viewModelScope.launch {
if (flightUid > 0) { if (flightUid > 0) {
flightsListUiState = FlightsListUiState(flightRepository.getAllFlights())
flightUiState = flightRepository.getFlightById(flightUid) flightUiState = flightRepository.getFlightById(flightUid)
.toUiState(true) .toUiState(true)
} }
} }
} }
fun setCurrentFlight(flightId: Int) {
val flight: Flight? = flightsListUiState.flightList.firstOrNull { flight -> flight.id == flightId }
flight?.let { updateUiState(it.toDetails()) }
}
fun updateUiState(flightDetails: FlightDetails) { fun updateUiState(flightDetails: FlightDetails) {
flightUiState = FlightUiState( flightUiState = FlightUiState(
flightDetails = flightDetails, flightDetails = flightDetails,
isEntryValid = validateInput(flightDetails) isEntryValid = validateInput(flightDetails),
flight = flightDetails.toFlight()
) )
} }
@ -66,7 +76,8 @@ class FlightEditViewModel(
data class FlightUiState( data class FlightUiState(
val flightDetails: FlightDetails = FlightDetails(), val flightDetails: FlightDetails = FlightDetails(),
val isEntryValid: Boolean = false val isEntryValid: Boolean = false,
val flight: Flight? = null
) )
data class FlightDetails( data class FlightDetails(
@ -102,3 +113,6 @@ fun Flight.toUiState(isEntryValid: Boolean = false): FlightUiState = FlightUiSta
isEntryValid = isEntryValid isEntryValid = isEntryValid
) )
data class FlightsListUiState(val flightList: List<Flight> = listOf())

View File

@ -12,28 +12,8 @@ class FlightListViewModel(
private val flightRepository: FlightRepository private val flightRepository: FlightRepository
): ViewModel() { ): ViewModel() {
//val foundFlightsUiState: Flow<PagingData<Flight>> = flightRepository.findPagingFlights(from, to, departureDate)
var flightsListUiState: Flow<PagingData<Flight>> = flightRepository.getFlights() var flightsListUiState: Flow<PagingData<Flight>> = flightRepository.getFlights()
// val flightListUiState: StateFlow<FlightListUiState> = flightRepository.getAllFlights().map {
// FlightListUiState(it)
// }.stateIn(
// scope = viewModelScope,
// started = SharingStarted.WhileSubscribed(stopTimeoutMillis = AppContainer.TIMEOUT),
// initialValue = FlightListUiState()
// )
// val _searchResults = MutableStateFlow<PagingData<Flight>>(PagingData.empty())
// val searchResults: MutableStateFlow<PagingData<Flight>> = _searchResults
//
// fun searchFlights(from: String, to: String, departureDate: String) {
// viewModelScope.launch {
// val results = flightRepository.findPagingFlights(from, to, departureDate).single()
// _searchResults.value = results
// }
// }
fun deleteFlight(flight: Flight) = viewModelScope.launch { fun deleteFlight(flight: Flight) = viewModelScope.launch {
flightRepository.deleteFlight(flight) flightRepository.deleteFlight(flight)
} }

View File

@ -9,6 +9,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import ru.ulstu.`is`.airticketrentservice.database.models.Rent import ru.ulstu.`is`.airticketrentservice.database.models.Rent
import ru.ulstu.`is`.airticketrentservice.database.repository.RentRepository import ru.ulstu.`is`.airticketrentservice.database.repository.RentRepository
@ -23,9 +24,15 @@ class RentEditViewModel(
init { init {
viewModelScope.launch { viewModelScope.launch {
if (rentUid > 0) { withContext(Dispatchers.IO) {
rentUiState = rentRepository.getRentById(rentUid) val rent = rentRepository.getRentById(rentUid)
.toUiState(true) .toUiState(true)
launch(Dispatchers.Main) {
if (rentUid > 0) {
rentUiState = rent
}
}
} }
} }
} }

View File

@ -6,7 +6,9 @@ import androidx.compose.runtime.setValue
import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import ru.ulstu.`is`.airticketrentservice.database.models.Ticket import ru.ulstu.`is`.airticketrentservice.database.models.Ticket
import ru.ulstu.`is`.airticketrentservice.database.repository.TicketRepository import ru.ulstu.`is`.airticketrentservice.database.repository.TicketRepository
@ -25,30 +27,41 @@ class TicketEditViewModel(
init { init {
viewModelScope.launch { viewModelScope.launch {
ticketsListUiState = TicketsListUiState(ticketRepository.getAllTickets()) withContext(Dispatchers.IO) {
if (ticketUid > 0) { val tickets = ticketRepository.getAllTickets()
ticketUiState = ticketRepository.getTicketById(ticketUid) val ticket = ticketRepository.getTicketById(ticketUid)
.toUiState(true) .toUiState(true)
launch(Dispatchers.Main) {
if (ticketUid > 0) {
ticketsListUiState = TicketsListUiState(tickets)
ticketUiState = ticket
}
}
} }
} }
} }
// init {
// viewModelScope.launch {
// if (ticketUid > 0) {
// ticketsListUiState = TicketsListUiState(ticketRepository.getAllTickets())
// ticketUiState = ticketRepository.getTicketById(ticketUid)
// .toUiState(true)
// }
// }
// }
fun setCurrentTicket(ticketId: Int) { fun setCurrentTicket(ticketId: Int) {
val ticket: Ticket? = val ticket: Ticket? =
ticketsListUiState.ticketList.firstOrNull { ticket -> ticket.id == ticketId } ticketsListUiState.ticketList.firstOrNull { ticket -> ticket.id == ticketId }
ticket?.let { updateTicketUiState(it) } ticket?.let { updateUiState(it.toDetails()) }
}
fun updateTicketUiState(ticket: Ticket) {
ticketUiState = TicketUiState(
ticket = ticket
)
} }
fun updateUiState(ticketDetails: TicketDetails) { fun updateUiState(ticketDetails: TicketDetails) {
ticketUiState = TicketUiState( ticketUiState = TicketUiState(
ticketDetails = ticketDetails, ticketDetails = ticketDetails,
isEntryValid = validateInput(ticketDetails) isEntryValid = validateInput(ticketDetails),
ticket = ticketDetails.toTicket()
) )
} }
@ -84,7 +97,7 @@ data class TicketUiState(
data class TicketDetails( data class TicketDetails(
val passengers_count: Int = 0, val passengers_count: Int = 0,
var ticket_cost: Double = 0.0, var ticket_cost: Double = 0.0,
var flightId: Int = 0, var flightId: Int = 0
) )
fun TicketDetails.toTicket(uid: Int = 0): Ticket = Ticket( fun TicketDetails.toTicket(uid: Int = 0): Ticket = Ticket(

View File

@ -10,23 +10,11 @@ import kotlinx.coroutines.launch
import ru.ulstu.`is`.airticketrentservice.database.models.Ticket import ru.ulstu.`is`.airticketrentservice.database.models.Ticket
import ru.ulstu.`is`.airticketrentservice.database.repository.TicketRepository import ru.ulstu.`is`.airticketrentservice.database.repository.TicketRepository
class TicketListViewModel(private val ticketRepository: TicketRepository): ViewModel() { class TicketListViewModel(
val ticketListUiState: Flow<PagingData<Ticket>> = ticketRepository.getTickets() private val ticketRepository: TicketRepository
): ViewModel() {
// private var userId: Int = 0 val ticketListUiState: Flow<PagingData<Ticket>> = ticketRepository.getTickets()
// 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 deleteTicket(ticket: Ticket) { suspend fun deleteTicket(ticket: Ticket) {
ticketRepository.deleteTicket(ticket) ticketRepository.deleteTicket(ticket)

View File

@ -27,8 +27,8 @@ class UserEditViewModel(
init { init {
viewModelScope.launch { viewModelScope.launch {
usersListUiState = UsersListUiState(userRepository.getAllUsers())
if (userUid > 0) { if (userUid > 0) {
usersListUiState = UsersListUiState(userRepository.getAllUsers())
userUiState = userRepository.getUserById(userUid) userUiState = userRepository.getUserById(userUid)
.toUiState(true)!! .toUiState(true)!!
} }
@ -38,19 +38,14 @@ class UserEditViewModel(
fun setCurrentUser(userId: Int) { fun setCurrentUser(userId: Int) {
val user: User? = val user: User? =
usersListUiState.userList.firstOrNull { user -> user.id == userId } usersListUiState.userList.firstOrNull { user -> user.id == userId }
user?.let { updateUserUiState(it) } user?.let { it.toDetails()?.let { it1 -> updateUiState(it1) } }
}
fun updateUserUiState(user: User) {
userUiState = UserUiState(
user = user
)
} }
fun updateUiState(userDetails: UserDetails) { fun updateUiState(userDetails: UserDetails) {
userUiState = UserUiState( userUiState = UserUiState(
userDetails = userDetails, userDetails = userDetails,
isEntryValid = validateInput(userDetails) isEntryValid = validateInput(userDetails),
user = userDetails.toUser()
) )
} }

View File

@ -6,7 +6,9 @@ import androidx.compose.runtime.setValue
import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import ru.ulstu.`is`.airticketrentservice.database.models.Rent import ru.ulstu.`is`.airticketrentservice.database.models.Rent
import ru.ulstu.`is`.airticketrentservice.database.repository.RentRepository import ru.ulstu.`is`.airticketrentservice.database.repository.RentRepository
import ru.ulstu.`is`.airticketrentservice.database.repository.UserRepository import ru.ulstu.`is`.airticketrentservice.database.repository.UserRepository
@ -24,8 +26,13 @@ class UsersRentsViewModel(
init { init {
viewModelScope.launch { viewModelScope.launch {
if (userUid > 0) { withContext(Dispatchers.IO) {
userRentsUiState = UserRentsUiState(userRepository.getUserRents(userUid)) val rents = userRepository.getUserRents(userUid)
launch(Dispatchers.Main) {
if (userUid > 0) {
userRentsUiState = UserRentsUiState(rents)
}
}
} }
} }
} }

View File

@ -3,11 +3,17 @@
{ {
"id": 1, "id": 1,
"passengers_count": 1, "passengers_count": 1,
"ticket_cost": 1000, "ticket_cost": 2680,
"flightId": 2 "flightId": 6
},
{
"id": 2,
"passengers_count": 1,
"ticket_cost": 2435,
"flightId": 5
} }
], ],
"searchFlights": [ "flights": [
{ {
"id": 2, "id": 2,
"direction_from": "a", "direction_from": "a",
@ -18,7 +24,7 @@
"one_ticket_cost": 1000 "one_ticket_cost": 1000
}, },
{ {
"direction_from": "Санкт-Петербург ", "direction_from": "Санкт-Петербург",
"direction_to": "Сочи", "direction_to": "Сочи",
"departure_date": "17-12-2023", "departure_date": "17-12-2023",
"arrival_date": "17-12-2023", "arrival_date": "17-12-2023",
@ -28,17 +34,15 @@
}, },
{ {
"id": 6, "id": 6,
"direction_from": "Ульяновск ", "direction_from": "Ульяновск",
"direction_to": "Москва ", "direction_to": "Москва ",
"departure_date": "26-12-2023", "departure_date": "26-12-2023",
"arrival_date": "26-12-2023", "arrival_date": "26-12-2023",
"tickets_count": 50, "tickets_count": 50,
"one_ticket_cost": 2680 "one_ticket_cost": 2680
} },
],
"flights": [
{ {
"direction_from": "Хабаровск ", "direction_from": "Хабаровск",
"direction_to": "Кострома ", "direction_to": "Кострома ",
"departure_date": "5-1-2024", "departure_date": "5-1-2024",
"arrival_date": "5-1-2024", "arrival_date": "5-1-2024",
@ -47,7 +51,7 @@
"id": 7 "id": 7
}, },
{ {
"direction_from": "Астрахань ", "direction_from": "Астрахань",
"direction_to": "Нижний Новгород", "direction_to": "Нижний Новгород",
"departure_date": "28-1-2024", "departure_date": "28-1-2024",
"arrival_date": "28-1-2024", "arrival_date": "28-1-2024",
@ -79,7 +83,7 @@
"id": 2, "id": 2,
"surname": "Артамонова", "surname": "Артамонова",
"name": "Татьяна", "name": "Татьяна",
"patronymic": "Валерьевна", "patronymic": "Валерьевн",
"date_of_birth": "7-11-2003", "date_of_birth": "7-11-2003",
"email": "usertt@mail.ru", "email": "usertt@mail.ru",
"password": "usertt", "password": "usertt",
@ -142,6 +146,12 @@
"status": "Ожидает подтверждения", "status": "Ожидает подтверждения",
"userId": 2, "userId": 2,
"ticketId": 1 "ticketId": 1
},
{
"id": 2,
"status": "Подтверждено",
"userId": 2,
"ticketId": 2
} }
] ]
} }

View File

@ -3,11 +3,17 @@
{ {
"id": 1, "id": 1,
"passengers_count": 1, "passengers_count": 1,
"ticket_cost": 1000, "ticket_cost": 2680,
"flightId": 2 "flightId": 6
},
{
"id": 2,
"passengers_count": 1,
"ticket_cost": 2435,
"flightId": 5
} }
], ],
"foundFlights": [ "flights": [
{ {
"id": 2, "id": 2,
"direction_from": "a", "direction_from": "a",
@ -18,7 +24,7 @@
"one_ticket_cost": 1000 "one_ticket_cost": 1000
}, },
{ {
"direction_from": "Санкт-Петербург ", "direction_from": "Санкт-Петербург",
"direction_to": "Сочи", "direction_to": "Сочи",
"departure_date": "17-12-2023", "departure_date": "17-12-2023",
"arrival_date": "17-12-2023", "arrival_date": "17-12-2023",
@ -28,17 +34,15 @@
}, },
{ {
"id": 6, "id": 6,
"direction_from": "Ульяновск ", "direction_from": "Ульяновск",
"direction_to": "Москва ", "direction_to": "Москва ",
"departure_date": "26-12-2023", "departure_date": "26-12-2023",
"arrival_date": "26-12-2023", "arrival_date": "26-12-2023",
"tickets_count": 50, "tickets_count": 50,
"one_ticket_cost": 2680 "one_ticket_cost": 2680
} },
],
"flights": [
{ {
"direction_from": "Хабаровск ", "direction_from": "Хабаровск",
"direction_to": "Кострома ", "direction_to": "Кострома ",
"departure_date": "5-1-2024", "departure_date": "5-1-2024",
"arrival_date": "5-1-2024", "arrival_date": "5-1-2024",
@ -47,7 +51,7 @@
"id": 7 "id": 7
}, },
{ {
"direction_from": "Астрахань ", "direction_from": "Астрахань",
"direction_to": "Нижний Новгород", "direction_to": "Нижний Новгород",
"departure_date": "28-1-2024", "departure_date": "28-1-2024",
"arrival_date": "28-1-2024", "arrival_date": "28-1-2024",
@ -137,11 +141,17 @@
} }
], ],
"rents": [ "rents": [
{ {
"id": 1, "id": 1,
"status": "Ожидает подтверждения", "status": "Ожидает подтверждения",
"userId": 2, "userId": 2,
"ticketId": 1 "ticketId": 1
} },
{
"id": 2,
"status": "Подтверждено",
"userId": 2,
"ticketId": 2
}
] ]
} }