Add controler actions to return stats for
the current season
This commit is contained in:
@@ -14,5 +14,13 @@ namespace skydiveLogs_api.Business.Interface
|
|||||||
IEnumerable<Statistic> GetStatsByGear();
|
IEnumerable<Statistic> GetStatsByGear();
|
||||||
|
|
||||||
IEnumerable<Statistic> GetStatsByYear();
|
IEnumerable<Statistic> GetStatsByYear();
|
||||||
|
|
||||||
|
IEnumerable<Statistic> GetStatsForLastYearByDz();
|
||||||
|
|
||||||
|
IEnumerable<Statistic> GetStatsForLastYearByJumpType();
|
||||||
|
|
||||||
|
IEnumerable<Statistic> GetStatsForLastMonthByDz();
|
||||||
|
|
||||||
|
IEnumerable<Statistic> GetStatsForLastMonthByJumpType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,80 @@ namespace skydiveLogs_api.Business
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||||
|
{
|
||||||
|
var allJumps = _jumpRepository.GetAll();
|
||||||
|
|
||||||
|
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault();
|
||||||
|
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||||
|
|
||||||
|
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||||
|
.GroupBy(j => j.DropZone.Name,
|
||||||
|
j => j,
|
||||||
|
(groupby, jumps) => new Statistic
|
||||||
|
{
|
||||||
|
Label = groupby.ToString(),
|
||||||
|
Nb = jumps.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||||
|
{
|
||||||
|
var allJumps = _jumpRepository.GetAll();
|
||||||
|
|
||||||
|
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault();
|
||||||
|
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||||
|
|
||||||
|
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||||
|
.GroupBy(j => j.JumpType.Name,
|
||||||
|
j => j,
|
||||||
|
(groupby, jumps) => new Statistic
|
||||||
|
{
|
||||||
|
Label = groupby.ToString(),
|
||||||
|
Nb = jumps.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||||
|
{
|
||||||
|
var allJumps = _jumpRepository.GetAll();
|
||||||
|
|
||||||
|
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault();
|
||||||
|
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||||
|
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||||
|
|
||||||
|
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
|
||||||
|
.GroupBy(j => j.DropZone.Name,
|
||||||
|
j => j,
|
||||||
|
(groupby, jumps) => new Statistic
|
||||||
|
{
|
||||||
|
Label = groupby.ToString(),
|
||||||
|
Nb = jumps.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||||
|
{
|
||||||
|
var allJumps = _jumpRepository.GetAll();
|
||||||
|
|
||||||
|
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault();
|
||||||
|
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||||
|
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||||
|
|
||||||
|
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
|
||||||
|
.GroupBy(j => j.JumpType.Name,
|
||||||
|
j => j,
|
||||||
|
(groupby, jumps) => new Statistic
|
||||||
|
{
|
||||||
|
Label = groupby.ToString(),
|
||||||
|
Nb = jumps.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
private readonly IJumpRepository _jumpRepository;
|
private readonly IJumpRepository _jumpRepository;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,34 @@ namespace skydiveLogs_api.Controllers
|
|||||||
return _mapper.Map<IEnumerable<StatisticResp>>(result);
|
return _mapper.Map<IEnumerable<StatisticResp>>(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("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;
|
||||||
|
}
|
||||||
|
|
||||||
#region Private properties
|
#region Private properties
|
||||||
private readonly IStatsService _statsService;
|
private readonly IStatsService _statsService;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace skydiveLogs_api.DataContract
|
||||||
|
{
|
||||||
|
public class StatisticForLastMonthResp
|
||||||
|
{
|
||||||
|
public IEnumerable<StatisticResp> ByDz { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<StatisticResp> ByJumpType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace skydiveLogs_api.DataContract
|
||||||
|
{
|
||||||
|
public class StatisticForLastYearResp
|
||||||
|
{
|
||||||
|
public IEnumerable<StatisticResp> ByDz { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<StatisticResp> ByJumpType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user