feat: Implement flight search functionality

This commit introduces the ability to search for flights based on user-defined criteria.

Key changes:
- Added `GetFlightsSearchContentUseCase` interface in the domain layer and its implementation `GetFlightsSearchContentUseCaseImpl` in the repository layer to handle flight search logic.
- Implemented `FlightDomainMapper` to map `FlightResponse` from the API to the domain `Flight` model.
- Updated `NetworkModule`:
    - Introduced `ServicesAPI` and `NativeAppsAPI` qualifiers to differentiate between Retrofit instances for different Ryanair APIs.
    - Configured a new Retrofit instance for the `nativeapps.ryanair.com` base URL.
    - Modified `FlightService` to use the `nativeapps.ryanair.com` base URL.
- Updated `FlightService` endpoint to `api/v4/en-gb/Availability`.
- Integrated `GetFlightsSearchContentUseCase` into `HomeScreenViewModel` to trigger flight searches.
- Created `SearchOptions` data class in the domain layer to encapsulate search parameters.
- Added `GetFlightsSearchContentUseCaseModule` to provide the use case implementation via Hilt.
This commit is contained in:
2025-06-14 15:42:07 +02:00
parent 5d9a56d71f
commit ffcfc1f45b
8 changed files with 193 additions and 6 deletions

View File

@ -5,7 +5,10 @@ import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.adriankuta.flights.core.util.Result
import dev.adriankuta.flights.core.util.asResult
import dev.adriankuta.flights.domain.search.GetFlightsSearchContentUseCase
import dev.adriankuta.flights.domain.search.ObserveAirportsUseCase
import dev.adriankuta.flights.domain.search.entities.SearchOptions
import dev.adriankuta.flights.domain.types.Airport
import dev.adriankuta.flights.domain.types.AirportInfo
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
@ -13,6 +16,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import timber.log.Timber
import java.time.LocalDate
import javax.inject.Inject
@ -20,6 +24,7 @@ import javax.inject.Inject
@HiltViewModel
class HomeScreenViewModel @Inject constructor(
observeAirportsUseCase: ObserveAirportsUseCase,
private val getFlightsSearchContentUseCase: GetFlightsSearchContentUseCase,
) : ViewModel() {
private val selectedOriginAirport = MutableStateFlow<AirportInfo?>(null)
@ -86,7 +91,27 @@ class HomeScreenViewModel @Inject constructor(
}
fun search() {
Timber.d("Search clicked")
viewModelScope.launch {
val results = getFlightsSearchContentUseCase(
searchOptions = SearchOptions(
origin = Airport.Departure(
code = selectedOriginAirport.value?.code ?: return@launch,
name = selectedOriginAirport.value?.name ?: return@launch,
macCity = selectedOriginAirport.value?.macCity,
),
destination = Airport.Arrival(
code = selectedDestinationAirport.value?.code ?: return@launch,
name = selectedDestinationAirport.value?.name ?: return@launch,
macCity = selectedDestinationAirport.value?.macCity,
),
date = selectedDate.value,
adults = adultCount.value,
teens = teenCount.value,
children = childCount.value,
),
)
Timber.d("Result $results")
}
}
}