Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using GatewayAPI.Clients.FlightService;
using GatewayAPI.Clients.UserService;
using GatewayAPI.Models;
using Microsoft.AspNetCore.Mvc;
namespace GatewayAPI.Controllers
{
[ApiController]
[Route("api/[Controller]")]
public class FlightController : ControllerBase
{
private readonly IFlightServiceClient flightServiceClient;
public FlightController(IFlightServiceClient flightServiceClient)
{
this.flightServiceClient = flightServiceClient;
}
[HttpGet()]
public async Task<IActionResult> GetFlights(string? origin = null, string? destination = null, DateTime? departureTime = null, DateTime? arrivalTime = null)
{
HttpResponseMessage response = await flightServiceClient.GetFlightsAsync(origin, destination, departureTime, arrivalTime);
return new HttpResponseMessageResult(response);
}
[HttpGet("{id}")]
public async Task<IActionResult> GetFlights(int id)
{
HttpResponseMessage response = await flightServiceClient.GetFlightAsync(id);
return new HttpResponseMessageResult(response);
}
[HttpPost()]
public async Task<IActionResult> AddFlight([FromBody] FlightCreation flightCreation)
{
HttpResponseMessage response = await flightServiceClient.AddFlightAsync(flightCreation);
return new HttpResponseMessageResult(response);
}
[HttpGet("{id}/capacity")]
public async Task<IActionResult> GetFlightCapacity([FromRoute] int id, [FromQuery] int classType)
{
HttpResponseMessage response = await flightServiceClient.GetFlightCapacityAsync(id, classType);
return new HttpResponseMessageResult(response);
}
}
}