Add methods used for the graph of the tunnel flights

This commit is contained in:
Sébastien ANDRE
2023-08-16 17:38:50 +02:00
parent 25e403c21f
commit dc06f256b4
5 changed files with 83 additions and 29 deletions

View File

@@ -17,8 +17,14 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
IEnumerable<TunnelFlight> GetTunnelFlightByDates(string beginDate, string endDate);
IEnumerable<Statistic> GetTunnelFlightGroupByMonth(string beginDate, string endDate);
void AddNewFlight(int tunnelId, TunnelFlight newFlight);
void DeleteTunnelFlightById(int id);
void UpdateTunnelFlight(int id, TunnelFlight updatedTunnelFlight);
#endregion Public Methods
}
}

View File

@@ -3,6 +3,7 @@ using skydiveLogs_api.DomainBusiness.Interfaces;
using skydiveLogs_api.DomainService.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
namespace skydiveLogs_api.DomainBusiness
{
@@ -33,6 +34,46 @@ namespace skydiveLogs_api.DomainBusiness
return _tunnelFlightRepository.GetById(id);
}
public int GetTunnelFlightCount()
{
return _tunnelFlightRepository.GetCount(_identityService.ConnectedUser);
}
public IEnumerable<TunnelFlight> GetTunnelFlightsByIndexes(int beginIndex, int endIndex)
{
return _tunnelFlightRepository.GetBetweenIndex(_identityService.ConnectedUser, beginIndex, endIndex);
}
public IEnumerable<Statistic> GetTunnelFlightGroupByMonth(string beginDate, string endDate)
{
var convertedBeginDate = Convert.ToDateTime(beginDate);
var convertedEndDate = Convert.ToDateTime(endDate);
var allTunnelFlights = _tunnelFlightRepository.GetBetweenDate(_identityService.ConnectedUser, convertedBeginDate, convertedEndDate);
var results = Enumerable.Empty<Statistic>();
if (allTunnelFlights.Any())
{
results = allTunnelFlights.GroupBy(j => j.FlightDate.ToString("yy-MM"),
j => j,
(groupby, tunnelFlights) => new Statistic
{
Label = groupby.ToString(),
Nb = tunnelFlights.Sum(t => t.NbMinutes)
})
.ToList();
}
return results;
}
public IEnumerable<TunnelFlight> GetTunnelFlightByDates(string beginDate, string endDate)
{
var convertedBeginDate = Convert.ToDateTime(beginDate);
var convertedEndDate = Convert.ToDateTime(endDate);
return _tunnelFlightRepository.GetBetweenDate(_identityService.ConnectedUser, convertedBeginDate, convertedEndDate);
}
public void AddNewFlight(int tunnelId, TunnelFlight newFlight)
{
var tmp = _dropZoneService.GetDzById(tunnelId);
@@ -51,23 +92,19 @@ namespace skydiveLogs_api.DomainBusiness
_tunnelFlightRepository.Add(newFlight);
}
public int GetTunnelFlightCount()
public void DeleteTunnelFlightById(int id)
{
return _tunnelFlightRepository.GetCount(_identityService.ConnectedUser);
_tunnelFlightRepository.DeleteById(id);
}
public IEnumerable<TunnelFlight> GetTunnelFlightsByIndexes(int beginIndex, int endIndex)
public void UpdateTunnelFlight(int id, TunnelFlight updatedTunnelFlight)
{
return _tunnelFlightRepository.GetBetweenIndex(_identityService.ConnectedUser, beginIndex, endIndex);
}
public IEnumerable<TunnelFlight> GetTunnelFlightByDates(string beginDate, string endDate)
{
var convertedBeginDate = Convert.ToDateTime(beginDate);
var convertedEndDate = Convert.ToDateTime(endDate);
return _tunnelFlightRepository.GetBetweenDate(_identityService.ConnectedUser, convertedBeginDate, convertedEndDate);
var myTunnelFlight = GetTunnelFlightById(id);
myTunnelFlight.FlightDate = updatedTunnelFlight.FlightDate;
myTunnelFlight.NbMinutes = updatedTunnelFlight.NbMinutes;
myTunnelFlight.Notes = updatedTunnelFlight.Notes;
_tunnelFlightRepository.Update(myTunnelFlight);
}
#endregion Public Methods

View File

@@ -7,14 +7,14 @@ namespace skydiveLogs_api.DomainService.Repositories
{
#region Public Methods
bool DeleteById(int id);
IEnumerable<Jump> GetAll(User user);
IEnumerable<Jump> GetBetweenIndex(User user, int beginIndex, int endIndex);
int GetCount(User user);
bool DeleteById(int id);
#endregion Public Methods
}
}

View File

@@ -16,6 +16,8 @@ namespace skydiveLogs_api.DomainService.Repositories
int GetCount(User user);
bool DeleteById(int id);
#endregion Public Methods
}
}

View File

@@ -23,14 +23,6 @@ namespace skydiveLogs_api.Controllers
#region Public Methods
// DELETE: api/Tunnel/5
//[HttpDelete("{id}")]
//[EnableCors]
//public void Delete(int id)
//{
// _tunnelService.DeleteTunnelById(id);
//}
// GET: api/TunnelFlight
[HttpGet]
[EnableCors]
@@ -58,6 +50,15 @@ namespace skydiveLogs_api.Controllers
return _mapper.Map<IEnumerable<TunnelFlightResp>>(result);
}
// GET: api/TunnelFlight/month/20230101/20230701
[HttpGet("month/{beginDate}/{endDate}")]
[EnableCors]
public IEnumerable<StatisticResp> GetGroupByMonth(string beginDate, string endDate)
{
var result = _tunnelFlightService.GetTunnelFlightGroupByMonth(beginDate, endDate);
return _mapper.Map<IEnumerable<StatisticResp>>(result);
}
// POST: api/Tunnel
[HttpPost]
[EnableCors]
@@ -67,13 +68,21 @@ namespace skydiveLogs_api.Controllers
_mapper.Map<TunnelFlight>(value));
}
// PUT: api/Tunnel/5
//[HttpPut("{id}")]
//[EnableCors]
//public void Put(int id, [FromBody] TunnelReq value)
//{
// _tunnelService.UpdateJumpType(id, _mapper.Map<Tunnel>(value));
//}
// PUT: api/TunnelFlight/5
[HttpPut("{id}")]
[EnableCors]
public void Put(int id, [FromBody] TunnelFlightReq value)
{
_tunnelFlightService.UpdateTunnelFlight(id, _mapper.Map<TunnelFlight>(value));
}
// DELETE: api/TunnelFlight/5
[HttpDelete("{id}")]
[EnableCors]
public void Delete(int id)
{
_tunnelFlightService.DeleteTunnelFlightById(id);
}
#endregion Public Methods