diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByAircraftService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByAircraftService.cs new file mode 100644 index 0000000..84ad3af --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByAircraftService.cs @@ -0,0 +1,14 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByAircraftService + { + #region Public Methods + + IEnumerable GetStats(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByAircraftService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByAircraftService.cs new file mode 100644 index 0000000..bb74b3d --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByAircraftService.cs @@ -0,0 +1,100 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; +using System.Linq; + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsByByAircraftService : IStatsByAircraftService + { + #region Public Constructors + + public StatsByByAircraftService(IJumpService jumpService, + IIdentityService identityService, + IStatsByAircraftRepository statsByAircraftRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByAircraftRepository = statsByAircraftRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + // var allStats = GetAllStats(); + // if (!allStats.ByDz.Any()) + // { + // var allJumps = _jumpService.GetAllJumps(); + // var results = new List(); + + // if (allJumps.Any()) + // { + // results = [.. allJumps.GroupBy(j => j.DropZone.Name, + // j => j, + // (groupby, jumps) => new Statistic + // { + // Label = groupby.ToString(), + // Nb = jumps.Count() + // })]; + // } + + // allStats.ByDz = results; + // _userStatsRepository.Update(allStats); + // } + + // return allStats.ByDz; + return null; + } + + // public void Reset() + // { + // 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; + // myStats.ByYearByJumpType = resetStats.ByYearByJumpType; + + // _userStatsRepository.Update(myStats); + // } + + #endregion Public Methods + + #region Private Methods + + private UserStats GetAllStats() + { + var allStats = _statsByAircraftRepository.GetAll(_identityService.ConnectedUser); + if (allStats == null) + { + allStats = new UserStats + { + User = _identityService.ConnectedUser + }; + _statsByAircraftRepository.Add(allStats); + } + + return allStats; + } + + #endregion Private Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByAircraftRepository _statsByAircraftRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsByAircraftRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByAircraftRepository.cs new file mode 100644 index 0000000..f1e038f --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByAircraftRepository.cs @@ -0,0 +1,13 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsByAircraftRepository : IRepository + { + #region Public Methods + + StatsByAircraft GetAll(User user); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/StatsByAircraftRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsByAircraftRepository.cs new file mode 100644 index 0000000..8cb46b4 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/StatsByAircraftRepository.cs @@ -0,0 +1,77 @@ +using LiteDB; +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Infrastructure.Interfaces; +using System.Collections.Generic; + +namespace skydiveLogs_api.Infrastructure +{ + public class StatsByAircraftRepository : IStatsByAircraftRepository + { + #region Public Constructors + + public StatsByAircraftRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfStatsByAircraft; + } + + #endregion Public Constructors + + #region Public Methods + + public int Add(StatsByAircraft newStats) + { + int result; + + try + { + var tmp = _col.Insert(newStats); + result = tmp.AsInt32; + } + catch + { + result = 0; + } + + return result; + } + + public IEnumerable GetAll() + { + throw new System.NotImplementedException(); + } + + public StatsByAircraft GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .SingleOrDefault(); + } + + public StatsByAircraft GetById(int id) + { + throw new System.NotImplementedException(); + } + + public int GetCount() + { + throw new System.NotImplementedException(); + } + + public bool Update(StatsByAircraft stats) + { + return _col.Update(stats); + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file