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 /// /// Deletes an aircraft by its ID. /// /// The aircraft ID to delete. [HttpDelete("{id}")] [EnableCors] public void Delete(int id) { _aircraftService.DeleteAircraftById(id); } /// /// Retrieves a list of all aircraft. /// /// A collection of AircraftResp objects containing all aircraft data. [HttpGet] [EnableCors] public IEnumerable Get() { var result = _aircraftService.GetAllAircrafts(); return _mapper.Map>(result); } /// /// Retrieves an aircraft by its ID. /// /// The aircraft ID to retrieve. /// An AircraftResp object containing the aircraft details. [HttpGet("{id}")] [EnableCors] public AircraftResp Get(int id) { var result = _aircraftService.GetAircraftById(id); return _mapper.Map(result); } /// /// Retrieves a simplified list of all aircraft. /// /// A collection of AircraftSimpleResp objects containing simplified aircraft data. [HttpGet("GetSimple")] [EnableCors] public IEnumerable GetSimple() { var result = _aircraftService.GetAllAircrafts(); return _mapper.Map>(result); } /// /// Adds a new aircraft to the system. /// /// AircraftReq object containing the new aircraft data. [HttpPost] [EnableCors] public void Post([FromBody] AircraftReq value) { _aircraftService.AddNewAircraft(_mapper.Map(value)); } /// /// Updates an existing aircraft. /// /// The aircraft ID to update. /// AircraftReq object containing the updated aircraft data. [HttpPut("{id}")] [EnableCors] public void Put(int id, [FromBody] AircraftReq value) { _aircraftService.UpdateAircraft(id, _mapper.Map(value)); } #endregion Public Methods #region Private Fields private readonly IAircraftService _aircraftService; private readonly IMapper _mapper; #endregion Private Fields } }