From 6a5e9020d55badc0e01c583e48ac0620688bc244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Tue, 3 Mar 2020 15:45:36 +0100 Subject: [PATCH] Add an action to retrieve un simple summary with the total of jumps and the last jump --- .../Interface/IStatsService.cs | 2 ++ Back/skydiveLogs-api.Business/StatsService.cs | 14 ++++++++++++++ Back/skydiveLogs-api.Model/SimpleSummary.cs | 11 +++++++++++ Back/skydiveLogs-api.Model/Statistic.cs | 6 +----- .../skydiveLogs-api/Controllers/StatsController.cs | 9 +++++++++ .../DataContract/SimpleSummaryResp.cs | 11 +++++++++++ Back/skydiveLogs-api/Mapper/ModelProfile.cs | 2 ++ 7 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 Back/skydiveLogs-api.Model/SimpleSummary.cs create mode 100644 Back/skydiveLogs-api/DataContract/SimpleSummaryResp.cs diff --git a/Back/skydiveLogs-api.Business/Interface/IStatsService.cs b/Back/skydiveLogs-api.Business/Interface/IStatsService.cs index 2f23af2..2b20d23 100644 --- a/Back/skydiveLogs-api.Business/Interface/IStatsService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IStatsService.cs @@ -22,5 +22,7 @@ namespace skydiveLogs_api.Business.Interface IEnumerable GetStatsForLastMonthByDz(); IEnumerable GetStatsForLastMonthByJumpType(); + + SimpleSummary GetSimpleSummary(); } } diff --git a/Back/skydiveLogs-api.Business/StatsService.cs b/Back/skydiveLogs-api.Business/StatsService.cs index 1475135..3173042 100644 --- a/Back/skydiveLogs-api.Business/StatsService.cs +++ b/Back/skydiveLogs-api.Business/StatsService.cs @@ -159,6 +159,20 @@ namespace skydiveLogs_api.Business .ToList(); } + public SimpleSummary GetSimpleSummary() + { + var allJumps = _jumpRepository.GetAll(); + + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); + + return new SimpleSummary + { + LastJump = lastJump, + TotalJumps = allJumps.Count(), + TotalCutaway = allJumps.Where(j => j.WithCutaway).Count() + }; + } + private readonly IJumpRepository _jumpRepository; } } diff --git a/Back/skydiveLogs-api.Model/SimpleSummary.cs b/Back/skydiveLogs-api.Model/SimpleSummary.cs new file mode 100644 index 0000000..0e74190 --- /dev/null +++ b/Back/skydiveLogs-api.Model/SimpleSummary.cs @@ -0,0 +1,11 @@ +namespace skydiveLogs_api.Model +{ + public class SimpleSummary + { + public int TotalJumps { get; set; } + + public int TotalCutaway { get; set; } + + public Jump LastJump { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Model/Statistic.cs b/Back/skydiveLogs-api.Model/Statistic.cs index 197b4aa..7aacd02 100644 --- a/Back/skydiveLogs-api.Model/Statistic.cs +++ b/Back/skydiveLogs-api.Model/Statistic.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace skydiveLogs_api.Model +namespace skydiveLogs_api.Model { public class Statistic { diff --git a/Back/skydiveLogs-api/Controllers/StatsController.cs b/Back/skydiveLogs-api/Controllers/StatsController.cs index a7c1780..f831730 100644 --- a/Back/skydiveLogs-api/Controllers/StatsController.cs +++ b/Back/skydiveLogs-api/Controllers/StatsController.cs @@ -21,6 +21,15 @@ namespace skydiveLogs_api.Controllers _mapper = mapper; } + [HttpGet("Simple")] + [EnableCors] + public SimpleSummaryResp Simple() + { + var result = _statsService.GetSimpleSummary(); + + return _mapper.Map(result); + } + [HttpGet("ByDz")] [EnableCors] public IEnumerable ByDz() diff --git a/Back/skydiveLogs-api/DataContract/SimpleSummaryResp.cs b/Back/skydiveLogs-api/DataContract/SimpleSummaryResp.cs new file mode 100644 index 0000000..d52674e --- /dev/null +++ b/Back/skydiveLogs-api/DataContract/SimpleSummaryResp.cs @@ -0,0 +1,11 @@ +namespace skydiveLogs_api.DataContract +{ + public class SimpleSummaryResp + { + public int TotalJumps { get; set; } + + public int TotalCutaway { get; set; } + + public JumpResp LastJump { get; set; } + } +} diff --git a/Back/skydiveLogs-api/Mapper/ModelProfile.cs b/Back/skydiveLogs-api/Mapper/ModelProfile.cs index 0e99c05..68f60f2 100644 --- a/Back/skydiveLogs-api/Mapper/ModelProfile.cs +++ b/Back/skydiveLogs-api/Mapper/ModelProfile.cs @@ -18,6 +18,8 @@ namespace skydiveLogs_api.Mapper CreateMap(); CreateMap(); CreateMap(); + + CreateMap(); } } }