diff --git a/Back/skydiveLogs-api.Business/ImageService.cs b/Back/skydiveLogs-api.Business/ImageService.cs index 4b2848a..7ff4073 100644 --- a/Back/skydiveLogs-api.Business/ImageService.cs +++ b/Back/skydiveLogs-api.Business/ImageService.cs @@ -31,9 +31,9 @@ namespace skydiveLogs_api.Business return _imageRepository.GetById(id); } - public IEnumerable GetAllImages() + public IEnumerable GetAllImages(User connectedUser) { - return _imageRepository.GetAll(); + return _imageRepository.GetAll(connectedUser); } public void UpdateImage(int id, Image Image) diff --git a/Back/skydiveLogs-api.Business/Interface/IImageService.cs b/Back/skydiveLogs-api.Business/Interface/IImageService.cs index e87ceb1..716e335 100644 --- a/Back/skydiveLogs-api.Business/Interface/IImageService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IImageService.cs @@ -7,7 +7,7 @@ namespace skydiveLogs_api.Business.Interface { public interface IImageService { - IEnumerable GetAllImages(); + IEnumerable GetAllImages(User connectedUser); Image GetImageById(int id); diff --git a/Back/skydiveLogs-api.Business/StatsService.cs b/Back/skydiveLogs-api.Business/StatsService.cs index f55acfb..d1ca193 100644 --- a/Back/skydiveLogs-api.Business/StatsService.cs +++ b/Back/skydiveLogs-api.Business/StatsService.cs @@ -18,159 +18,219 @@ namespace skydiveLogs_api.Business public IEnumerable GetStatsByAircraft(User connectedUser) { var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); - return allJumps.GroupBy(j => j.Aircraft.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; } public IEnumerable GetStatsByDz(User connectedUser) { var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); - return allJumps.GroupBy(j => j.DropZone.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; } public IEnumerable GetStatsByJumpType(User connectedUser) { var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); - return allJumps.GroupBy(j => j.JumpType.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; } public IEnumerable GetStatsByGear(User connectedUser) { var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); - return allJumps.GroupBy(j => j.Gear.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => j.Gear.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; } public IEnumerable GetStatsByYear(User connectedUser) { var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); - return allJumps.GroupBy(j => j.JumpDate.Year, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; } public IEnumerable GetStatsForLastYearByDz(User connectedUser) { var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); - var yearOfLastJump = lastJump.JumpDate.Year; + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + 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(); + results = 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(); + } + + return results; } public IEnumerable GetStatsForLastYearByJumpType(User connectedUser) { var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); - var yearOfLastJump = lastJump.JumpDate.Year; + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + 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(); + results = 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(); + } + + return results; } public IEnumerable GetStatsForLastMonthByDz(User connectedUser) { var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); - var yearOfLastJump = lastJump.JumpDate.Year; - var monthOfLastJump = lastJump.JumpDate.Month; + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + 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(); + results = 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(); + } + + return results; } public IEnumerable GetStatsForLastMonthByJumpType(User connectedUser) { var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); - var yearOfLastJump = lastJump.JumpDate.Year; - var monthOfLastJump = lastJump.JumpDate.Month; + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + 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(); + results = 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(); + } + + return results; } public SimpleSummary GetSimpleSummary(User connectedUser) { var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new SimpleSummary(); - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); - - return new SimpleSummary + if (allJumps.Any()) { - LastJump = lastJump, - TotalJumps = allJumps.Count(), - TotalCutaways = allJumps.Where(j => j.WithCutaway).Count() - }; + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + + results = new SimpleSummary + { + LastJump = lastJump, + TotalJumps = allJumps.Count(), + TotalCutaways = allJumps.Where(j => j.WithCutaway).Count() + }; + } + + return results; } private readonly IJumpService _jumpService; diff --git a/Back/skydiveLogs-api/Controllers/ImageController.cs b/Back/skydiveLogs-api/Controllers/ImageController.cs index 9d9ba94..df33e59 100644 --- a/Back/skydiveLogs-api/Controllers/ImageController.cs +++ b/Back/skydiveLogs-api/Controllers/ImageController.cs @@ -25,7 +25,7 @@ namespace skydiveLogs_api.Controllers [EnableCors] public IEnumerable Get() { - var result = _imageService.GetAllImages(); + var result = _imageService.GetAllImages(ConnectedUser); return _mapper.Map>(result); }