From 894f28365481ecd16aea37893eef7185a0630b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20ANDRE?= Date: Thu, 22 Jun 2023 20:24:28 +0200 Subject: [PATCH] Add function to get the tunnel flights between dates --- .../Interfaces/ITunnelFlightService.cs | 2 ++ .../TunnelFlightService.cs | 10 ++++++++++ .../Repositories/ITunnelFlightRepository.cs | 3 +++ .../TunnelFlightRepository.cs | 11 +++++++++++ .../Controllers/TunnelFlightController.cs | 9 +++++++++ 5 files changed, 35 insertions(+) diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelFlightService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelFlightService.cs index af3cd61..78a9472 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelFlightService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelFlightService.cs @@ -15,6 +15,8 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces IEnumerable GetTunnelFlightsByIndexes(int beginIndex, int endIndex); + IEnumerable GetTunnelFlightByDates(string beginDate, string endDate); + void AddNewFlight(int tunnelId, TunnelFlight newFlight); #endregion Public Methods diff --git a/Back/skydiveLogs-api.DomainBusiness/TunnelFlightService.cs b/Back/skydiveLogs-api.DomainBusiness/TunnelFlightService.cs index 67da60b..4cfb426 100644 --- a/Back/skydiveLogs-api.DomainBusiness/TunnelFlightService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/TunnelFlightService.cs @@ -1,6 +1,7 @@ using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DomainService.Repositories; +using System; using System.Collections.Generic; namespace skydiveLogs_api.DomainBusiness @@ -60,6 +61,15 @@ namespace skydiveLogs_api.DomainBusiness return _tunnelFlightRepository.GetBetweenIndex(_identityService.ConnectedUser, beginIndex, endIndex); } + public IEnumerable GetTunnelFlightByDates(string beginDate, string endDate) + { + var convertedBeginDate = Convert.ToDateTime(beginDate); + var convertedEndDate = Convert.ToDateTime(endDate); + + return _tunnelFlightRepository.GetBetweenDate(_identityService.ConnectedUser, convertedBeginDate, convertedEndDate); + + } + #endregion Public Methods #region Private Fields diff --git a/Back/skydiveLogs-api.DomainService/Repositories/ITunnelFlightRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/ITunnelFlightRepository.cs index 6a086f1..e868d1e 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/ITunnelFlightRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/ITunnelFlightRepository.cs @@ -1,4 +1,5 @@ using skydiveLogs_api.Domain; +using System; using System.Collections.Generic; namespace skydiveLogs_api.DomainService.Repositories @@ -11,6 +12,8 @@ namespace skydiveLogs_api.DomainService.Repositories IEnumerable GetBetweenIndex(User user, int beginIndex, int endIndex); + IEnumerable GetBetweenDate(User user, DateTime beginDate, DateTime endDate); + int GetCount(User user); #endregion Public Methods diff --git a/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs b/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs index bfb3e25..f9a1dda 100644 --- a/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs @@ -2,6 +2,7 @@ using skydiveLogs_api.Domain; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure.Interfaces; +using System; using System.Collections.Generic; namespace skydiveLogs_api.Infrastructure @@ -64,6 +65,16 @@ namespace skydiveLogs_api.Infrastructure .ToList(); } + public IEnumerable GetBetweenDate(User user, DateTime beginDate, DateTime endDate) + { + return _col.Include(x => x.Tunnel) + .Query() + .OrderByDescending(j => j.FlightDate) + .Where(j => j.FlightDate >= beginDate) + .Where(j => j.FlightDate <= endDate) + .ToList(); + } + public TunnelFlight GetById(int id) { return _col.FindById(new BsonValue(id)); diff --git a/Back/skydiveLogs-api/Controllers/TunnelFlightController.cs b/Back/skydiveLogs-api/Controllers/TunnelFlightController.cs index 78b947e..6fc3269 100644 --- a/Back/skydiveLogs-api/Controllers/TunnelFlightController.cs +++ b/Back/skydiveLogs-api/Controllers/TunnelFlightController.cs @@ -49,6 +49,15 @@ namespace skydiveLogs_api.Controllers return _mapper.Map(result); } + // GET: api/TunnelFlight/20230101/20230701 + [HttpGet("{beginDate}/{endDate}")] + [EnableCors] + public TunnelFlightResp Get(string beginDate, string endDate) + { + var result = _tunnelFlightService.GetTunnelFlightByDates(beginDate, endDate); + return _mapper.Map(result); + } + // POST: api/Tunnel [HttpPost] [EnableCors]