diff --git a/Back/.editorconfig b/Back/.editorconfig new file mode 100644 index 0000000..9b73521 --- /dev/null +++ b/Back/.editorconfig @@ -0,0 +1,13 @@ +# Editor configuration, see http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/Back/skydiveLogs-api.Domain/StatsByAircraft.cs b/Back/skydiveLogs-api.Domain/StatsByAircraft.cs new file mode 100644 index 0000000..6bf377b --- /dev/null +++ b/Back/skydiveLogs-api.Domain/StatsByAircraft.cs @@ -0,0 +1,13 @@ +namespace skydiveLogs_api.Domain +{ + public class StatsByAircraft + { + public string Aircraft { get; set; } + + public int Nb { get; set; } + + public int Id { get; set; } + + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/StatsByDz.cs b/Back/skydiveLogs-api.Domain/StatsByDz.cs new file mode 100644 index 0000000..92c7b5f --- /dev/null +++ b/Back/skydiveLogs-api.Domain/StatsByDz.cs @@ -0,0 +1,13 @@ +namespace skydiveLogs_api.Domain +{ + public class StatsByDz + { + public string DropZone { get; set; } + + public int Nb { get; set; } + + public int Id { get; set; } + + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/StatsByGear.cs b/Back/skydiveLogs-api.Domain/StatsByGear.cs new file mode 100644 index 0000000..0bf97ff --- /dev/null +++ b/Back/skydiveLogs-api.Domain/StatsByGear.cs @@ -0,0 +1,13 @@ +namespace skydiveLogs_api.Domain +{ + public class StatsByGear + { + public string Gear { get; set; } + + public int Nb { get; set; } + + public int Id { get; set; } + + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/StatsByJumpType.cs b/Back/skydiveLogs-api.Domain/StatsByJumpType.cs new file mode 100644 index 0000000..cf1bc6c --- /dev/null +++ b/Back/skydiveLogs-api.Domain/StatsByJumpType.cs @@ -0,0 +1,13 @@ +namespace skydiveLogs_api.Domain +{ + public class StatsByJumpType + { + public string JumpType { get; set; } + + public int Nb { get; set; } + + public int Id { get; set; } + + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/StatsByYear.cs b/Back/skydiveLogs-api.Domain/StatsByYear.cs new file mode 100644 index 0000000..e05cd32 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/StatsByYear.cs @@ -0,0 +1,13 @@ +namespace skydiveLogs_api.Domain +{ + public class StatsByYear + { + public string Year { get; set; } + + public int Nb { get; set; } + + public int Id { get; set; } + + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/StatsByYearByJumpType.cs b/Back/skydiveLogs-api.Domain/StatsByYearByJumpType.cs new file mode 100644 index 0000000..c930e53 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/StatsByYearByJumpType.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace skydiveLogs_api.Domain +{ + public class StatsByYearByJumpType + { + public string Year { get; set; } + + public string JumpType { get; set; } + + public int Nb { get; set; } + + public int Id { get; set; } + + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/StatsForLastMonthByDz.cs b/Back/skydiveLogs-api.Domain/StatsForLastMonthByDz.cs new file mode 100644 index 0000000..bde99f8 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/StatsForLastMonthByDz.cs @@ -0,0 +1,13 @@ +namespace skydiveLogs_api.Domain +{ + public class StatsForLastMonthByDz + { + public string DropZone { get; set; } + + public int Nb { get; set; } + + public int Id { get; set; } + + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/StatsForLastMonthByJumpType.cs b/Back/skydiveLogs-api.Domain/StatsForLastMonthByJumpType.cs new file mode 100644 index 0000000..cc4dd6b --- /dev/null +++ b/Back/skydiveLogs-api.Domain/StatsForLastMonthByJumpType.cs @@ -0,0 +1,13 @@ +namespace skydiveLogs_api.Domain +{ + public class StatsForLastMonthByJumpType + { + public string JumpType { get; set; } + + public int Nb { get; set; } + + public int Id { get; set; } + + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/StatsForLastYearByDz.cs b/Back/skydiveLogs-api.Domain/StatsForLastYearByDz.cs new file mode 100644 index 0000000..2730b00 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/StatsForLastYearByDz.cs @@ -0,0 +1,13 @@ +namespace skydiveLogs_api.Domain +{ + public class StatsForLastYearByDz + { + public string DropZone { get; set; } + + public int Nb { get; set; } + + public int Id { get; set; } + + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/StatsForLastYearByJumpType.cs b/Back/skydiveLogs-api.Domain/StatsForLastYearByJumpType.cs new file mode 100644 index 0000000..2a5556f --- /dev/null +++ b/Back/skydiveLogs-api.Domain/StatsForLastYearByJumpType.cs @@ -0,0 +1,13 @@ +namespace skydiveLogs_api.Domain +{ + public class StatsForLastYearByJumpType + { + public string JumpType { get; set; } + + public int Nb { get; set; } + + public int Id { get; set; } + + public User User { get; set; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/UserStats.cs b/Back/skydiveLogs-api.Domain/UserStats.cs deleted file mode 100644 index 0303b74..0000000 --- a/Back/skydiveLogs-api.Domain/UserStats.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Collections.Generic; - -namespace skydiveLogs_api.Domain -{ - public class UserStats - { - #region Public Constructors - - public UserStats() - { - ByAircraft = new List(); - ByDz = new List(); - ByGear = new List(); - ByJumpType = new List(); - ByYear = new List(); - ForLastMonthByDz = new List(); - ForLastMonthByJumpType = new List(); - ForLastYearByDz = new List(); - ForLastYearByJumpType = new List(); - ByYearByJumpType = new List(); - } - - #endregion Public Constructors - - #region Public Properties - - public IEnumerable ByAircraft { get; set; } - public IEnumerable ByDz { get; set; } - public IEnumerable ByGear { get; set; } - public IEnumerable ByJumpType { get; set; } - public IEnumerable ByYear { get; set; } - public IEnumerable ForLastMonthByDz { get; set; } - public IEnumerable ForLastMonthByJumpType { get; set; } - public IEnumerable ForLastYearByDz { get; set; } - public IEnumerable ForLastYearByJumpType { get; set; } - public IEnumerable ByYearByJumpType { get; set; } - public int Id { get; set; } - public User User { get; set; } - - #endregion Public Properties - } -} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByAircraftService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByAircraftService.cs new file mode 100644 index 0000000..d998a39 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByAircraftService.cs @@ -0,0 +1,16 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByAircraftService + { + #region Public Methods + + IEnumerable GetStats(); + + void Reset(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByDzService.cs new file mode 100644 index 0000000..34c41f8 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByDzService.cs @@ -0,0 +1,16 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByDzService + { + #region Public Methods + + IEnumerable GetStats(); + + void Reset(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByGearService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByGearService.cs new file mode 100644 index 0000000..0a83b28 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByGearService.cs @@ -0,0 +1,16 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByGearService + { + #region Public Methods + + IEnumerable GetStats(); + + void Reset(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByJumpTypeService.cs new file mode 100644 index 0000000..0857475 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByJumpTypeService.cs @@ -0,0 +1,16 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByJumpTypeService + { + #region Public Methods + + IEnumerable GetStats(); + + void Reset(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearByJumpTypeService.cs new file mode 100644 index 0000000..152be31 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearByJumpTypeService.cs @@ -0,0 +1,16 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByYearByJumpTypeService + { + #region Public Methods + + IEnumerable GetStats(); + + void Reset(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearService.cs new file mode 100644 index 0000000..39fc2e4 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByYearService.cs @@ -0,0 +1,15 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsByYearService + { + #region Public Methods + IEnumerable GetStats(); + + void Reset(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByDzService.cs new file mode 100644 index 0000000..c7c9cbc --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByDzService.cs @@ -0,0 +1,16 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsForLastMonthByDzService + { + #region Public Methods + + IEnumerable GetStats(); + + void Reset(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByJumpTypeService.cs new file mode 100644 index 0000000..581bc78 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastMonthByJumpTypeService.cs @@ -0,0 +1,16 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsForLastMonthByJumpTypeService + { + #region Public Methods + + IEnumerable GetStats(); + + void Reset(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByDzService.cs new file mode 100644 index 0000000..19533a2 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByDzService.cs @@ -0,0 +1,16 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsForLastYearByDzService + { + #region Public Methods + + IEnumerable GetStats(); + + void Reset(); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByJumpTypeService.cs new file mode 100644 index 0000000..a2d20d8 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsForLastYearByJumpTypeService.cs @@ -0,0 +1,16 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsForLastYearByJumpTypeService + { + #region Public Methods + + IEnumerable GetStats(); + + void Reset(); + + #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..2815abd --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByAircraftService.cs @@ -0,0 +1,68 @@ +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 StatsByAircraftService : IStatsByAircraftService + { + #region Public Constructors + + public StatsByAircraftService(IJumpService jumpService, + IIdentityService identityService, + IStatsByAircraftRepository statsByAircraftRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByAircraftRepository = statsByAircraftRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + var allStats = _statsByAircraftRepository.GetAll(_identityService.ConnectedUser); + if (!allStats.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new StatsByAircraft + { + Aircraft = groupby.ToString(), + Nb = jumps.Count(), + User = _identityService.ConnectedUser + })]; + } + + _statsByAircraftRepository.Add(results); + return results; + } + + return allStats; + } + + public void Reset() + { + _statsByAircraftRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public 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.DomainBusiness/StatsByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByDzService.cs new file mode 100644 index 0000000..c8046b4 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByDzService.cs @@ -0,0 +1,68 @@ +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 StatsByDzService : IStatsByDzService + { + #region Public Constructors + + public StatsByDzService(IJumpService jumpService, + IIdentityService identityService, + IStatsByDzRepository statsByDzRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByDzRepository = statsByDzRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + var allStats = _statsByDzRepository.GetAll(_identityService.ConnectedUser); + if (!allStats.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new StatsByDz + { + DropZone = groupby.ToString(), + Nb = jumps.Count(), + User = _identityService.ConnectedUser + })]; + } + + _statsByDzRepository.Add(results); + return results; + } + + return allStats; + } + + public void Reset() + { + _statsByDzRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByDzRepository _statsByDzRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByGearService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByGearService.cs new file mode 100644 index 0000000..90d045c --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByGearService.cs @@ -0,0 +1,68 @@ +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 StatsByGearService : IStatsByGearService + { + #region Public Constructors + + public StatsByGearService(IJumpService jumpService, + IIdentityService identityService, + IStatsByGearRepository statsByGearRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByGearRepository = statsByGearRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + var allStats = _statsByGearRepository.GetAll(_identityService.ConnectedUser); + if (!allStats.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", + j => j, + (groupby, jumps) => new StatsByGear + { + Gear = groupby.ToString(), + Nb = jumps.Count(), + User = _identityService.ConnectedUser + })]; + } + + _statsByGearRepository.Add(results); + return results; + } + + return allStats; + } + + public void Reset() + { + _statsByGearRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByGearRepository _statsByGearRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByJumpTypeService.cs new file mode 100644 index 0000000..831016e --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByJumpTypeService.cs @@ -0,0 +1,68 @@ +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 StatsByJumpTypeService : IStatsByJumpTypeService + { + #region Public Constructors + + public StatsByJumpTypeService(IJumpService jumpService, + IIdentityService identityService, + IStatsByJumpTypeRepository statsByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByJumpTypeRepository = statsByJumpTypeRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + var allStats = _statsByJumpTypeRepository.GetAll(_identityService.ConnectedUser); + if (!allStats.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new StatsByJumpType + { + JumpType = groupby.ToString(), + Nb = jumps.Count(), + User = _identityService.ConnectedUser + })]; + } + + _statsByJumpTypeRepository.Add(results); + return results; + } + + return allStats; + } + + public void Reset() + { + _statsByJumpTypeRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByYearByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByYearByJumpTypeService.cs new file mode 100644 index 0000000..1920469 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByYearByJumpTypeService.cs @@ -0,0 +1,69 @@ +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 StatsByYearByJumpTypeService : IStatsByYearByJumpTypeService + { + #region Public Constructors + + public StatsByYearByJumpTypeService(IJumpService jumpService, + IIdentityService identityService, + IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + var allStats = _statsByYearByJumpTypeRepository.GetAll(_identityService.ConnectedUser); + if (!allStats.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year }, + j => j, + (groupby, jumps) => new StatsByYearByJumpType + { + Year = groupby.Year.ToString(), + JumpType = groupby.Name.ToString(), + Nb = jumps.Count(), + User = _identityService.ConnectedUser + })]; + } + + _statsByYearByJumpTypeRepository.Add(results); + return results; + } + + return allStats; + } + + public void Reset() + { + _statsByYearByJumpTypeRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByYearService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByYearService.cs new file mode 100644 index 0000000..81bb2a0 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByYearService.cs @@ -0,0 +1,68 @@ +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 StatsByYearService : IStatsByYearService + { + #region Public Constructors + + public StatsByYearService(IJumpService jumpService, + IIdentityService identityService, + IStatsByYearRepository statsByYearRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsByYearRepository = statsByYearRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + var allStats = _statsByYearRepository.GetAll(_identityService.ConnectedUser); + if (!allStats.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + results = [.. allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new StatsByYear + { + Year = groupby.ToString(), + Nb = jumps.Count(), + User = _identityService.ConnectedUser + })]; + } + + _statsByYearRepository.Add(results); + return results; + } + + return allStats; + } + + public void Reset() + { + _statsByYearRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsByYearRepository _statsByYearRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByDzService.cs new file mode 100644 index 0000000..5cbfdca --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByDzService.cs @@ -0,0 +1,73 @@ +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 StatsForLastMonthByDzService : IStatsForLastMonthByDzService + { + #region Public Constructors + + public StatsForLastMonthByDzService(IJumpService jumpService, + IIdentityService identityService, + IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsForLastMonthByDzRepository = statsForLastMonthByDzRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + var allStats = _statsForLastMonthByDzRepository.GetAll(_identityService.ConnectedUser); + if (!allStats.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new StatsForLastMonthByDz + { + DropZone = groupby.ToString(), + Nb = jumps.Count(), + User = _identityService.ConnectedUser + })]; + } + + _statsForLastMonthByDzRepository.Add(results); + return results; + } + + return allStats; + } + + public void Reset() + { + _statsForLastMonthByDzRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByJumpTypeService.cs new file mode 100644 index 0000000..9f89577 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByJumpTypeService.cs @@ -0,0 +1,73 @@ +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 StatsForLastMonthByJumpTypeService : IStatsForLastMonthByJumpTypeService + { + #region Public Constructors + + public StatsForLastMonthByJumpTypeService(IJumpService jumpService, + IIdentityService identityService, + IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + var allStats = _statsForLastMonthByJumpTypeRepository.GetAll(_identityService.ConnectedUser); + if (!allStats.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new StatsForLastMonthByJumpType + { + JumpType = groupby.ToString(), + Nb = jumps.Count(), + User = _identityService.ConnectedUser + })]; + } + + _statsForLastMonthByJumpTypeRepository.Add(results); + return results; + } + + return allStats; + } + + public void Reset() + { + _statsForLastMonthByJumpTypeRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByDzService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByDzService.cs new file mode 100644 index 0000000..6b44295 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByDzService.cs @@ -0,0 +1,72 @@ +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 StatsForLastYearByDzService : IStatsForLastYearByDzService + { + #region Public Constructors + + public StatsForLastYearByDzService(IJumpService jumpService, + IIdentityService identityService, + IStatsForLastYearByDzRepository statsForLastYearByDzRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsForLastYearByDzRepository = statsForLastYearByDzRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + var allStats = _statsForLastYearByDzRepository.GetAll(_identityService.ConnectedUser); + if (!allStats.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new StatsForLastYearByDz + { + DropZone = groupby.ToString(), + Nb = jumps.Count(), + User = _identityService.ConnectedUser + })]; + } + + _statsForLastYearByDzRepository.Add(results); + return results; + } + + return allStats; + } + + public void Reset() + { + _statsForLastYearByDzRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public Methods + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByJumpTypeService.cs new file mode 100644 index 0000000..7f0569c --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsForLastYearByJumpTypeService.cs @@ -0,0 +1,74 @@ +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 StatsForLastYearByJumpTypeService : IStatsForLastYearByJumpTypeService + { + #region Public Constructors + + public StatsForLastYearByJumpTypeService(IJumpService jumpService, + IIdentityService identityService, + IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository) + { + _jumpService = jumpService; + _identityService = identityService; + _statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetStats() + { + var allStats = _statsForLastYearByJumpTypeRepository.GetAll(_identityService.ConnectedUser); + if (!allStats.Any()) + { + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new StatsForLastYearByJumpType + { + JumpType = groupby.ToString(), + Nb = jumps.Count(), + User = _identityService.ConnectedUser + })]; + } + + _statsForLastYearByJumpTypeRepository.Add(results); + return results; + } + + return allStats; + } + + + public void Reset() + { + _statsForLastYearByJumpTypeRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public Methods + + + #region Private Fields + + private readonly IIdentityService _identityService; + private readonly IJumpService _jumpService; + private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs index 6f0982b..e6eb3e2 100644 --- a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs @@ -1,6 +1,5 @@ using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; -using skydiveLogs_api.DomainService.Repositories; using System.Collections.Generic; using System.Linq; @@ -11,12 +10,28 @@ namespace skydiveLogs_api.DomainBusiness #region Public Constructors public StatsService(IJumpService jumpService, - IUserStatsRepository userStatsRepository, - IIdentityService identityService) + IStatsByAircraftService statsByAircraftService, + IStatsByDzService statsByDzService, + IStatsByGearService statsByGearService, + IStatsByJumpTypeService statsByJumpTypeService, + IStatsByYearByJumpTypeService statsByYearByJumpTypeService, + IStatsByYearService statsByYearService, + IStatsForLastMonthByDzService statsForLastMonthByDzService, + IStatsForLastMonthByJumpTypeService statsForLastMonthByJumpTypeService, + IStatsForLastYearByDzService statsForLastYearByDzService, + IStatsForLastYearByJumpTypeService statsForLastYearByJumpTypeService) { _jumpService = jumpService; - _identityService = identityService; - _userStatsRepository = userStatsRepository; + _statsByAircraftService = statsByAircraftService; + _statsByDzService = statsByDzService; + _statsByGearService = statsByGearService; + _statsByJumpTypeService = statsByJumpTypeService; + _statsByYearByJumpTypeService = statsByYearByJumpTypeService; + _statsByYearService = statsByYearService; + _statsForLastMonthByDzService = statsForLastMonthByDzService; + _statsForLastMonthByJumpTypeService = statsForLastMonthByJumpTypeService; + _statsForLastYearByDzService = statsForLastYearByDzService; + _statsForLastYearByJumpTypeService = statsForLastYearByJumpTypeService; } #endregion Public Constructors @@ -43,339 +58,136 @@ namespace skydiveLogs_api.DomainBusiness return results; } + public void Reset() + { + _statsByAircraftService.Reset(); + _statsByDzService.Reset(); + _statsByGearService.Reset(); + _statsByJumpTypeService.Reset(); + _statsByYearByJumpTypeService.Reset(); + _statsByYearService.Reset(); + _statsForLastMonthByDzService.Reset(); + _statsForLastMonthByJumpTypeService.Reset(); + _statsForLastYearByDzService.Reset(); + _statsForLastYearByJumpTypeService.Reset(); + } + public IEnumerable GetStatsByAircraft() { - var allStats = GetAllStats(); - if (!allStats.ByAircraft.Any()) + var tmp = _statsByAircraftService.GetStats(); + return [.. tmp.Select(a => new Statistic { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - results = allJumps.GroupBy(j => j.Aircraft.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ByAircraft = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByAircraft; + Label = a.Aircraft, + Nb = a.Nb + })]; } public IEnumerable GetStatsByDz() { - var allStats = GetAllStats(); - if (!allStats.ByDz.Any()) + var tmp = _statsByDzService.GetStats(); + return [.. tmp.Select(a => new Statistic { - 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() - }) - .ToList(); - } - - allStats.ByDz = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByDz; + Label = a.DropZone, + Nb = a.Nb + })]; } public IEnumerable GetStatsByGear() { - var allStats = GetAllStats(); - if (!allStats.ByGear.Any()) + var tmp = _statsByGearService.GetStats(); + return [.. tmp.Select(a => new Statistic { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - results = allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}", - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ByGear = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByGear; + Label = a.Gear, + Nb = a.Nb + })]; } public IEnumerable GetStatsByJumpType() { - var allStats = GetAllStats(); - if (!allStats.ByJumpType.Any()) + var tmp = _statsByJumpTypeService.GetStats(); + return [.. tmp.Select(a => new Statistic { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - results = allJumps.GroupBy(j => j.JumpType.Name, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ByJumpType = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByJumpType; + Label = a.JumpType, + Nb = a.Nb + })]; } public IEnumerable GetStatsByYear() { - var allStats = GetAllStats(); - if (!allStats.ByYear.Any()) + var tmp = _statsByYearService.GetStats(); + return [.. tmp.Select(a => new Statistic { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - results = allJumps.GroupBy(j => j.JumpDate.Year, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ByYear = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByYear; + Label = a.Year, + Nb = a.Nb + })]; } public IEnumerable GetStatsForLastMonthByDz() { - var allStats = GetAllStats(); - if (!allStats.ForLastMonthByDz.Any()) + var tmp = _statsForLastMonthByDzService.GetStats(); + return [.. tmp.Select(a => new Statistic { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); - var yearOfLastJump = lastJump.JumpDate.Year; - var monthOfLastJump = lastJump.JumpDate.Month; - - 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(); - } - - allStats.ForLastMonthByDz = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ForLastMonthByDz; + Label = a.DropZone, + Nb = a.Nb + })]; } public IEnumerable GetStatsForLastMonthByJumpType() { - var allStats = GetAllStats(); - if (!allStats.ForLastMonthByJumpType.Any()) + var tmp = _statsForLastMonthByJumpTypeService.GetStats(); + return [.. tmp.Select(a => new Statistic { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); - var yearOfLastJump = lastJump.JumpDate.Year; - var monthOfLastJump = lastJump.JumpDate.Month; - - 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(); - } - - allStats.ForLastMonthByJumpType = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ForLastMonthByJumpType; + Label = a.JumpType, + Nb = a.Nb + })]; } public IEnumerable GetStatsForLastYearByDz() { - var allStats = GetAllStats(); - if (!allStats.ForLastYearByDz.Any()) + var tmp = _statsForLastYearByDzService.GetStats(); + return [.. tmp.Select(a => new Statistic { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); - var yearOfLastJump = lastJump.JumpDate.Year; - - 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(); - } - - allStats.ForLastYearByDz = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ForLastYearByDz; + Label = a.DropZone, + Nb = a.Nb + })]; } public IEnumerable GetStatsForLastYearByJumpType() { - var allStats = GetAllStats(); - if (!allStats.ForLastYearByJumpType.Any()) + var tmp = _statsForLastYearByJumpTypeService.GetStats(); + return [.. tmp.Select(a => new Statistic { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); - var yearOfLastJump = lastJump.JumpDate.Year; - - 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(); - } - - allStats.ForLastYearByJumpType = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ForLastYearByJumpType; + Label = a.JumpType, + Nb = a.Nb + })]; } public IEnumerable GetStatsByYearByJumpType() { - var allStats = GetAllStats(); - if (!allStats.ByYearByJumpType.Any()) + var tmp = _statsByYearByJumpTypeService.GetStats(); + return [.. tmp.Select(a => new Statistic { - var allJumps = _jumpService.GetAllJumps(); - var results = new List(); - - if (allJumps.Any()) - { - results = allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year }, - j => j, - (groupby, jumps) => new Statistic - { - Label = groupby.Year.ToString(), - Label2 = groupby.Name.ToString(), - Nb = jumps.Count() - }) - .ToList(); - } - - allStats.ByYearByJumpType = results; - _userStatsRepository.Update(allStats); - } - - return allStats.ByYearByJumpType; - } - - 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); + Label = a.Year, + Label2 = a.JumpType, + Nb = a.Nb + })]; } #endregion Public Methods - #region Private Methods - - private UserStats GetAllStats() - { - var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser); - if (allStats == null) - { - allStats = new UserStats - { - User = _identityService.ConnectedUser - }; - _userStatsRepository.Add(allStats); - } - - return allStats; - } - - #endregion Private Methods - #region Private Fields - private readonly IIdentityService _identityService; private readonly IJumpService _jumpService; - private readonly IUserStatsRepository _userStatsRepository; + private readonly IStatsByAircraftService _statsByAircraftService; + private readonly IStatsByDzService _statsByDzService; + private readonly IStatsByGearService _statsByGearService; + private readonly IStatsByJumpTypeService _statsByJumpTypeService; + private readonly IStatsByYearByJumpTypeService _statsByYearByJumpTypeService; + private readonly IStatsByYearService _statsByYearService; + private readonly IStatsForLastMonthByDzService _statsForLastMonthByDzService; + private readonly IStatsForLastMonthByJumpTypeService _statsForLastMonthByJumpTypeService; + private readonly IStatsForLastYearByDzService _statsForLastYearByDzService; + private readonly IStatsForLastYearByJumpTypeService _statsForLastYearByJumpTypeService; #endregion Private Fields } diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsByAircraftRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByAircraftRepository.cs new file mode 100644 index 0000000..34f29b9 --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByAircraftRepository.cs @@ -0,0 +1,8 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsByAircraftRepository : IStatsRepository + { + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsByDzRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByDzRepository.cs new file mode 100644 index 0000000..500f2a6 --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByDzRepository.cs @@ -0,0 +1,8 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsByDzRepository : IStatsRepository + { + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsByGearRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByGearRepository.cs new file mode 100644 index 0000000..0c3e2b9 --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByGearRepository.cs @@ -0,0 +1,8 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsByGearRepository : IStatsRepository + { + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsByJumpTypeRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByJumpTypeRepository.cs new file mode 100644 index 0000000..4c19444 --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByJumpTypeRepository.cs @@ -0,0 +1,8 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsByJumpTypeRepository : IStatsRepository + { + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsByYearByJumpTypeRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByYearByJumpTypeRepository.cs new file mode 100644 index 0000000..d6d134e --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByYearByJumpTypeRepository.cs @@ -0,0 +1,8 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsByYearByJumpTypeRepository : IStatsRepository + { + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsByYearRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByYearRepository.cs new file mode 100644 index 0000000..00ecb5c --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByYearRepository.cs @@ -0,0 +1,8 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsByYearRepository : IStatsRepository + { + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastMonthByDzRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastMonthByDzRepository.cs new file mode 100644 index 0000000..6e91941 --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastMonthByDzRepository.cs @@ -0,0 +1,8 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsForLastMonthByDzRepository : IStatsRepository + { + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastMonthByJumpTypeRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastMonthByJumpTypeRepository.cs new file mode 100644 index 0000000..eee6dce --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastMonthByJumpTypeRepository.cs @@ -0,0 +1,8 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsForLastMonthByJumpTypeRepository : IStatsRepository + { + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastYearByDzRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastYearByDzRepository.cs new file mode 100644 index 0000000..adc164d --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastYearByDzRepository.cs @@ -0,0 +1,8 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsForLastYearByDzRepository : IStatsRepository + { + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastYearByJumpTypeRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastYearByJumpTypeRepository.cs new file mode 100644 index 0000000..15cfd11 --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsForLastYearByJumpTypeRepository.cs @@ -0,0 +1,8 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsForLastYearByJumpTypeRepository : IStatsRepository + { + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsRepository.cs new file mode 100644 index 0000000..267ac38 --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsRepository.cs @@ -0,0 +1,20 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface IStatsRepository + { + #region Public Methods + + IEnumerable GetAll(User user); + + int Add(IEnumerable newEntity); + + bool Update(IEnumerable updatedEntity, User user); + + bool Delete(User user); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IUserStatsRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IUserStatsRepository.cs deleted file mode 100644 index ef462a7..0000000 --- a/Back/skydiveLogs-api.DomainService/Repositories/IUserStatsRepository.cs +++ /dev/null @@ -1,13 +0,0 @@ -using skydiveLogs_api.Domain; - -namespace skydiveLogs_api.DomainService.Repositories -{ - public interface IUserStatsRepository : IRepository - { - #region Public Methods - - UserStats GetAll(User user); - - #endregion Public Methods - } -} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs b/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs index 9590cbe..cf934e2 100644 --- a/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs +++ b/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs @@ -30,12 +30,30 @@ namespace skydiveLogs_api.Infrastructure.Interfaces ILiteCollection CollOfJumpType { get; } - ILiteCollection CollOfStats { get; } - ILiteCollection CollOfUser { get; } - + ILiteCollection CollOfTunnelFlight { get; } + ILiteCollection CollOfStatsByAircraft { get; } + + ILiteCollection CollOfStatsByDz { get; } + + ILiteCollection CollOfStatsByGear { get; } + + ILiteCollection CollOfStatsByJumpType { get; } + + ILiteCollection CollOfStatsByYear { get; } + + ILiteCollection CollOfStatsForLastMonthByDz { get; } + + ILiteCollection CollOfStatsForLastMonthByJumpType { get; } + + ILiteCollection CollOfStatsForLastYearByDz { get; } + + ILiteCollection CollOfStatsForLastYearByJumpType { get; } + + ILiteCollection CollOfStatsByYearByJumpType { get; } + #endregion Public Properties } } \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs b/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs index 4cd74b6..3376856 100644 --- a/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs +++ b/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs @@ -21,8 +21,6 @@ namespace skydiveLogs_api.Infrastructure BsonMapper.Global.Entity().DbRef(x => x.User, "User"); - BsonMapper.Global.Entity().DbRef(x => x.User, "User"); - BsonMapper.Global.Entity().DbRef(x => x.User, "User"); BsonMapper.Global.Entity().DbRef(x => x.User, "User"); @@ -31,6 +29,17 @@ namespace skydiveLogs_api.Infrastructure BsonMapper.Global.Entity().DbRef(x => x.Tunnel, "DropZone"); BsonMapper.Global.Entity().DbRef(x => x.JumpType, "JumpType"); BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); } #endregion Public Constructors @@ -58,10 +67,18 @@ namespace skydiveLogs_api.Infrastructure public ILiteCollection CollOfImage => _db.GetCollection(); public ILiteCollection CollOfJump => _db.GetCollection(); public ILiteCollection CollOfJumpType => _db.GetCollection(); - public ILiteCollection CollOfStats => _db.GetCollection(); public ILiteCollection CollOfUser => _db.GetCollection(); public ILiteCollection CollOfTunnelFlight => _db.GetCollection(); - + public ILiteCollection CollOfStatsByAircraft => _db.GetCollection(); + public ILiteCollection CollOfStatsByDz => _db.GetCollection(); + public ILiteCollection CollOfStatsByGear => _db.GetCollection(); + public ILiteCollection CollOfStatsByJumpType => _db.GetCollection(); + public ILiteCollection CollOfStatsByYear => _db.GetCollection(); + public ILiteCollection CollOfStatsForLastMonthByDz => _db.GetCollection(); + public ILiteCollection CollOfStatsForLastMonthByJumpType => _db.GetCollection(); + public ILiteCollection CollOfStatsForLastYearByDz => _db.GetCollection(); + public ILiteCollection CollOfStatsForLastYearByJumpType => _db.GetCollection(); + public ILiteCollection CollOfStatsByYearByJumpType => _db.GetCollection(); #endregion Public Properties #region Private Fields diff --git a/Back/skydiveLogs-api.Infrastructure/StatsByAircraftRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsByAircraftRepository.cs new file mode 100644 index 0000000..500979e --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/StatsByAircraftRepository.cs @@ -0,0 +1,74 @@ +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(IEnumerable newStats) + { + int result = 0; + + try + { + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } + } + catch + { + result = 0; + } + + return result; + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public bool Update(IEnumerable updatedStats, User user) + { + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; + } + + public bool Delete(User user) + { + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsByDzRepository.cs similarity index 50% rename from Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs rename to Back/skydiveLogs-api.Infrastructure/StatsByDzRepository.cs index dbe9305..c64b5af 100644 --- a/Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/StatsByDzRepository.cs @@ -1,4 +1,4 @@ -using LiteDB; +using LiteDB; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure.Interfaces; @@ -6,28 +6,31 @@ using System.Collections.Generic; namespace skydiveLogs_api.Infrastructure { - public class UserStatsRepository : IUserStatsRepository + public class StatsByDzRepository : IStatsByDzRepository { #region Public Constructors - public UserStatsRepository(IDataProvider dataProvider) + public StatsByDzRepository(IDataProvider dataProvider) { _dataProvider = dataProvider; - _col = _dataProvider.CollOfStats; + _col = _dataProvider.CollOfStatsByDz; } #endregion Public Constructors #region Public Methods - public int Add(UserStats newStats) + public int Add(IEnumerable newStats) { - int result; + int result = 0; try { - var tmp = _col.Insert(newStats); - result = tmp.AsInt32; + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } } catch { @@ -37,39 +40,33 @@ namespace skydiveLogs_api.Infrastructure return result; } - public IEnumerable GetAll() - { - throw new System.NotImplementedException(); - } - - public UserStats GetAll(User user) + public IEnumerable GetAll(User user) { return _col.Include(x => x.User) .Query() .Where(j => j.User.Id == user.Id) - .SingleOrDefault(); + .ToList(); } - public UserStats GetById(int id) + public bool Update(IEnumerable updatedStats, User user) { - throw new System.NotImplementedException(); + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; } - public int GetCount() + public bool Delete(User user) { - throw new System.NotImplementedException(); - } - - public bool Update(UserStats stats) - { - return _col.Update(stats); + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; } #endregion Public Methods #region Private Fields - private readonly ILiteCollection _col; + private readonly ILiteCollection _col; private readonly IDataProvider _dataProvider; #endregion Private Fields diff --git a/Back/skydiveLogs-api.Infrastructure/StatsByGearRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsByGearRepository.cs new file mode 100644 index 0000000..ba2fd95 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/StatsByGearRepository.cs @@ -0,0 +1,74 @@ +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 StatsByGearRepository : IStatsByGearRepository + { + #region Public Constructors + + public StatsByGearRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfStatsByGear; + } + + #endregion Public Constructors + + #region Public Methods + + public int Add(IEnumerable newStats) + { + int result = 0; + + try + { + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } + } + catch + { + result = 0; + } + + return result; + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public bool Update(IEnumerable updatedStats, User user) + { + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; + } + + public bool Delete(User user) + { + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/StatsByJumpTypeRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsByJumpTypeRepository.cs new file mode 100644 index 0000000..e938f54 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/StatsByJumpTypeRepository.cs @@ -0,0 +1,74 @@ +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 StatsByJumpTypeRepository : IStatsByJumpTypeRepository + { + #region Public Constructors + + public StatsByJumpTypeRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfStatsByJumpType; + } + + #endregion Public Constructors + + #region Public Methods + + public int Add(IEnumerable newStats) + { + int result = 0; + + try + { + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } + } + catch + { + result = 0; + } + + return result; + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public bool Update(IEnumerable updatedStats, User user) + { + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; + } + + public bool Delete(User user) + { + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/StatsByYearByJumpTypeRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsByYearByJumpTypeRepository.cs new file mode 100644 index 0000000..51da73d --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/StatsByYearByJumpTypeRepository.cs @@ -0,0 +1,74 @@ +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 StatsByYearByJumpTypeRepository : IStatsByYearByJumpTypeRepository + { + #region Public Constructors + + public StatsByYearByJumpTypeRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfStatsByYearByJumpType; + } + + #endregion Public Constructors + + #region Public Methods + + public int Add(IEnumerable newStats) + { + int result = 0; + + try + { + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } + } + catch + { + result = 0; + } + + return result; + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public bool Update(IEnumerable updatedStats, User user) + { + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; + } + + public bool Delete(User user) + { + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/StatsByYearRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsByYearRepository.cs new file mode 100644 index 0000000..5a0f716 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/StatsByYearRepository.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using LiteDB; +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Infrastructure.Interfaces; + +namespace skydiveLogs_api.Infrastructure +{ + public class StatsByYearRepository : IStatsByYearRepository + { + #region Public Constructors + + public StatsByYearRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfStatsByYear; + } + + #endregion Public Constructors + + #region Public Methods + + public int Add(IEnumerable newStats) + { + int result = 0; + + try + { + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } + } + catch + { + result = 0; + } + + return result; + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public bool Update(IEnumerable updatedStats, User user) + { + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; + } + + public bool Delete(User user) + { + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/StatsForLastMonthByDzRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsForLastMonthByDzRepository.cs new file mode 100644 index 0000000..d970a89 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/StatsForLastMonthByDzRepository.cs @@ -0,0 +1,74 @@ +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 StatsForLastMonthByDzRepository : IStatsForLastMonthByDzRepository + { + #region Public Constructors + + public StatsForLastMonthByDzRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfStatsForLastMonthByDz; + } + + #endregion Public Constructors + + #region Public Methods + + public int Add(IEnumerable newStats) + { + int result = 0; + + try + { + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } + } + catch + { + result = 0; + } + + return result; + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public bool Update(IEnumerable updatedStats, User user) + { + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; + } + + public bool Delete(User user) + { + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/StatsForLastMonthByJumpTypeRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsForLastMonthByJumpTypeRepository.cs new file mode 100644 index 0000000..cdb0680 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/StatsForLastMonthByJumpTypeRepository.cs @@ -0,0 +1,74 @@ +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 StatsForLastMonthByJumpTypeRepository : IStatsForLastMonthByJumpTypeRepository + { + #region Public Constructors + + public StatsForLastMonthByJumpTypeRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfStatsForLastMonthByJumpType; + } + + #endregion Public Constructors + + #region Public Methods + + public int Add(IEnumerable newStats) + { + int result = 0; + + try + { + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } + } + catch + { + result = 0; + } + + return result; + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public bool Update(IEnumerable updatedStats, User user) + { + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; + } + + public bool Delete(User user) + { + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/StatsForLastYearByDzRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsForLastYearByDzRepository.cs new file mode 100644 index 0000000..3888be8 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/StatsForLastYearByDzRepository.cs @@ -0,0 +1,74 @@ +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 StatsForLastYearByDzRepository : IStatsForLastYearByDzRepository + { + #region Public Constructors + + public StatsForLastYearByDzRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfStatsForLastYearByDz; + } + + #endregion Public Constructors + + #region Public Methods + + public int Add(IEnumerable newStats) + { + int result = 0; + + try + { + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } + } + catch + { + result = 0; + } + + return result; + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public bool Update(IEnumerable updatedStats, User user) + { + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; + } + + public bool Delete(User user) + { + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/StatsForLastYearByJumpTypeRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsForLastYearByJumpTypeRepository.cs new file mode 100644 index 0000000..9921007 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/StatsForLastYearByJumpTypeRepository.cs @@ -0,0 +1,74 @@ +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 StatsForLastYearByJumpTypeRepository : IStatsForLastYearByJumpTypeRepository + { + #region Public Constructors + + public StatsForLastYearByJumpTypeRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfStatsForLastYearByJumpType; + } + + #endregion Public Constructors + + #region Public Methods + + public int Add(IEnumerable newStats) + { + int result = 0; + + try + { + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } + } + catch + { + result = 0; + } + + return result; + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public bool Update(IEnumerable updatedStats, User user) + { + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; + } + + public bool Delete(User user) + { + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Ioc/IocService.cs b/Back/skydiveLogs-api.Ioc/IocService.cs index a08586b..7b30664 100644 --- a/Back/skydiveLogs-api.Ioc/IocService.cs +++ b/Back/skydiveLogs-api.Ioc/IocService.cs @@ -32,13 +32,24 @@ namespace skydiveLogs_api.Ioc _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); - _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddSingleton(); _services.AddScoped(); @@ -52,9 +63,19 @@ namespace skydiveLogs_api.Ioc _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); - _services.AddScoped(); _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + _services.AddScoped(); + string connectionString = _configuration.GetConnectionString("DefaultConnection"); _services.AddSingleton(c => new LiteDbProvider(connectionString)); } diff --git a/Front/skydivelogs-app/src/app/summary/summary.component.ts b/Front/skydivelogs-app/src/app/summary/summary.component.ts index 5e33c4e..8e93329 100644 --- a/Front/skydivelogs-app/src/app/summary/summary.component.ts +++ b/Front/skydivelogs-app/src/app/summary/summary.component.ts @@ -193,7 +193,7 @@ export class SummaryComponent implements OnInit { let firstYear: number = Number(data[0].label); const now = new Date(); const currentYear = now.getFullYear(); - const nbYears = currentYear - firstYear; + const nbYears = currentYear - firstYear + 1; let listOfYears = new Array(nbYears) .fill(null) .map(() => firstYear++);