This commit is contained in:
Sébastien André
2020-08-25 16:25:40 +02:00
parent 25cfc62005
commit 498ec2c741
4 changed files with 157 additions and 97 deletions

View File

@@ -31,9 +31,9 @@ namespace skydiveLogs_api.Business
return _imageRepository.GetById(id); return _imageRepository.GetById(id);
} }
public IEnumerable<Image> GetAllImages() public IEnumerable<Image> GetAllImages(User connectedUser)
{ {
return _imageRepository.GetAll(); return _imageRepository.GetAll(connectedUser);
} }
public void UpdateImage(int id, Image Image) public void UpdateImage(int id, Image Image)

View File

@@ -7,7 +7,7 @@ namespace skydiveLogs_api.Business.Interface
{ {
public interface IImageService public interface IImageService
{ {
IEnumerable<Image> GetAllImages(); IEnumerable<Image> GetAllImages(User connectedUser);
Image GetImageById(int id); Image GetImageById(int id);

View File

@@ -18,159 +18,219 @@ namespace skydiveLogs_api.Business
public IEnumerable<Statistic> GetStatsByAircraft(User connectedUser) public IEnumerable<Statistic> GetStatsByAircraft(User connectedUser)
{ {
var allJumps = _jumpService.GetAllJumps(connectedUser); var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
return allJumps.GroupBy(j => j.Aircraft.Name, if (allJumps.Any())
j => j, {
(groupby, jumps) => new Statistic results = allJumps.GroupBy(j => j.Aircraft.Name,
{ j => j,
Label = groupby.ToString(), (groupby, jumps) => new Statistic
Nb = jumps.Count() {
}) Label = groupby.ToString(),
.ToList(); Nb = jumps.Count()
})
.ToList();
}
return results;
} }
public IEnumerable<Statistic> GetStatsByDz(User connectedUser) public IEnumerable<Statistic> GetStatsByDz(User connectedUser)
{ {
var allJumps = _jumpService.GetAllJumps(connectedUser); var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
return allJumps.GroupBy(j => j.DropZone.Name, if (allJumps.Any())
j => j, {
(groupby, jumps) => new Statistic results = allJumps.GroupBy(j => j.DropZone.Name,
{ j => j,
Label = groupby.ToString(), (groupby, jumps) => new Statistic
Nb = jumps.Count() {
}) Label = groupby.ToString(),
.ToList(); Nb = jumps.Count()
})
.ToList();
}
return results;
} }
public IEnumerable<Statistic> GetStatsByJumpType(User connectedUser) public IEnumerable<Statistic> GetStatsByJumpType(User connectedUser)
{ {
var allJumps = _jumpService.GetAllJumps(connectedUser); var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
return allJumps.GroupBy(j => j.JumpType.Name, if (allJumps.Any())
j => j, {
(groupby, jumps) => new Statistic results = allJumps.GroupBy(j => j.JumpType.Name,
{ j => j,
Label = groupby.ToString(), (groupby, jumps) => new Statistic
Nb = jumps.Count() {
}) Label = groupby.ToString(),
.ToList(); Nb = jumps.Count()
})
.ToList();
}
return results;
} }
public IEnumerable<Statistic> GetStatsByGear(User connectedUser) public IEnumerable<Statistic> GetStatsByGear(User connectedUser)
{ {
var allJumps = _jumpService.GetAllJumps(connectedUser); var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
return allJumps.GroupBy(j => j.Gear.Name, if (allJumps.Any())
j => j, {
(groupby, jumps) => new Statistic results = allJumps.GroupBy(j => j.Gear.Name,
{ j => j,
Label = groupby.ToString(), (groupby, jumps) => new Statistic
Nb = jumps.Count() {
}) Label = groupby.ToString(),
.ToList(); Nb = jumps.Count()
})
.ToList();
}
return results;
} }
public IEnumerable<Statistic> GetStatsByYear(User connectedUser) public IEnumerable<Statistic> GetStatsByYear(User connectedUser)
{ {
var allJumps = _jumpService.GetAllJumps(connectedUser); var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
return allJumps.GroupBy(j => j.JumpDate.Year, if (allJumps.Any())
j => j, {
(groupby, jumps) => new Statistic results = allJumps.GroupBy(j => j.JumpDate.Year,
{ j => j,
Label = groupby.ToString(), (groupby, jumps) => new Statistic
Nb = jumps.Count() {
}) Label = groupby.ToString(),
.ToList(); Nb = jumps.Count()
})
.ToList();
}
return results;
} }
public IEnumerable<Statistic> GetStatsForLastYearByDz(User connectedUser) public IEnumerable<Statistic> GetStatsForLastYearByDz(User connectedUser)
{ {
var allJumps = _jumpService.GetAllJumps(connectedUser); var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); if (allJumps.Any())
var yearOfLastJump = lastJump.JumpDate.Year; {
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
var yearOfLastJump = lastJump.JumpDate.Year;
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
.GroupBy(j => j.DropZone.Name, .GroupBy(j => j.DropZone.Name,
j => j, j => j,
(groupby, jumps) => new Statistic (groupby, jumps) => new Statistic
{ {
Label = groupby.ToString(), Label = groupby.ToString(),
Nb = jumps.Count() Nb = jumps.Count()
}) })
.ToList(); .ToList();
}
return results;
} }
public IEnumerable<Statistic> GetStatsForLastYearByJumpType(User connectedUser) public IEnumerable<Statistic> GetStatsForLastYearByJumpType(User connectedUser)
{ {
var allJumps = _jumpService.GetAllJumps(connectedUser); var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); if (allJumps.Any())
var yearOfLastJump = lastJump.JumpDate.Year; {
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
var yearOfLastJump = lastJump.JumpDate.Year;
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
.GroupBy(j => j.JumpType.Name, .GroupBy(j => j.JumpType.Name,
j => j, j => j,
(groupby, jumps) => new Statistic (groupby, jumps) => new Statistic
{ {
Label = groupby.ToString(), Label = groupby.ToString(),
Nb = jumps.Count() Nb = jumps.Count()
}) })
.ToList(); .ToList();
}
return results;
} }
public IEnumerable<Statistic> GetStatsForLastMonthByDz(User connectedUser) public IEnumerable<Statistic> GetStatsForLastMonthByDz(User connectedUser)
{ {
var allJumps = _jumpService.GetAllJumps(connectedUser); var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); if (allJumps.Any())
var yearOfLastJump = lastJump.JumpDate.Year; {
var monthOfLastJump = lastJump.JumpDate.Month; var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
var yearOfLastJump = lastJump.JumpDate.Year;
var monthOfLastJump = lastJump.JumpDate.Month;
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
.GroupBy(j => j.DropZone.Name, .GroupBy(j => j.DropZone.Name,
j => j, j => j,
(groupby, jumps) => new Statistic (groupby, jumps) => new Statistic
{ {
Label = groupby.ToString(), Label = groupby.ToString(),
Nb = jumps.Count() Nb = jumps.Count()
}) })
.ToList(); .ToList();
}
return results;
} }
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType(User connectedUser) public IEnumerable<Statistic> GetStatsForLastMonthByJumpType(User connectedUser)
{ {
var allJumps = _jumpService.GetAllJumps(connectedUser); var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); if (allJumps.Any())
var yearOfLastJump = lastJump.JumpDate.Year; {
var monthOfLastJump = lastJump.JumpDate.Month; var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
var yearOfLastJump = lastJump.JumpDate.Year;
var monthOfLastJump = lastJump.JumpDate.Month;
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
.GroupBy(j => j.JumpType.Name, .GroupBy(j => j.JumpType.Name,
j => j, j => j,
(groupby, jumps) => new Statistic (groupby, jumps) => new Statistic
{ {
Label = groupby.ToString(), Label = groupby.ToString(),
Nb = jumps.Count() Nb = jumps.Count()
}) })
.ToList(); .ToList();
}
return results;
} }
public SimpleSummary GetSimpleSummary(User connectedUser) public SimpleSummary GetSimpleSummary(User connectedUser)
{ {
var allJumps = _jumpService.GetAllJumps(connectedUser); var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new SimpleSummary();
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault(); if (allJumps.Any())
return new SimpleSummary
{ {
LastJump = lastJump, var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
TotalJumps = allJumps.Count(),
TotalCutaways = allJumps.Where(j => j.WithCutaway).Count() results = new SimpleSummary
}; {
LastJump = lastJump,
TotalJumps = allJumps.Count(),
TotalCutaways = allJumps.Where(j => j.WithCutaway).Count()
};
}
return results;
} }
private readonly IJumpService _jumpService; private readonly IJumpService _jumpService;

View File

@@ -25,7 +25,7 @@ namespace skydiveLogs_api.Controllers
[EnableCors] [EnableCors]
public IEnumerable<ImageResp> Get() public IEnumerable<ImageResp> Get()
{ {
var result = _imageService.GetAllImages(); var result = _imageService.GetAllImages(ConnectedUser);
return _mapper.Map<IEnumerable<ImageResp>>(result); return _mapper.Map<IEnumerable<ImageResp>>(result);
} }