diff --git a/Back/skydiveLogs-api.Domain/UserStats.cs b/Back/skydiveLogs-api.Domain/UserStats.cs index 19c158f..0303b74 100644 --- a/Back/skydiveLogs-api.Domain/UserStats.cs +++ b/Back/skydiveLogs-api.Domain/UserStats.cs @@ -17,6 +17,7 @@ namespace skydiveLogs_api.Domain ForLastMonthByJumpType = new List(); ForLastYearByDz = new List(); ForLastYearByJumpType = new List(); + ByYearByJumpType = new List(); } #endregion Public Constructors @@ -32,6 +33,7 @@ namespace skydiveLogs_api.Domain public IEnumerable ForLastMonthByJumpType { get; set; } public IEnumerable ForLastYearByDz { get; set; } public IEnumerable ForLastYearByJumpType { get; set; } + public IEnumerable ByYearByJumpType { get; set; } public int Id { get; set; } public User User { get; set; } diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs index 343a97e..a04913b 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs @@ -26,6 +26,9 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces IEnumerable GetStatsForLastYearByDz(); IEnumerable GetStatsForLastYearByJumpType(); + + IEnumerable GetStatsByYearByJumpType(); + void Reset(); #endregion Public Methods diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs index a2684ef..378f69a 100644 --- a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs @@ -304,6 +304,34 @@ namespace skydiveLogs_api.DomainBusiness return allStats.ForLastYearByJumpType; } + public IEnumerable GetStatsByYearByJumpType() + { + var allStats = GetAllStats(); + if (!allStats.ByYearByJumpType.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year }, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.Year.ToString(), + Label2 = groupby.Name.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + allStats.ByYearByJumpType = results; + _userStatsRepository.Update(allStats); + } + + return allStats.ByYearByJumpType; + } + public void Reset() { var resetStats = new UserStats(); diff --git a/Back/skydiveLogs-api/Controllers/StatsController.cs b/Back/skydiveLogs-api/Controllers/StatsController.cs index eb5235e..f934d16 100644 --- a/Back/skydiveLogs-api/Controllers/StatsController.cs +++ b/Back/skydiveLogs-api/Controllers/StatsController.cs @@ -95,6 +95,15 @@ namespace skydiveLogs_api.Controllers return result; } + [HttpGet("ByYearByJumpType")] + [EnableCors] + public IEnumerable ByYearByJumpType() + { + var result = _statsService.GetStatsByYearByJumpType(); + + return _mapper.Map>(result); + } + [HttpGet("Reset")] [EnableCors] public void Reset()