mirror of
https://github.com/azaion/flights.git
synced 2026-04-22 06:56:30 +00:00
Initial commit
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Azaion.Flights.DTOs;
|
||||
using Azaion.Flights.Services;
|
||||
|
||||
namespace Azaion.Flights.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("aircrafts")]
|
||||
[Authorize(Policy = "FL")]
|
||||
public class AircraftsController(AircraftService aircraftService) : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateAircraftRequest request)
|
||||
{
|
||||
var aircraft = await aircraftService.CreateAircraft(request);
|
||||
return Created($"/aircrafts/{aircraft.Id}", aircraft);
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateAircraftRequest request)
|
||||
{
|
||||
var aircraft = await aircraftService.UpdateAircraft(id, request);
|
||||
return Ok(aircraft);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> Delete(Guid id)
|
||||
{
|
||||
await aircraftService.DeleteAircraft(id);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll([FromQuery] GetAircraftsQuery query)
|
||||
{
|
||||
var aircrafts = await aircraftService.GetAircrafts(query);
|
||||
return Ok(aircrafts);
|
||||
}
|
||||
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<IActionResult> Get(Guid id)
|
||||
{
|
||||
var aircraft = await aircraftService.GetAircraft(id);
|
||||
return Ok(aircraft);
|
||||
}
|
||||
|
||||
[HttpPatch("{id:guid}/default")]
|
||||
public async Task<IActionResult> SetDefault(Guid id, [FromBody] SetDefaultRequest request)
|
||||
{
|
||||
await aircraftService.SetDefault(id, request);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Azaion.Flights.DTOs;
|
||||
using Azaion.Flights.Services;
|
||||
|
||||
namespace Azaion.Flights.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("flights")]
|
||||
[Authorize(Policy = "FL")]
|
||||
public class FlightsController(FlightService flightService, WaypointService waypointService) : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateFlightRequest request)
|
||||
{
|
||||
var flight = await flightService.CreateFlight(request);
|
||||
return Created($"/flights/{flight.Id}", flight);
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateFlightRequest request)
|
||||
{
|
||||
var flight = await flightService.UpdateFlight(id, request);
|
||||
return Ok(flight);
|
||||
}
|
||||
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<IActionResult> Get(Guid id)
|
||||
{
|
||||
var flight = await flightService.GetFlight(id);
|
||||
return Ok(flight);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll([FromQuery] GetFlightsQuery query)
|
||||
{
|
||||
var result = await flightService.GetFlights(query);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> Delete(Guid id)
|
||||
{
|
||||
await flightService.DeleteFlight(id);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}/waypoints")]
|
||||
public async Task<IActionResult> CreateWaypoint(Guid id, [FromBody] CreateWaypointRequest request)
|
||||
{
|
||||
var waypoint = await waypointService.CreateWaypoint(id, request);
|
||||
return Created($"/flights/{id}/waypoints/{waypoint.Id}", waypoint);
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}/waypoints/{waypointId:guid}")]
|
||||
public async Task<IActionResult> UpdateWaypoint(Guid id, Guid waypointId, [FromBody] UpdateWaypointRequest request)
|
||||
{
|
||||
var waypoint = await waypointService.UpdateWaypoint(id, waypointId, request);
|
||||
return Ok(waypoint);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}/waypoints/{waypointId:guid}")]
|
||||
public async Task<IActionResult> DeleteWaypoint(Guid id, Guid waypointId)
|
||||
{
|
||||
await waypointService.DeleteWaypoint(id, waypointId);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("{id:guid}/waypoints")]
|
||||
public async Task<IActionResult> GetWaypoints(Guid id)
|
||||
{
|
||||
var waypoints = await waypointService.GetWaypoints(id);
|
||||
return Ok(waypoints);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user