Compare commits
No commits in common. "f67c6d76befdefde32f59c813f45c50fb09b4e1b" and "02b3e891a683f9213a04074971647657b532b5c5" have entirely different histories.
f67c6d76be
...
02b3e891a6
@ -1,7 +1,6 @@
|
||||
package ru.ulstu.`is`.airticketrentservice
|
||||
|
||||
import android.app.Application
|
||||
import ru.ulstu.`is`.airticketrentservice.api.AppService
|
||||
import ru.ulstu.`is`.airticketrentservice.database.AppContainer
|
||||
import ru.ulstu.`is`.airticketrentservice.database.AppDataContainer
|
||||
|
||||
|
@ -28,19 +28,14 @@ interface AppService {
|
||||
@Query("_page") page: Int,
|
||||
@Query("_limit") limit: Int,
|
||||
): List<RentRemote>
|
||||
@GET("searchFlights")
|
||||
suspend fun foundFlights(
|
||||
@GET("findFlights/{direction_from}-{direction_to}-{departure_date}")
|
||||
suspend fun findFlights(
|
||||
@Path("direction_from") from: String,
|
||||
@Path("direction_to") to: String,
|
||||
@Path("departure_date") departureDate: String
|
||||
): List<FlightRemote>
|
||||
// suspend fun findFlights(
|
||||
// @Path("direction_from") from: String,
|
||||
// @Path("direction_to") to: String,
|
||||
// @Path("departure_date") departureDate: String
|
||||
// ): List<FlightRemote>
|
||||
@GET("tickets")
|
||||
suspend fun getAllTickets(): List<TicketRemote>
|
||||
|
||||
@GET("foundFlights")
|
||||
suspend fun getAllFlights(): List<FlightRemote>
|
||||
@GET("tickets")
|
||||
suspend fun getTickets(
|
||||
@Query("_page") page: Int,
|
||||
@ -131,7 +126,7 @@ interface AppService {
|
||||
@Path("id") id: Int,
|
||||
): TicketRemote
|
||||
|
||||
companion object : AppService {
|
||||
companion object {
|
||||
private const val BASE_URL = "http://192.168.1.100:8079/"
|
||||
|
||||
@Volatile
|
||||
|
@ -1,9 +1,7 @@
|
||||
package ru.ulstu.`is`.airticketrentservice.api.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import ru.ulstu.`is`.airticketrentservice.database.models.Flight
|
||||
import java.io.File
|
||||
|
||||
@Serializable
|
||||
data class FlightRemote(
|
||||
@ -35,21 +33,3 @@ fun Flight.toFlightRemote(): FlightRemote = FlightRemote(
|
||||
tickets_count,
|
||||
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
|
||||
}
|
@ -14,7 +14,6 @@ import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.serialization.json.Json
|
||||
import ru.ulstu.`is`.airticketrentservice.api.AppService
|
||||
import ru.ulstu.`is`.airticketrentservice.api.model.toFlight
|
||||
import ru.ulstu.`is`.airticketrentservice.api.model.toFlightRemote
|
||||
@ -26,7 +25,6 @@ import ru.ulstu.`is`.airticketrentservice.database.repository.FlightRepository
|
||||
import ru.ulstu.`is`.airticketrentservice.database.repository.OfflineRemoteKeyRepository
|
||||
import ru.ulstu.`is`.airticketrentservice.api.mediator.FlightRemoteMediator
|
||||
import ru.ulstu.`is`.airticketrentservice.api.model.FlightRemote
|
||||
import java.io.File
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.resumeWithException
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
@ -61,45 +59,50 @@ class RestFlightRepository(
|
||||
override suspend fun getFlightById(flightId: Int): Flight =
|
||||
service.getFlight(flightId).toFlight()
|
||||
|
||||
override suspend fun foundFlights(
|
||||
from: String,
|
||||
to: String,
|
||||
departureDate: String
|
||||
): List<Flight> {
|
||||
|
||||
val existFlights = dbFlightRepository.getAllFlights().associateBy { it.id }.toMutableMap()
|
||||
|
||||
service.foundFlights()
|
||||
.map { it.toFlight() }
|
||||
.forEach { flight ->
|
||||
flight.direction_from == from ||
|
||||
flight.direction_to == to ||
|
||||
flight.departure_date == departureDate
|
||||
existFlights[flight.id] = flight
|
||||
}
|
||||
|
||||
return existFlights.map { it.value }.sortedBy { it.id }
|
||||
|
||||
}
|
||||
|
||||
// override suspend fun findFlights(
|
||||
// from: String,
|
||||
// to: String,
|
||||
// departureDate: String
|
||||
// ): List<Flight> {
|
||||
// Log.d(RestFlightRepository::class.simpleName, "Find flights")
|
||||
//
|
||||
//
|
||||
// val existFlights = dbFlightRepository.findFlights(from, to, departureDate).associateBy { it.id }.toMutableMap()
|
||||
//
|
||||
// service.findFlights(from, to, departureDate)
|
||||
// .map { it.toFlight() }
|
||||
// .forEach { flight ->
|
||||
// existFlights[flight.id] = flight
|
||||
// ): List<Flight> = suspendCancellableCoroutine { continuation ->
|
||||
// val call = service.findFlights(from, to, departureDate)
|
||||
// call.enqueue(object: Callback<List<FlightRemote>> {
|
||||
// override fun onResponse(call: Call<List<FlightRemote>>, response: Response<List<FlightRemote>>) {
|
||||
// if (response.isSuccessful) {
|
||||
// val flightRemoteList = response.body() ?: emptyList()
|
||||
// val flightList = flightRemoteList.map { it.toFlight() }
|
||||
// continuation.resume(flightList)
|
||||
// } else {
|
||||
// continuation.resumeWithException(Exception("Server error: ${response.code()}"))
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return existFlights.map { it.value }.sortedBy { it.id }
|
||||
// override fun onFailure(call: Call<List<FlightRemote>>, t: Throwable) {
|
||||
// continuation.resumeWithException(t)
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// continuation.invokeOnCancellation {
|
||||
// call.cancel()
|
||||
// }
|
||||
// }
|
||||
|
||||
override suspend fun findFlights(
|
||||
from: String,
|
||||
to: String,
|
||||
departureDate: String
|
||||
): List<Flight> {
|
||||
Log.d(RestFlightRepository::class.simpleName, "Find flights")
|
||||
|
||||
val existFlights = dbFlightRepository.findFlights(from, to, departureDate).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 insertFlight(flight: Flight) {
|
||||
service.createFlight(flight.toFlightRemote()).toFlight()
|
||||
|
@ -9,6 +9,6 @@ interface FlightRepository {
|
||||
suspend fun updateFlight(flight: Flight)
|
||||
suspend fun deleteFlight(flight: 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>>
|
||||
}
|
@ -11,7 +11,6 @@ import ru.ulstu.`is`.airticketrentservice.database.models.Flight
|
||||
import ru.ulstu.`is`.airticketrentservice.database.models.Rent
|
||||
|
||||
class OfflineFlightRepository(private val flightDao: FlightDao) : FlightRepository{
|
||||
suspend fun getAllFlights(): List<Flight> = flightDao.getAll()
|
||||
override suspend fun insertFlight(flight: Flight) = flightDao.insert(flight)
|
||||
override suspend fun updateFlight(flight: Flight) = flightDao.update(flight)
|
||||
override suspend fun deleteFlight(flight: Flight) = flightDao.delete(flight)
|
||||
@ -25,7 +24,7 @@ class OfflineFlightRepository(private val flightDao: FlightDao) : FlightReposito
|
||||
).flow
|
||||
|
||||
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 insertFlights(flights: List<Flight>) =
|
||||
flightDao.insert(*flights.toTypedArray())
|
||||
|
@ -45,23 +45,6 @@ fun Admin (
|
||||
) {
|
||||
Text("Рейсы")
|
||||
}
|
||||
Button(
|
||||
onClick = { navController.navigate(BottomBarScreen.UserList.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("Пользователи")
|
||||
}
|
||||
Button(
|
||||
onClick = { navController.navigate(BottomBarScreen.RentList.route)},
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
@ -79,5 +62,22 @@ fun Admin (
|
||||
) {
|
||||
Text("Бронирования")
|
||||
}
|
||||
Button(
|
||||
onClick = { navController.navigate(BottomBarScreen.UserList.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("Пользователи")
|
||||
}
|
||||
}
|
||||
}
|
@ -40,13 +40,14 @@ import ru.ulstu.`is`.airticketrentservice.database.models.Flight
|
||||
import ru.ulstu.`is`.airticketrentservice.navigation.BottomBarScreen
|
||||
import ru.ulstu.`is`.airticketrentservice.viewModel.AppViewModelProvider
|
||||
import ru.ulstu.`is`.airticketrentservice.viewModel.FindFlightsViewModel
|
||||
import ru.ulstu.`is`.airticketrentservice.viewModel.FoundFlightsUiState
|
||||
|
||||
@Composable
|
||||
fun FoundFlights(
|
||||
navController: NavController,
|
||||
viewModel: FindFlightsViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
||||
) {
|
||||
val foundFlightsUiState = viewModel.foundFlightsList
|
||||
val foundFlightsUiState = viewModel.foundFlightsUiState
|
||||
|
||||
Scaffold(
|
||||
topBar = {}
|
||||
@ -55,7 +56,7 @@ fun FoundFlights(
|
||||
modifier = Modifier
|
||||
.padding(innerPadding)
|
||||
.fillMaxSize(),
|
||||
flightList = foundFlightsUiState,
|
||||
flightList = foundFlightsUiState.flightList,
|
||||
onClick = { uid: Int ->
|
||||
val route = BottomBarScreen.FlightInfo.passId(uid.toString())
|
||||
navController.navigate(route)
|
||||
|
@ -6,7 +6,6 @@ import androidx.lifecycle.viewmodel.CreationExtras
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import ru.ulstu.`is`.airticketrentservice.TicketApplication
|
||||
import ru.ulstu.`is`.airticketrentservice.api.AppService
|
||||
|
||||
object AppViewModelProvider {
|
||||
val Factory = viewModelFactory {
|
||||
@ -53,7 +52,8 @@ object AppViewModelProvider {
|
||||
initializer {
|
||||
FindFlightsViewModel(
|
||||
this.createSavedStateHandle(),
|
||||
ticketApplication().container.flightRestRepository)
|
||||
ticketApplication().container.flightRestRepository
|
||||
)
|
||||
}
|
||||
initializer {
|
||||
UserEditViewModel(
|
||||
|
@ -11,36 +11,24 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.ulstu.`is`.airticketrentservice.api.AppService
|
||||
import ru.ulstu.`is`.airticketrentservice.api.model.toFlight
|
||||
import ru.ulstu.`is`.airticketrentservice.database.AppContainer
|
||||
import ru.ulstu.`is`.airticketrentservice.database.models.Flight
|
||||
import ru.ulstu.`is`.airticketrentservice.database.repository.FlightRepository
|
||||
|
||||
class FindFlightsViewModel(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
private val flightRepository: FlightRepository,
|
||||
|
||||
private val flightRepository: FlightRepository
|
||||
) : ViewModel() {
|
||||
private val from: String = checkNotNull(savedStateHandle["direction_from"])
|
||||
private val to: String = checkNotNull(savedStateHandle["direction_to"])
|
||||
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())
|
||||
private set
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
//foundFlightsList = appService.foundFlights().map { it.toFlight() }
|
||||
foundFlightsUiState = FoundFlightsUiState(flightRepository.foundFlights(from, to, departureDate))
|
||||
foundFlightsUiState = FoundFlightsUiState(flightRepository.findFlights(from, to, departureDate))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
"flightId": 2
|
||||
}
|
||||
],
|
||||
"searchFlights": [
|
||||
"flights": [
|
||||
{
|
||||
"id": 2,
|
||||
"direction_from": "a",
|
||||
@ -17,6 +17,15 @@
|
||||
"tickets_count": 100,
|
||||
"one_ticket_cost": 1000
|
||||
},
|
||||
{
|
||||
"direction_from": "ульск",
|
||||
"direction_to": "мск",
|
||||
"departure_date": "24-12-2023",
|
||||
"arrival_date": "24-12-2023",
|
||||
"tickets_count": 20,
|
||||
"one_ticket_cost": 2000,
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"direction_from": "Санкт-Петербург ",
|
||||
"direction_to": "Сочи",
|
||||
@ -27,16 +36,14 @@
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"direction_from": "Ульяновск ",
|
||||
"direction_to": "Москва ",
|
||||
"departure_date": "26-12-2023",
|
||||
"arrival_date": "26-12-2023",
|
||||
"tickets_count": 50,
|
||||
"one_ticket_cost": 2680
|
||||
}
|
||||
],
|
||||
"flights": [
|
||||
"tickets_count": 40,
|
||||
"one_ticket_cost": 2680,
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"direction_from": "Хабаровск ",
|
||||
"direction_to": "Кострома ",
|
||||
@ -114,26 +121,6 @@
|
||||
"password": "aaa",
|
||||
"role": "user",
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"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
|
||||
}
|
||||
],
|
||||
"rents": [
|
||||
|
@ -7,7 +7,7 @@
|
||||
"flightId": 2
|
||||
}
|
||||
],
|
||||
"foundFlights": [
|
||||
"flights": [
|
||||
{
|
||||
"id": 2,
|
||||
"direction_from": "a",
|
||||
@ -17,6 +17,15 @@
|
||||
"tickets_count": 100,
|
||||
"one_ticket_cost": 1000
|
||||
},
|
||||
{
|
||||
"direction_from": "ульск",
|
||||
"direction_to": "мск",
|
||||
"departure_date": "24-12-2023",
|
||||
"arrival_date": "24-12-2023",
|
||||
"tickets_count": 20,
|
||||
"one_ticket_cost": 2000,
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"direction_from": "Санкт-Петербург ",
|
||||
"direction_to": "Сочи",
|
||||
@ -27,16 +36,14 @@
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"direction_from": "Ульяновск ",
|
||||
"direction_to": "Москва ",
|
||||
"departure_date": "26-12-2023",
|
||||
"arrival_date": "26-12-2023",
|
||||
"tickets_count": 50,
|
||||
"one_ticket_cost": 2680
|
||||
}
|
||||
],
|
||||
"flights": [
|
||||
"tickets_count": 40,
|
||||
"one_ticket_cost": 2680,
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"direction_from": "Хабаровск ",
|
||||
"direction_to": "Кострома ",
|
||||
@ -110,30 +117,10 @@
|
||||
"name": "шчшчгч",
|
||||
"patronymic": "шчшчшч",
|
||||
"date_of_birth": "10-12-2015",
|
||||
"email": "aa@mail.ru",
|
||||
"email": "aaa@mail.ru",
|
||||
"password": "aaa",
|
||||
"role": "user",
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"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
|
||||
}
|
||||
],
|
||||
"rents": [
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user