Add an action to retrieve un simple summary with

the total of jumps and the last jump
This commit is contained in:
Sébastien André
2020-03-03 15:45:36 +01:00
parent e6f0edebf5
commit 6a5e9020d5
7 changed files with 50 additions and 5 deletions

View File

@@ -22,5 +22,7 @@ namespace skydiveLogs_api.Business.Interface
IEnumerable<Statistic> GetStatsForLastMonthByDz();
IEnumerable<Statistic> GetStatsForLastMonthByJumpType();
SimpleSummary GetSimpleSummary();
}
}

View File

@@ -159,6 +159,20 @@ namespace skydiveLogs_api.Business
.ToList();
}
public SimpleSummary GetSimpleSummary()
{
var allJumps = _jumpRepository.GetAll();
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault();
return new SimpleSummary
{
LastJump = lastJump,
TotalJumps = allJumps.Count(),
TotalCutaway = allJumps.Where(j => j.WithCutaway).Count()
};
}
private readonly IJumpRepository _jumpRepository;
}
}

View File

@@ -0,0 +1,11 @@
namespace skydiveLogs_api.Model
{
public class SimpleSummary
{
public int TotalJumps { get; set; }
public int TotalCutaway { get; set; }
public Jump LastJump { get; set; }
}
}

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace skydiveLogs_api.Model
namespace skydiveLogs_api.Model
{
public class Statistic
{

View File

@@ -21,6 +21,15 @@ namespace skydiveLogs_api.Controllers
_mapper = mapper;
}
[HttpGet("Simple")]
[EnableCors]
public SimpleSummaryResp Simple()
{
var result = _statsService.GetSimpleSummary();
return _mapper.Map<SimpleSummaryResp>(result);
}
[HttpGet("ByDz")]
[EnableCors]
public IEnumerable<StatisticResp> ByDz()

View File

@@ -0,0 +1,11 @@
namespace skydiveLogs_api.DataContract
{
public class SimpleSummaryResp
{
public int TotalJumps { get; set; }
public int TotalCutaway { get; set; }
public JumpResp LastJump { get; set; }
}
}

View File

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