Files
SkydiveLogs/Back/skydiveLogs-api/Controllers/StatsController.cs

132 lines
3.7 KiB
C#

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
[HttpGet("ByAircraft")]
[EnableCors]
public IEnumerable<StatisticResp> ByAircraft()
{
var result = _statsService.GetStatsByAircraft();
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
[HttpGet("ByDz")]
[EnableCors]
public IEnumerable<StatisticResp> ByDz()
{
var result = _statsService.GetStatsByDz();
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
[HttpGet("ByGear")]
[EnableCors]
public IEnumerable<StatisticResp> ByGear()
{
var result = _statsService.GetStatsByGear();
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
[HttpGet("ByJumpType")]
[EnableCors]
public IEnumerable<StatisticResp> ByJumpType()
{
var result = _statsService.GetStatsByJumpType();
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
[HttpGet("ByYear")]
[EnableCors]
public IEnumerable<StatisticResp> ByYear()
{
var result = _statsService.GetStatsByYear();
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
[HttpGet("ForLastMonth")]
[EnableCors]
public StatisticForLastMonthResp ForLastMonth()
{
var resultByDz = _statsService.GetStatsForLastMonthByDz();
var resultByJumpType = _statsService.GetStatsForLastMonthByJumpType();
var result = new StatisticForLastMonthResp();
result.ByDz = _mapper.Map<IEnumerable<StatisticResp>>(resultByDz);
result.ByJumpType = _mapper.Map<IEnumerable<StatisticResp>>(resultByJumpType);
return result;
}
[HttpGet("ForLastYear")]
[EnableCors]
public StatisticForLastYearResp ForLastYear()
{
var resultByDz = _statsService.GetStatsForLastYearByDz();
var resultByJumpType = _statsService.GetStatsForLastYearByJumpType();
var result = new StatisticForLastYearResp();
result.ByDz = _mapper.Map<IEnumerable<StatisticResp>>(resultByDz);
result.ByJumpType = _mapper.Map<IEnumerable<StatisticResp>>(resultByJumpType);
return result;
}
[HttpGet("ByYearByJumpType")]
[EnableCors]
public IEnumerable<StatisticForChartResp> ByYearByJumpType()
{
var result = _statsService.GetStatsByYearByJumpType();
return _mapper.Map<IEnumerable<StatisticForChartResp>>(result);
}
[HttpGet("Reset")]
[EnableCors]
public void Reset()
{
_statsService.Reset();
}
[HttpGet("Simple")]
[EnableCors]
public SimpleSummaryResp Simple()
{
var result = _statsService.GetSimpleSummary();
return _mapper.Map<SimpleSummaryResp>(result);
}
#endregion Public Methods
#region Private properties
private readonly IMapper _mapper;
private readonly IStatsService _statsService;
#endregion Private properties
}
}