Files
SkydiveLogs/Back/skydiveLogs-api/Controllers/AircraftController.cs
T
sandre ceed44f997 Little test with AI + Add the equipment (#8)
Tests using local LLM AI to add comments in the C# files
For the flights tunnel, show the total to day/hours
For the jump, add the equipment (now just with the wingsuit)

Reviewed-on: #8
Co-authored-by: sandre <perso@sebastienandre.com>
Co-committed-by: sandre <perso@sebastienandre.com>
2026-05-16 09:24:13 +00:00

107 lines
3.3 KiB
C#

using System.Collections.Generic;
using AutoMapper;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using skydiveLogs_api.DataContract;
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
namespace skydiveLogs_api.Controllers
{
public class AircraftController : Base
{
#region Public Constructors
public AircraftController(IAircraftService aircraftService,
IMapper mapper)
{
_aircraftService = aircraftService;
_mapper = mapper;
}
#endregion Public Constructors
#region Public Methods
/// <summary>
/// Deletes an aircraft by its ID.
/// </summary>
/// <param name="id">The aircraft ID to delete.</param>
[HttpDelete("{id}")]
[EnableCors]
public void Delete(int id)
{
_aircraftService.DeleteAircraftById(id);
}
/// <summary>
/// Retrieves a list of all aircraft.
/// </summary>
/// <returns>A collection of AircraftResp objects containing all aircraft data.</returns>
[HttpGet]
[EnableCors]
public IEnumerable<AircraftResp> Get()
{
var result = _aircraftService.GetAllAircrafts();
return _mapper.Map<IEnumerable<AircraftResp>>(result);
}
/// <summary>
/// Retrieves an aircraft by its ID.
/// </summary>
/// <param name="id">The aircraft ID to retrieve.</param>
/// <returns>An AircraftResp object containing the aircraft details.</returns>
[HttpGet("{id}")]
[EnableCors]
public AircraftResp Get(int id)
{
var result = _aircraftService.GetAircraftById(id);
return _mapper.Map<AircraftResp>(result);
}
/// <summary>
/// Retrieves a simplified list of all aircraft.
/// </summary>
/// <returns>A collection of AircraftSimpleResp objects containing simplified aircraft data.</returns>
[HttpGet("GetSimple")]
[EnableCors]
public IEnumerable<AircraftSimpleResp> GetSimple()
{
var result = _aircraftService.GetAllAircrafts();
return _mapper.Map<IEnumerable<AircraftSimpleResp>>(result);
}
/// <summary>
/// Adds a new aircraft to the system.
/// </summary>
/// <param name="value">AircraftReq object containing the new aircraft data.</param>
[HttpPost]
[EnableCors]
public void Post([FromBody] AircraftReq value)
{
_aircraftService.AddNewAircraft(_mapper.Map<Aircraft>(value));
}
/// <summary>
/// Updates an existing aircraft.
/// </summary>
/// <param name="id">The aircraft ID to update.</param>
/// <param name="value">AircraftReq object containing the updated aircraft data.</param>
[HttpPut("{id}")]
[EnableCors]
public void Put(int id, [FromBody] AircraftReq value)
{
_aircraftService.UpdateAircraft(id, _mapper.Map<Aircraft>(value));
}
#endregion Public Methods
#region Private Fields
private readonly IAircraftService _aircraftService;
private readonly IMapper _mapper;
#endregion Private Fields
}
}