Skip to content

Commit

Permalink
Change flight search mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
sefadegirmenci committed Jul 14, 2022
1 parent 0104daa commit a09d961
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

public interface FlightRepository
extends MongoRepository<Flight,String> {
Optional<List<Flight>> findFlightsByArrivalAirportIgnoreCaseAndDepartureAirportIgnoreCaseAndDepartureDateTimeGreaterThanEqualAndArrivalDateTimeLessThanEqual (Airport arrivalAirport, Airport departureAirport, LocalDateTime departureDateTime, LocalDateTime arrivalDateTime);
Optional<List<Flight>> findFlightsByDepartureAirportAirportCodeIgnoreCaseAndArrivalAirportAirportCodeIgnoreCaseAndDepartureDateTimeGreaterThanEqualAndArrivalDateTimeLessThanEqual (String departureAirport, String arrivalAirport, LocalDateTime departureDateTime, LocalDateTime arrivalDateTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ public List<Flight> getFlights(){
return flightRepository.findAll();
}
public List<Flight> searchFlight(String departureAirportCode, String arrivalAirportCode, LocalDateTime departureDateTime, LocalDateTime arrivalDateTime) {
Airport departureAirport = airportRepository.findAirportByAirportCodeIgnoreCase(departureAirportCode)
.orElseThrow(() -> new AirportNotFoundException("Departure airport not found"));
Airport arrivalAirport = airportRepository.findAirportByAirportCodeIgnoreCase(arrivalAirportCode)
.orElseThrow(() -> new AirportNotFoundException("Arrival airport not found"));
return flightRepository.findFlightsByArrivalAirportIgnoreCaseAndDepartureAirportIgnoreCaseAndDepartureDateTimeGreaterThanEqualAndArrivalDateTimeLessThanEqual(departureAirport, arrivalAirport, departureDateTime, arrivalDateTime)
return flightRepository.findFlightsByDepartureAirportAirportCodeIgnoreCaseAndArrivalAirportAirportCodeIgnoreCaseAndDepartureDateTimeGreaterThanEqualAndArrivalDateTimeLessThanEqual
(departureAirportCode, arrivalAirportCode, departureDateTime, arrivalDateTime)
.orElseThrow(() -> new FlightNotFoundException("Flight not found"));
}

Expand Down

0 comments on commit a09d961

Please sign in to comment.