using AutoMapper; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using skydiveLogs_api.DataContract; using skydiveLogs_api.DomainBusiness.Interfaces; using System.Collections.Generic; namespace skydiveLogs_api.Controllers { public class StatsController : Base { #region Public Constructors public StatsController(IStatsService statsService, IMapper mapper) { _statsService = statsService; _mapper = mapper; } #endregion Public Constructors #region Public Methods /// /// Retrieves statistics grouped by aircraft. /// /// A collection of StatisticResp objects containing aircraft statistics. [HttpGet("ByAircraft")] [EnableCors] public IEnumerable ByAircraft() { var result = _statsService.GetStatsByAircraft(); return _mapper.Map>(result); } /// /// Retrieves statistics grouped by drop zone. /// /// A collection of StatisticResp objects containing drop zone statistics. [HttpGet("ByDz")] [EnableCors] public IEnumerable ByDz() { var result = _statsService.GetStatsByDz(); return _mapper.Map>(result); } /// /// Retrieves statistics grouped by gear. /// /// A collection of StatisticResp objects containing gear statistics. [HttpGet("ByGear")] [EnableCors] public IEnumerable ByGear() { var result = _statsService.GetStatsByGear(); return _mapper.Map>(result); } /// /// Retrieves statistics grouped by jump type. /// /// A collection of StatisticResp objects containing jump type statistics. [HttpGet("ByJumpType")] [EnableCors] public IEnumerable ByJumpType() { var result = _statsService.GetStatsByJumpType(); return _mapper.Map>(result); } /// /// Retrieves statistics grouped by year. /// /// A collection of StatisticResp objects containing year statistics. [HttpGet("ByYear")] [EnableCors] public IEnumerable ByYear() { var result = _statsService.GetStatsByYear(); return _mapper.Map>(result); } /// /// Retrieves statistics for the last month grouped by drop zone and jump type. /// /// A StatisticForLastMonthResp object containing last month statistics. [HttpGet("ForLastMonth")] [EnableCors] public StatisticForLastMonthResp ForLastMonth() { var resultByDz = _statsService.GetStatsForLastMonthByDz(); var resultByJumpType = _statsService.GetStatsForLastMonthByJumpType(); var result = new StatisticForLastMonthResp(); result.ByDz = _mapper.Map>(resultByDz); result.ByJumpType = _mapper.Map>(resultByJumpType); return result; } /// /// Retrieves statistics for the last year grouped by drop zone and jump type. /// /// A StatisticForLastYearResp object containing last year statistics. [HttpGet("ForLastYear")] [EnableCors] public StatisticForLastYearResp ForLastYear() { var resultByDz = _statsService.GetStatsForLastYearByDz(); var resultByJumpType = _statsService.GetStatsForLastYearByJumpType(); var result = new StatisticForLastYearResp(); result.ByDz = _mapper.Map>(resultByDz); result.ByJumpType = _mapper.Map>(resultByJumpType); return result; } /// /// Retrieves statistics by year grouped with jump type for chart visualization. /// /// A collection of StatisticForChartResp objects containing yearly jump type statistics. [HttpGet("ByYearByJumpType")] [EnableCors] public IEnumerable ByYearByJumpType() { var result = _statsService.GetStatsByYearByJumpType(); return _mapper.Map>(result); } /// /// Resets all statistics to their initial state. /// [HttpGet("Reset")] [EnableCors] public void Reset() { _statsService.Reset(); } /// /// Retrieves a simple summary of all statistics. /// /// A SimpleSummaryResp object containing the simple summary statistics. [HttpGet("Simple")] [EnableCors] public SimpleSummaryResp Simple() { var result = _statsService.GetSimpleSummary(); return _mapper.Map(result); } #endregion Public Methods #region Private properties private readonly IMapper _mapper; private readonly IStatsService _statsService; #endregion Private properties } }