Add a cache system on the referential info

+ Add an identity service
This commit is contained in:
Sébastien André
2021-04-17 22:17:45 +02:00
parent 0bb9ed2a30
commit 143127cd01
30 changed files with 955 additions and 570 deletions

View File

@@ -1,220 +1,26 @@
using System.Collections.Generic;
using System.Linq;
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
using skydiveLogs_api.Domain;
using System.Collections.Generic;
using System.Linq;
namespace skydiveLogs_api.DomainBusiness
{
public class StatsService : IStatsService
{
#region Public Constructors
public StatsService(IJumpService jumpService)
{
_jumpService = jumpService;
}
public IEnumerable<Statistic> GetStatsByAircraft(User connectedUser)
#endregion Public Constructors
#region Public Methods
public SimpleSummary GetSimpleSummary()
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsByDz(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsByJumpType(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsByGear(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsByYear(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsForLastYearByDz(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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();
}
return results;
}
public IEnumerable<Statistic> GetStatsForLastYearByJumpType(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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();
}
return results;
}
public IEnumerable<Statistic> GetStatsForLastMonthByDz(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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();
}
return results;
}
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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();
}
return results;
}
public SimpleSummary GetSimpleSummary(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var allJumps = _jumpService.GetAllJumps();
var results = new SimpleSummary();
if (allJumps.Any())
@@ -232,6 +38,210 @@ namespace skydiveLogs_api.DomainBusiness
return results;
}
public IEnumerable<Statistic> GetStatsByAircraft()
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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<Statistic> GetStatsByDz()
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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<Statistic> GetStatsByGear()
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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<Statistic> GetStatsByJumpType()
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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<Statistic> GetStatsByYear()
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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<Statistic> GetStatsForLastMonthByDz()
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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();
}
return results;
}
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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();
}
return results;
}
public IEnumerable<Statistic> GetStatsForLastYearByDz()
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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();
}
return results;
}
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<Statistic>();
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();
}
return results;
}
#endregion Public Methods
#region Private Fields
private readonly IJumpService _jumpService;
#endregion Private Fields
}
}
}