Ajout de l'implémentation des stats par dz, avion, piège et annèe.

This commit is contained in:
Sébastien André
2019-10-25 15:05:57 +02:00
parent e8dacaaefe
commit 6499e03c56
11 changed files with 159 additions and 25 deletions

View File

@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using skydiveLogs_api.Business.Interface;
using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Business
{
public class DropZoneService : IDropZoneService

View File

@@ -0,0 +1,18 @@
using skydiveLogs_api.Model;
using System.Collections.Generic;
namespace skydiveLogs_api.Business.Interface
{
public interface IStatsService
{
IEnumerable<Statistic> GetStatsByDz();
IEnumerable<Statistic> GetStatsByAircraft();
IEnumerable<Statistic> GetStatsByJumpType();
IEnumerable<Statistic> GetStatsByRig();
IEnumerable<Statistic> GetStatsByYear();
}
}

View File

@@ -0,0 +1,90 @@
using System.Collections.Generic;
using System.Linq;
using skydiveLogs_api.Business.Interface;
using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Business
{
public class StatsService : IStatsService
{
public StatsService(IJumpRepository jumpRepository)
{
_jumpRepository = jumpRepository;
}
public IEnumerable<Statistic> GetStatsByAircraft()
{
var allJumps = _jumpRepository.GetAllJumps();
return allJumps.GroupBy(j => j.AircraftId,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsByDz()
{
var allJumps = _jumpRepository.GetAllJumps();
return allJumps.GroupBy(j => j.DropZoneId,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsByJumpType()
{
var allJumps = _jumpRepository.GetAllJumps();
return allJumps.GroupBy(j => j.JumpTypeId,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsByRig()
{
var allJumps = _jumpRepository.GetAllJumps();
return allJumps.GroupBy(j => j.GearId,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsByYear()
{
var allJumps = _jumpRepository.GetAllJumps();
return allJumps.GroupBy(j => j.JumpDate.Year,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
private readonly IJumpRepository _jumpRepository;
}
}

View File

@@ -8,6 +8,7 @@ namespace skydiveLogs_api.Data.Interface
public interface IJumpRepository
{
IEnumerable<Jump> GetAllJumps();
Jump GetJumpById(int id);
}
}

View File

@@ -20,6 +20,7 @@ namespace skydiveLogs_api.Ioc
_services.AddScoped<Business.Interface.IDropZoneService, Business.DropZoneService>();
_services.AddScoped<Business.Interface.IJumpService, Business.JumpService>();
_services.AddScoped<Business.Interface.IJumpTypeService, Business.JumpTypeService>();
_services.AddScoped<Business.Interface.IStatsService, Business.StatsService>();
_services.AddScoped<Data.Interface.IAircraftRepository, Data.AircraftRepository>();
_services.AddScoped<Data.Interface.IDropZoneRepository, Data.DropZoneRepository>();

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace skydiveLogs_api.Model
{
@@ -23,5 +21,7 @@ namespace skydiveLogs_api.Model
public bool WithCutaway { get; set; }
public string Notes { get; set; }
public DateTime JumpDate { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace skydiveLogs_api.Model
{
public class Statistic
{
public string Label { get; set; }
public int Nb { get; set; }
}
}

View File

@@ -6,7 +6,6 @@ using AutoMapper;
using skydiveLogs_api.Business.Interface;
using skydiveLogs_api.DataContract;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Controllers
@@ -15,60 +14,62 @@ namespace skydiveLogs_api.Controllers
[ApiController]
public class StatsController : ControllerBase
{
public StatsController(IDropZoneService dropZoneService,
public StatsController(IStatsService statsService,
IMapper mapper)
{
_dropZoneService = dropZoneService;
_statsService = statsService;
_mapper = mapper;
}
[HttpGet("ByDz")]
[EnableCors]
public IEnumerable<DropZoneResp> ByDz()
public IEnumerable<StatisticResp> ByDz()
{
var result = _dropZoneService.GetAllDzs();
var result = _statsService.GetStatsByDz();
return _mapper.Map<IEnumerable<DropZoneResp>>(result);
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
[HttpGet("ByAircraft")]
[EnableCors]
public IEnumerable<DropZoneResp> ByAircraft()
public IEnumerable<StatisticResp> ByAircraft()
{
var result = _dropZoneService.GetAllDzs();
var result = _statsService.GetStatsByAircraft();
return _mapper.Map<IEnumerable<DropZoneResp>>(result);
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
[HttpGet("ByJumpType")]
[EnableCors]
public IEnumerable<DropZoneResp> ByJumpType()
public IEnumerable<StatisticResp> ByJumpType()
{
var result = _dropZoneService.GetAllDzs();
var result = _statsService.GetStatsByJumpType();
return _mapper.Map<IEnumerable<DropZoneResp>>(result);
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
[HttpGet("ByRig")]
[EnableCors]
public IEnumerable<DropZoneResp> ByRig()
public IEnumerable<StatisticResp> ByRig()
{
var result = _dropZoneService.GetAllDzs();
var result = _statsService.GetStatsByRig();
return _mapper.Map<IEnumerable<DropZoneResp>>(result);
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
[HttpGet("ByYear")]
[EnableCors]
public IEnumerable<DropZoneResp> ByYear()
public IEnumerable<StatisticResp> ByYear()
{
var result = _dropZoneService.GetAllDzs();
var result = _statsService.GetStatsByYear();
return _mapper.Map<IEnumerable<DropZoneResp>>(result);
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
#region Private properties
private readonly IStatsService _statsService;
private readonly IDropZoneService _dropZoneService;
private readonly IMapper _mapper;
#endregion
}
}

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace skydiveLogs_api.DataContract
{
@@ -24,5 +21,7 @@ namespace skydiveLogs_api.DataContract
public bool WithCutaway { get; set; }
public string Notes { get; set; }
public DateTime JumpDate { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace skydiveLogs_api.DataContract
{
public class StatisticResp
{
public string Label { get; set; }
public int Nb { get; set; }
}
}

View File

@@ -18,6 +18,7 @@ namespace skydiveLogs_api.Mapper
CreateMap<Model.JumpType ,DataContract.JumpTypeResp>();
CreateMap<Model.Aircraft ,DataContract.AircraftResp>();
CreateMap<Model.DropZone ,DataContract.DropZoneResp>();
CreateMap<Model.Statistic ,DataContract.StatisticResp>();
}
}
}