diff --git a/FlightMicroservice/Controllers/FlightController.cs b/FlightMicroservice/Controllers/FlightController.cs index 649e10418beb7922f494983520f430ab359ab7b4..2bd55a2cf7155ba0bfbb609ac35ec4da29e47062 100644 --- a/FlightMicroservice/Controllers/FlightController.cs +++ b/FlightMicroservice/Controllers/FlightController.cs @@ -18,9 +18,9 @@ namespace FlightMicroservice.Controllers } [HttpGet()] - public ActionResult GetFlights(string? origin = null, string? destination = null, DateTime? departureTime = null, DateTime? arrivalTime = null) + public ActionResult GetFlights(int? airlineId = null, string? origin = null, string? destination = null, DateTime? departureTime = null, DateTime? arrivalTime = null) { - List<Flight> flights = flightService.GetFlights(origin, destination, departureTime, arrivalTime); + List<Flight> flights = flightService.GetFlights(airlineId, origin, destination, departureTime, arrivalTime); if (flights == null) return BadRequest(); diff --git a/FlightMicroservice/Services/FlightService.cs b/FlightMicroservice/Services/FlightService.cs index 91e30b89143172ab5fe60391b5cf2f98ad234afa..c849e71a99d8f6deb83d068773de401b302fcfba 100644 --- a/FlightMicroservice/Services/FlightService.cs +++ b/FlightMicroservice/Services/FlightService.cs @@ -18,10 +18,13 @@ namespace FlightMicroservice.Services return flight; } - public List<Flight> GetFlights(string? origin, string? destination, DateTime? departureTime, DateTime? arrivalTime) + public List<Flight> GetFlights(int? airlineId, string? origin, string? destination, DateTime? departureTime, DateTime? arrivalTime) { IQueryable<Flight> query = dbContext.Flights.AsQueryable(); + if(airlineId != null) + query = query.Where(flight => flight.AirlineId == airlineId); + if (!string.IsNullOrWhiteSpace(origin)) query = query.Where(flight => flight.Origin == origin); diff --git a/FlightMicroservice/Services/IFlightService.cs b/FlightMicroservice/Services/IFlightService.cs index f3bed26d5dad7e96846f67db8593dc0c809c0749..4dad71b46f0b9372e243485b29eef0d166634678 100644 --- a/FlightMicroservice/Services/IFlightService.cs +++ b/FlightMicroservice/Services/IFlightService.cs @@ -5,7 +5,7 @@ namespace FlightMicroservice.Services public interface IFlightService { Flight? GetFlight(int flightId); - List<Flight> GetFlights(string? origin, string? destination, DateTime? departureTime, DateTime? arrivalTime); + List<Flight> GetFlights(int? airlineId, string? origin, string? destination, DateTime? departureTime, DateTime? arrivalTime); Flight CreateFlight(int airlineId, string origin, string destination, DateTime departureTime, DateTime arrivalTime, int economyCapacity, int businessCapacity, decimal economyPrice, decimal businessPrice); bool RemoveFlight(int flightId); List<Seat> GetSeatsByFlightId(int flightId); diff --git a/GatewayAPI/Clients/FlightService/FlightServiceClient.cs b/GatewayAPI/Clients/FlightService/FlightServiceClient.cs index 82e4ca76e9c3f5a932be90366aff634ee9832223..aff15a4f9cfdadfab77b0f148532919bfb27f616 100644 --- a/GatewayAPI/Clients/FlightService/FlightServiceClient.cs +++ b/GatewayAPI/Clients/FlightService/FlightServiceClient.cs @@ -18,14 +18,17 @@ namespace GatewayAPI.Clients.FlightService return await httpClient.GetAsync($"{FLIGHT_API_PATH}/{flightId}"); } - public async Task<HttpResponseMessage> GetFlightsAsync(string? origin = null, string? destination = null, DateTime? departureTime = null, DateTime? arrivalTime = null) + public async Task<HttpResponseMessage> GetFlightsAsync(int? airlineId = null, string? origin = null, string? destination = null, DateTime? departureTime = null, DateTime? arrivalTime = null) { var queryParams = new List<string>(); - if (origin != null) + if(airlineId != null) + queryParams.Add($"airlineId={airlineId}"); + + if (!string.IsNullOrEmpty(origin)) queryParams.Add($"origin={Uri.EscapeDataString(origin)}"); - if (destination != null) + if (!string.IsNullOrEmpty(destination)) queryParams.Add($"destination={Uri.EscapeDataString(destination)}"); if (departureTime.HasValue) diff --git a/GatewayAPI/Clients/FlightService/IFlightServiceClient.cs b/GatewayAPI/Clients/FlightService/IFlightServiceClient.cs index ac86b80d8cf8bf3bb2ca54de3b9c6563d01fcbf0..70b9e430e68b67a69dc16e8eaae47b84e066a0ef 100644 --- a/GatewayAPI/Clients/FlightService/IFlightServiceClient.cs +++ b/GatewayAPI/Clients/FlightService/IFlightServiceClient.cs @@ -5,7 +5,7 @@ namespace GatewayAPI.Clients.FlightService public interface IFlightServiceClient { Task<HttpResponseMessage> GetFlightAsync(int flightId); - Task<HttpResponseMessage> GetFlightsAsync(string? origin = null, string? destination = null, DateTime? departureTime = null, DateTime? arrivalTime = null); + Task<HttpResponseMessage> GetFlightsAsync(int? airlineId = null, string? origin = null, string? destination = null, DateTime? departureTime = null, DateTime? arrivalTime = null); Task<HttpResponseMessage> AddFlightAsync(FlightCreation flight); Task<HttpResponseMessage> GetFlightCapacityAsync(int flightId, int classType); Task<HttpResponseMessage> GetFlightSeatsAsync(int flightId); diff --git a/GatewayAPI/Controllers/FlightController.cs b/GatewayAPI/Controllers/FlightController.cs index c567683c5f5f67a7826b772be0055d050d5f9934..2166bfa303018188a35db8a01b71fa61a76f4aa3 100644 --- a/GatewayAPI/Controllers/FlightController.cs +++ b/GatewayAPI/Controllers/FlightController.cs @@ -16,9 +16,9 @@ namespace GatewayAPI.Controllers } [HttpGet()] - public async Task<IActionResult> GetFlights(string? origin = null, string? destination = null, DateTime? departureTime = null, DateTime? arrivalTime = null) + public async Task<IActionResult> GetFlights(int? airlineId = null, string? origin = null, string? destination = null, DateTime? departureTime = null, DateTime? arrivalTime = null) { - HttpResponseMessage response = await flightServiceClient.GetFlightsAsync(origin, destination, departureTime, arrivalTime); + HttpResponseMessage response = await flightServiceClient.GetFlightsAsync(airlineId, origin, destination, departureTime, arrivalTime); return new HttpResponseMessageResult(response); }