From 7856989866499ff0ccad7dee47aee664e8e84cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20ANDRE?= Date: Fri, 19 May 2023 12:24:29 +0200 Subject: [PATCH] Add some update Add a TODO for the ideas --- Back/skydiveLogs-api.Domain/JumpType.cs | 2 + Back/skydiveLogs-api.Domain/TunnelFlight.cs | 21 ++++ .../Interfaces/ITunnelService.cs | 2 + .../TunnelService.cs | 31 +++++- .../Interfaces/IDataProvider.cs | 7 ++ .../LiteDbProvider.cs | 3 + .../TunnelFlightRepository.cs | 96 +++++++++++++++++++ .../Controllers/TunnelController.cs | 14 +-- .../DataContract/TunnelFlightReq.cs | 17 ++++ .../skydiveLogs-api/DataContract/TunnelReq.cs | 21 ---- Back/skydiveLogs-api/Mapper/ModelProfile.cs | 2 +- TODO.md | 11 +++ 12 files changed, 197 insertions(+), 30 deletions(-) create mode 100644 Back/skydiveLogs-api.Domain/TunnelFlight.cs create mode 100644 Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs create mode 100644 Back/skydiveLogs-api/DataContract/TunnelFlightReq.cs delete mode 100644 Back/skydiveLogs-api/DataContract/TunnelReq.cs create mode 100644 TODO.md diff --git a/Back/skydiveLogs-api.Domain/JumpType.cs b/Back/skydiveLogs-api.Domain/JumpType.cs index 1e1bf6d..4c5bdf8 100644 --- a/Back/skydiveLogs-api.Domain/JumpType.cs +++ b/Back/skydiveLogs-api.Domain/JumpType.cs @@ -8,6 +8,8 @@ public string Name { get; set; } + public string InTunnel { get; set; } + #endregion Public Properties } } \ No newline at end of file diff --git a/Back/skydiveLogs-api.Domain/TunnelFlight.cs b/Back/skydiveLogs-api.Domain/TunnelFlight.cs new file mode 100644 index 0000000..302cee8 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/TunnelFlight.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace skydiveLogs_api.Domain +{ + public class TunnelFlight + { + #region Public Properties + public int Id { get; set; } + + public Tunnel Tunnel { get; set; } + + public int NbMinutes { get; set; } + + public string Notes { get; set; } + + public DateTime FlightDate { get; set; } + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelService.cs index 4f18a62..193cead 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelService.cs @@ -11,6 +11,8 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces Tunnel GetTunnelById(int id); + void AddNewFlight(int tunnelId, TunnelFlight newFlight); + #endregion Public Methods } } \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/TunnelService.cs b/Back/skydiveLogs-api.DomainBusiness/TunnelService.cs index 13eace2..6e7c007 100644 --- a/Back/skydiveLogs-api.DomainBusiness/TunnelService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/TunnelService.cs @@ -12,9 +12,13 @@ namespace skydiveLogs_api.DomainBusiness #region Public Constructors public TunnelService(IDropZoneRepository dropZoneRepository, + ITunnelFlightepository tunnelFlightRepository, + IDropZoneService dropZoneService, ICacheService cacheService) { _dropZoneRepository = dropZoneRepository; + _dropZoneService = dropZoneService; + _tunnelFlightRepository = tunnelFlightRepository; _cacheService = cacheService; } @@ -33,6 +37,28 @@ namespace skydiveLogs_api.DomainBusiness return allTunnels.Single(g => g.Id == id); } + public void AddNewFlight(int tunnelId, TunnelFlight newFlight) + { + var selectedTunnel = _dropZoneService.GetDzById(tunnelId) + .Single(t => new Tunnel + { + Id = t.Id, + Name = t.Name, + Website = t.Website, + Address = t.Address, + Email = t.Email, + Latitude = t.Latitude, + Longitude = t.Longitude + }); ; + + newFlight.Tunnel = selectedTunnel; + _tunnelFlightRepository.Add(newFlight); + } + + #endregion Public Methods + + #region Private Methods + private IEnumerable GetAllRefTunnels() { if (!_cacheService.Contains(CacheType.Tunnel)) @@ -54,13 +80,14 @@ namespace skydiveLogs_api.DomainBusiness return _cacheService.Get>(CacheType.Tunnel); } - - #endregion Public Methods + #endregion Private Methods #region Private Fields private readonly ICacheService _cacheService; + private readonly IDropZoneService _dropZoneService; private readonly IDropZoneRepository _dropZoneRepository; + private readonly ITunnelFlightepository _tunnelFlightRepository; #endregion Private Fields } diff --git a/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs b/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs index be6e900..9590cbe 100644 --- a/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs +++ b/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs @@ -21,13 +21,20 @@ namespace skydiveLogs_api.Infrastructure.Interfaces ILiteCollection CollOfDropZone { get; } ILiteCollection CollOfFavoriteDropZone { get; } + ILiteCollection CollOfGear { get; } ILiteCollection CollOfImage { get; } + ILiteCollection CollOfJump { get; } + ILiteCollection CollOfJumpType { get; } + ILiteCollection CollOfStats { get; } + ILiteCollection CollOfUser { get; } + + ILiteCollection CollOfTunnelFlight { get; } #endregion Public Properties } diff --git a/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs b/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs index c540525..a324e7f 100644 --- a/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs +++ b/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs @@ -27,6 +27,8 @@ namespace skydiveLogs_api.Infrastructure BsonMapper.Global.Entity().DbRef(x => x.User, "User"); BsonMapper.Global.Entity().DbRef(x => x.DropZone, "DropZone"); + + BsonMapper.Global.Entity().DbRef(x => x.Tunnel, "DropZone"); } #endregion Public Constructors @@ -56,6 +58,7 @@ namespace skydiveLogs_api.Infrastructure public ILiteCollection CollOfJumpType => _db.GetCollection(); public ILiteCollection CollOfStats => _db.GetCollection(); public ILiteCollection CollOfUser => _db.GetCollection(); + public ILiteCollection CollOfTunnelFlight => _db.GetCollection(); #endregion Public Properties diff --git a/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs b/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs new file mode 100644 index 0000000..f409bee --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs @@ -0,0 +1,96 @@ +using LiteDB; +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Infrastructure.Interfaces; +using System.Collections.Generic; + +namespace skydiveLogs_api.Infrastructure +{ + public class TunnelFlightRepository : ITunnelFlightRepository + { + #region Public Constructors + + public TunnelFlightRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfTunnelFlight; + } + + #endregion Public Constructors + + #region Public Methods + + public int Add(TunnelFlight newTunnelFlight) + { + int result; + + try + { + var tmp = _col.Insert(newTunnelFlight); + result = tmp.AsInt32; + } + catch + { + result = 0; + } + + return result; + } + + public bool DeleteById(int id) + { + return _col.Delete(new BsonValue(id)); + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.Tunnel) + .Find(j => j.User.Id == user.Id); + } + + public IEnumerable GetAll() + { + throw new System.NotImplementedException(); + } + + public IEnumerable GetBetweenIndex(User user, int beginIndex, int endIndex) + { + return _col.Include(x => x.DropZone) + .Query() + .OrderByDescending(j => j.FlightDate) + .Where(j => j.User.Id == user.Id) + .Limit(endIndex - beginIndex) + .Offset(beginIndex) + .ToList(); + } + + public TunnelFlight GetById(int id) + { + return _col.FindById(new BsonValue(id)); + } + + public int GetCount(User user) + { + return _col.Count(j => j.User.Id == user.Id); + } + + public int GetCount() + { + throw new System.NotImplementedException(); + } + + public bool Update(TunnelFlight updatedTunnelFlight) + { + return _col.Update(updatedTunnelFlight); + } + + #endregion Public Methods + + #region Private Fields + + private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api/Controllers/TunnelController.cs b/Back/skydiveLogs-api/Controllers/TunnelController.cs index e543a28..b7094a4 100644 --- a/Back/skydiveLogs-api/Controllers/TunnelController.cs +++ b/Back/skydiveLogs-api/Controllers/TunnelController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using skydiveLogs_api.DataContract; +using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; using System.Collections.Generic; @@ -49,12 +50,13 @@ namespace skydiveLogs_api.Controllers } // POST: api/Tunnel - //[HttpPost] - //[EnableCors] - //public void Post([FromBody] TunnelReq value) - //{ - // _tunnelService.AddNewJumpType(_mapper.Map(value)); - //} + [HttpPost] + [EnableCors] + public void Post([FromBody] TunnelFlightReq value) + { + _tunnelService.AddNewFlight(value.TunnelId, + _mapper.Map(value)); + } // PUT: api/Tunnel/5 //[HttpPut("{id}")] diff --git a/Back/skydiveLogs-api/DataContract/TunnelFlightReq.cs b/Back/skydiveLogs-api/DataContract/TunnelFlightReq.cs new file mode 100644 index 0000000..51a7d40 --- /dev/null +++ b/Back/skydiveLogs-api/DataContract/TunnelFlightReq.cs @@ -0,0 +1,17 @@ +using System; + +namespace skydiveLogs_api.DataContract +{ + public class TunnelFlightReq + { + public int Id { get; set; } + + public int TunnelId { get; set; } + + public int NbMinutes { get; set; } + + public string Notes { get; set; } + + public DateTime FlightDate { get; set; } + } +} diff --git a/Back/skydiveLogs-api/DataContract/TunnelReq.cs b/Back/skydiveLogs-api/DataContract/TunnelReq.cs deleted file mode 100644 index 5317878..0000000 --- a/Back/skydiveLogs-api/DataContract/TunnelReq.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; - -namespace skydiveLogs_api.DataContract -{ - public class TunnelReq - { - public int Id { get; set; } - - public string Latitude { get; set; } - - public string Longitude { get; set; } - - public string Name { get; set; } - - public string Address { get; set; } - - public string Website { get; set; } - - public string Email { get; set; } - } -} diff --git a/Back/skydiveLogs-api/Mapper/ModelProfile.cs b/Back/skydiveLogs-api/Mapper/ModelProfile.cs index 4ca296b..b18d291 100644 --- a/Back/skydiveLogs-api/Mapper/ModelProfile.cs +++ b/Back/skydiveLogs-api/Mapper/ModelProfile.cs @@ -17,7 +17,7 @@ namespace skydiveLogs_api.Mapper CreateMap(); CreateMap(); CreateMap(); - CreateMap(); + CreateMap(); CreateMap(); CreateMap().ForMember(dest => dest.AircraftId, opt => opt.MapFrom(s => s.Aircraft.Id)) diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..7194ab1 --- /dev/null +++ b/TODO.md @@ -0,0 +1,11 @@ +BACK : + - JumpType : + - ajouter l'indication que le type de saut est faisable en tunnel + +FRONT : + - JumpType : + - ajouter dans la page un check-box pour indiquer que le type est faisable en tunnel + - permettre de mettre à jour le type sur l'info "en tunnel" + - Tunnel Flight + - la liste de type de vol filter pour ceux concernant par le tunnel + - avec juste 1 date \ No newline at end of file