using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Cors; using AutoMapper; using skydiveLogs_api.Business.Interface; using skydiveLogs_api.DataContract; namespace skydiveLogs_api.Controllers { [Route("api/[controller]")] [ApiController] public class StatsController : ControllerBase { public StatsController(IStatsService statsService, IMapper mapper) { _statsService = statsService; _mapper = mapper; } [HttpGet("Simple")] [EnableCors] public SimpleSummaryResp Simple() { var result = _statsService.GetSimpleSummary(); return _mapper.Map(result); } [HttpGet("ByDz")] [EnableCors] public IEnumerable ByDz() { var result = _statsService.GetStatsByDz(); return _mapper.Map>(result); } [HttpGet("ByAircraft")] [EnableCors] public IEnumerable ByAircraft() { var result = _statsService.GetStatsByAircraft(); return _mapper.Map>(result); } [HttpGet("ByJumpType")] [EnableCors] public IEnumerable ByJumpType() { var result = _statsService.GetStatsByJumpType(); return _mapper.Map>(result); } [HttpGet("ByGear")] [EnableCors] public IEnumerable ByGear() { var result = _statsService.GetStatsByGear(); return _mapper.Map>(result); } [HttpGet("ByYear")] [EnableCors] public IEnumerable ByYear() { var result = _statsService.GetStatsByYear(); return _mapper.Map>(result); } [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; } [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; } #region Private properties private readonly IStatsService _statsService; private readonly IMapper _mapper; #endregion } }