Add a feature to reset the user statistics.

This commit is contained in:
Sébastien André
2021-08-14 23:12:28 +02:00
parent 4c1dc89006
commit ce6dad44ce
4 changed files with 24 additions and 9 deletions

View File

@@ -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<Jump> 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
}

View File

@@ -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

View File

@@ -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);
}

View File

@@ -95,6 +95,13 @@ namespace skydiveLogs_api.Controllers
return result;
}
[HttpGet("Reset")]
[EnableCors]
public void Reset()
{
_statsService.Reset();
}
[HttpGet("Simple")]
[EnableCors]
public SimpleSummaryResp Simple()