Skip to content

Commit

Permalink
Search only by airports
Browse files Browse the repository at this point in the history
  • Loading branch information
sefadegirmenci committed Jul 15, 2022
1 parent 22a5147 commit a3d8b02
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@

public interface FlightRepository
extends MongoRepository<Flight,String> {
Optional<List<Flight>> findFlightsByDepartureAirportAirportCodeIgnoreCaseAndArrivalAirportAirportCodeIgnoreCaseAndDepartureDateTimeGreaterThanEqualAndArrivalDateTimeLessThanEqual (String departureAirport, String arrivalAirport, LocalDateTime departureDateTime, LocalDateTime arrivalDateTime);
Optional<List<Flight>> findFlightsByDepartureAirportAirportCodeIgnoreCaseAndArrivalAirportAirportCodeIgnoreCaseAndDepartureDateTimeGreaterThanEqualAndArrivalDateTimeLessThanEqual (String departureAirportCode, String arrivalAirportCode, LocalDateTime departureDateTime, LocalDateTime arrivalDateTime);
Optional<List<Flight>> findFlightsByDepartureAirportAirportCodeIgnoreCaseAndArrivalAirportAirportCodeIgnoreCase(String departureAirportCode, String arrivalAirportCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ResponseEntity<Flight> addFlight(@RequestBody Flight flight){
}

/* TODO: Change the search logic*/
@Operation(summary = "Search a flight by departure and arrival airports")
@Operation(summary = "Search a flight by all the fields")
@GetMapping(value = "search/{departureAirportCode}/{arrivalAirportCode}/{departureDateTimeString}/{arrivalDateTimeString}",produces = {"application/json"})
public ResponseEntity<List<Flight>> searchFlight(@PathVariable(required = false) String departureAirportCode,
@PathVariable(required = false) String arrivalAirportCode,
Expand All @@ -52,6 +52,13 @@ public ResponseEntity<List<Flight>> searchFlight(@PathVariable(required = false)
return ResponseEntity.ok(flightService.searchFlight(departureAirportCode, arrivalAirportCode, departureDateTime, arrivalDateTime));
}

@Operation(summary = "Search a flight by departure and arrival airports")
@GetMapping(value = "search/{departureAirportCode}/{arrivalAirportCode}",produces = {"application/json"})
public ResponseEntity<List<Flight>> searchFlightByAirports(@PathVariable(required = false) String departureAirportCode,
@PathVariable(required = false) String arrivalAirportCode) {
return ResponseEntity.ok(flightService.searchFlightByAirports(departureAirportCode, arrivalAirportCode));
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public List<Flight> searchFlight(String departureAirportCode, String arrivalAirp
.orElseThrow(() -> new FlightNotFoundException("Flight not found"));
}

public List<Flight> searchFlightByAirports(String departureAirportCode, String arrivalAirportCode) {
return flightRepository.findFlightsByDepartureAirportAirportCodeIgnoreCaseAndArrivalAirportAirportCodeIgnoreCase(departureAirportCode, arrivalAirportCode)
.orElseThrow(() -> new FlightNotFoundException("Flight not found"));
}


public Flight addFlight(Flight flight) {
return flightRepository.save(flight);
Expand Down

0 comments on commit a3d8b02

Please sign in to comment.