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 TunnelFlightController : Base { #region Public Constructors public TunnelFlightController(ITunnelFlightService tunnelFlightService, IMapper mapper) { _tunnelFlightService = tunnelFlightService; _mapper = mapper; } #endregion Public Constructors #region Public Methods /// /// Retrieves a list of all tunnel flights. /// /// A collection of TunnelFlightResp objects containing all tunnel flights. [HttpGet] [EnableCors] public IEnumerable Get() { var result = _tunnelFlightService.GetAllTunnelFlights(); return _mapper.Map>(result); } /// /// Retrieves a tunnel flight by its ID. /// /// The tunnel flight ID to retrieve. /// A TunnelFlightResp object containing the tunnel flight details. [HttpGet("{id}")] [EnableCors] public TunnelFlightResp Get(int id) { var result = _tunnelFlightService.GetTunnelFlightById(id); return _mapper.Map(result); } /// /// Retrieves tunnel flights filtered by date range. /// /// The start date for filtering. /// The end date for filtering. /// A collection of TunnelFlightResp objects filtered by the specified date range. [HttpGet("{beginDate}/{endDate}")] [EnableCors] public IEnumerable Get(string beginDate, string endDate) { var result = _tunnelFlightService.GetTunnelFlightByDates(beginDate, endDate); return _mapper.Map>(result); } /// /// Retrieves tunnel flights grouped by month within a date range. /// /// The start date for grouping. /// The end date for grouping. /// A collection of StatisticForChartResp objects grouped by month. [HttpGet("month/{beginDate}/{endDate}")] [EnableCors] public IEnumerable GetGroupByMonth(string beginDate, string endDate) { var result = _tunnelFlightService.GetTunnelFlightGroupByMonth(beginDate, endDate); return _mapper.Map>(result); } /// /// Adds a new tunnel flight to the system. /// /// TunnelFlightReq object containing the new tunnel flight data. [HttpPost] [EnableCors] public void Post([FromBody] TunnelFlightReq value) { _tunnelFlightService.AddNewFlight(value.TunnelId, value.JumpTypeId, _mapper.Map(value)); } /// /// Updates an existing tunnel flight. /// /// The tunnel flight ID to update. /// TunnelFlightReq object containing the updated tunnel flight data. [HttpPut("{id}")] [EnableCors] public void Put(int id, [FromBody] TunnelFlightReq value) { _tunnelFlightService.UpdateTunnelFlight(id, _mapper.Map(value)); } /// /// Deletes a tunnel flight by its ID. /// /// The tunnel flight ID to delete. [HttpDelete("{id}")] [EnableCors] public void Delete(int id) { _tunnelFlightService.DeleteTunnelFlightById(id); } #endregion Public Methods #region Private Fields private readonly ITunnelFlightService _tunnelFlightService; private readonly IMapper _mapper; #endregion Private Fields } }