From ce6dad44ceb033842f9b2db1a27029f34d914378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Sat, 14 Aug 2021 23:12:28 +0200 Subject: [PATCH] Add a feature to reset the user statistics. --- .../JumpService.cs | 7 +------ .../StatsService.cs | 16 +++++++++++++--- .../UserStatsRepository.cs | 3 +++ .../Controllers/StatsController.cs | 7 +++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Back/skydiveLogs-api.DomainBusiness/JumpService.cs b/Back/skydiveLogs-api.DomainBusiness/JumpService.cs index e385143..ca2ce4e 100644 --- a/Back/skydiveLogs-api.DomainBusiness/JumpService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/JumpService.cs @@ -14,8 +14,7 @@ namespace skydiveLogs_api.DomainBusiness IDropZoneService dropZoneService, IGearService gearService, IJumpRepository jumpRepository, - IIdentityService identityService, - IStatsService statsService) + IIdentityService identityService) { _jumpTypeService = jumpTypeService; _aircraftService = aircraftService; @@ -23,7 +22,6 @@ namespace skydiveLogs_api.DomainBusiness _gearService = gearService; _jumpRepository = jumpRepository; _identityService = identityService; - _statsService = statsService; } #endregion Public Constructors @@ -48,13 +46,11 @@ namespace skydiveLogs_api.DomainBusiness jump.User = _identityService.ConnectedUser; _jumpRepository.Add(jump); - _statsService.Reset(); } public void DeleteJumpById(int id) { _jumpRepository.DeleteById(id); - _statsService.Reset(); } public IEnumerable GetAllJumps() @@ -87,7 +83,6 @@ namespace skydiveLogs_api.DomainBusiness private readonly IIdentityService _identityService; private readonly IJumpRepository _jumpRepository; private readonly IJumpTypeService _jumpTypeService; - private readonly IStatsService _statsService; #endregion Private Fields } diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs index 4e8f2e5..a2684ef 100644 --- a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs @@ -306,9 +306,19 @@ namespace skydiveLogs_api.DomainBusiness public void Reset() { - var tmp = new UserStats(); - tmp.User = _identityService.ConnectedUser; - _userStatsRepository.Add(tmp); + var resetStats = new UserStats(); + var myStats = GetAllStats(); + myStats.ByAircraft = resetStats.ByAircraft; + myStats.ByDz = resetStats.ByDz; + myStats.ByGear = resetStats.ByGear; + myStats.ByJumpType = resetStats.ByJumpType; + myStats.ByYear = resetStats.ByYear; + myStats.ForLastMonthByDz = resetStats.ForLastMonthByDz; + myStats.ForLastMonthByJumpType = resetStats.ForLastMonthByJumpType; + myStats.ForLastYearByDz = resetStats.ForLastYearByDz; + myStats.ForLastYearByJumpType = resetStats.ForLastYearByJumpType; + + _userStatsRepository.Update(myStats); } #endregion Public Methods diff --git a/Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs b/Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs index db31985..e6dff83 100644 --- a/Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs @@ -57,6 +57,9 @@ namespace skydiveLogs_api.Infrastructure public bool Update(UserStats stats) { + //col.UpdateMany(x => new Customer { Name + // = x.Name.ToUpper(), Salary: 100 }, x => x.Name == "John") + return _col.Update(stats); } diff --git a/Back/skydiveLogs-api/Controllers/StatsController.cs b/Back/skydiveLogs-api/Controllers/StatsController.cs index 5a50ffc..eb5235e 100644 --- a/Back/skydiveLogs-api/Controllers/StatsController.cs +++ b/Back/skydiveLogs-api/Controllers/StatsController.cs @@ -95,6 +95,13 @@ namespace skydiveLogs_api.Controllers return result; } + [HttpGet("Reset")] + [EnableCors] + public void Reset() + { + _statsService.Reset(); + } + [HttpGet("Simple")] [EnableCors] public SimpleSummaryResp Simple()