diff --git a/Back/skydiveLogs-api.Domain/TunnelFlight.cs b/Back/skydiveLogs-api.Domain/TunnelFlight.cs index 302cee8..81e9c48 100644 --- a/Back/skydiveLogs-api.Domain/TunnelFlight.cs +++ b/Back/skydiveLogs-api.Domain/TunnelFlight.cs @@ -15,6 +15,8 @@ namespace skydiveLogs_api.Domain public string Notes { get; set; } public DateTime FlightDate { get; set; } + + public User User { get; set; } #endregion Public Properties } diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelFlightService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelFlightService.cs new file mode 100644 index 0000000..af3cd61 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelFlightService.cs @@ -0,0 +1,22 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface ITunnelFlightService + { + #region Public Methods + + IEnumerable GetAllTunnelFlights(); + + TunnelFlight GetTunnelFlightById(int id); + + int GetTunnelFlightCount(); + + IEnumerable GetTunnelFlightsByIndexes(int beginIndex, int endIndex); + + void AddNewFlight(int tunnelId, TunnelFlight newFlight); + + #endregion Public Methods + } +} \ 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 193cead..4f18a62 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/ITunnelService.cs @@ -11,8 +11,6 @@ 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/TunnelFlightService.cs b/Back/skydiveLogs-api.DomainBusiness/TunnelFlightService.cs new file mode 100644 index 0000000..67da60b --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/TunnelFlightService.cs @@ -0,0 +1,73 @@ +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainBusiness +{ + public class TunnelFlightService : ITunnelFlightService + { + #region Public Constructors + + public TunnelFlightService(ITunnelFlightRepository tunnelFlightRepository, + IDropZoneService dropZoneService, + IIdentityService identityService) + { + _dropZoneService = dropZoneService; + _identityService = identityService; + _tunnelFlightRepository = tunnelFlightRepository; + } + + #endregion Public Constructors + + #region Public Methods + + public IEnumerable GetAllTunnelFlights() + { + return _tunnelFlightRepository.GetAll(_identityService.ConnectedUser); + } + + public TunnelFlight GetTunnelFlightById(int id) + { + return _tunnelFlightRepository.GetById(id); + } + + public void AddNewFlight(int tunnelId, TunnelFlight newFlight) + { + var tmp = _dropZoneService.GetDzById(tunnelId); + var selectedTunnel = new Tunnel + { + Id = tmp.Id, + Name = tmp.Name, + Website = tmp.Website, + Address = tmp.Address, + Email = tmp.Email, + Latitude = tmp.Latitude, + Longitude = tmp.Longitude + }; + + newFlight.Tunnel = selectedTunnel; + _tunnelFlightRepository.Add(newFlight); + } + + public int GetTunnelFlightCount() + { + return _tunnelFlightRepository.GetCount(_identityService.ConnectedUser); + } + + public IEnumerable GetTunnelFlightsByIndexes(int beginIndex, int endIndex) + { + return _tunnelFlightRepository.GetBetweenIndex(_identityService.ConnectedUser, beginIndex, endIndex); + } + + #endregion Public Methods + + #region Private Fields + + private readonly IDropZoneService _dropZoneService; + private readonly ITunnelFlightRepository _tunnelFlightRepository; + private readonly IIdentityService _identityService; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/TunnelService.cs b/Back/skydiveLogs-api.DomainBusiness/TunnelService.cs index 6e7c007..da89339 100644 --- a/Back/skydiveLogs-api.DomainBusiness/TunnelService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/TunnelService.cs @@ -12,13 +12,11 @@ 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; } @@ -37,24 +35,6 @@ 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 @@ -87,7 +67,6 @@ namespace skydiveLogs_api.DomainBusiness 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.DomainBusiness/skydiveLogs-api.DomainBusiness.csproj b/Back/skydiveLogs-api.DomainBusiness/skydiveLogs-api.DomainBusiness.csproj index 99d785a..3d895cc 100644 --- a/Back/skydiveLogs-api.DomainBusiness/skydiveLogs-api.DomainBusiness.csproj +++ b/Back/skydiveLogs-api.DomainBusiness/skydiveLogs-api.DomainBusiness.csproj @@ -12,6 +12,7 @@ + diff --git a/Back/skydiveLogs-api.DomainService/Repositories/ITunnelFlightRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/ITunnelFlightRepository.cs new file mode 100644 index 0000000..6a086f1 --- /dev/null +++ b/Back/skydiveLogs-api.DomainService/Repositories/ITunnelFlightRepository.cs @@ -0,0 +1,18 @@ +using skydiveLogs_api.Domain; +using System.Collections.Generic; + +namespace skydiveLogs_api.DomainService.Repositories +{ + public interface ITunnelFlightRepository : IRepository + { + #region Public Methods + + IEnumerable GetAll(User user); + + IEnumerable GetBetweenIndex(User user, int beginIndex, int endIndex); + + int GetCount(User user); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs b/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs index f409bee..bfb3e25 100644 --- a/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/TunnelFlightRepository.cs @@ -55,7 +55,7 @@ namespace skydiveLogs_api.Infrastructure public IEnumerable GetBetweenIndex(User user, int beginIndex, int endIndex) { - return _col.Include(x => x.DropZone) + return _col.Include(x => x.Tunnel) .Query() .OrderByDescending(j => j.FlightDate) .Where(j => j.User.Id == user.Id) diff --git a/Back/skydiveLogs-api.Ioc/IocService.cs b/Back/skydiveLogs-api.Ioc/IocService.cs index f947c45..b814839 100644 --- a/Back/skydiveLogs-api.Ioc/IocService.cs +++ b/Back/skydiveLogs-api.Ioc/IocService.cs @@ -37,6 +37,7 @@ namespace skydiveLogs_api.Ioc _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); + _services.AddScoped(); _services.AddSingleton(); _services.AddScoped(); @@ -51,6 +52,7 @@ namespace skydiveLogs_api.Ioc _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); + _services.AddScoped(); string connectionString = _configuration.GetConnectionString("DefaultConnection"); _services.AddSingleton(c => new LiteDbProvider(connectionString)); diff --git a/Back/skydiveLogs-api/Controllers/TunnelController.cs b/Back/skydiveLogs-api/Controllers/TunnelController.cs index b7094a4..60f00b7 100644 --- a/Back/skydiveLogs-api/Controllers/TunnelController.cs +++ b/Back/skydiveLogs-api/Controllers/TunnelController.cs @@ -2,7 +2,6 @@ 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; @@ -23,14 +22,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/Tunnel [HttpGet] [EnableCors] @@ -49,23 +40,6 @@ namespace skydiveLogs_api.Controllers return _mapper.Map(result); } - // POST: api/Tunnel - [HttpPost] - [EnableCors] - public void Post([FromBody] TunnelFlightReq value) - { - _tunnelService.AddNewFlight(value.TunnelId, - _mapper.Map(value)); - } - - // PUT: api/Tunnel/5 - //[HttpPut("{id}")] - //[EnableCors] - //public void Put(int id, [FromBody] TunnelReq value) - //{ - // _tunnelService.UpdateJumpType(id, _mapper.Map(value)); - //} - #endregion Public Methods #region Private Fields diff --git a/Back/skydiveLogs-api/Controllers/TunnelFlightController.cs b/Back/skydiveLogs-api/Controllers/TunnelFlightController.cs new file mode 100644 index 0000000..78b947e --- /dev/null +++ b/Back/skydiveLogs-api/Controllers/TunnelFlightController.cs @@ -0,0 +1,78 @@ +using AutoMapper; +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; + +namespace skydiveLogs_api.Controllers +{ + public class TunnelFlightController : Base + { + #region Public Constructors + + public TunnelFlightController(ITunnelFlightService tunnelFlightService, + IMapper mapper) + { + _tunnelFlightService = tunnelFlightService; + _mapper = mapper; + } + + #endregion Public Constructors + + #region Public Methods + + // DELETE: api/Tunnel/5 + //[HttpDelete("{id}")] + //[EnableCors] + //public void Delete(int id) + //{ + // _tunnelService.DeleteTunnelById(id); + //} + + // GET: api/TunnelFlight + [HttpGet] + [EnableCors] + public IEnumerable Get() + { + var result = _tunnelFlightService.GetAllTunnelFlights(); + return _mapper.Map>(result); + } + + // GET: api/TunnelFlight/5 + [HttpGet("{id}")] + [EnableCors] + public TunnelFlightResp Get(int id) + { + var result = _tunnelFlightService.GetTunnelFlightById(id); + return _mapper.Map(result); + } + + // POST: api/Tunnel + [HttpPost] + [EnableCors] + public void Post([FromBody] TunnelFlightReq value) + { + _tunnelFlightService.AddNewFlight(value.TunnelId, + _mapper.Map(value)); + } + + // PUT: api/Tunnel/5 + //[HttpPut("{id}")] + //[EnableCors] + //public void Put(int id, [FromBody] TunnelReq value) + //{ + // _tunnelService.UpdateJumpType(id, _mapper.Map(value)); + //} + + #endregion Public Methods + + #region Private Fields + + private readonly ITunnelFlightService _tunnelFlightService; + private readonly IMapper _mapper; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api/DataContract/TunnelFlightReq.cs b/Back/skydiveLogs-api/DataContract/TunnelFlightReq.cs index 51a7d40..112646c 100644 --- a/Back/skydiveLogs-api/DataContract/TunnelFlightReq.cs +++ b/Back/skydiveLogs-api/DataContract/TunnelFlightReq.cs @@ -14,4 +14,4 @@ namespace skydiveLogs_api.DataContract public DateTime FlightDate { get; set; } } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api/DataContract/TunnelFlightResp.cs b/Back/skydiveLogs-api/DataContract/TunnelFlightResp.cs new file mode 100644 index 0000000..91dc2ed --- /dev/null +++ b/Back/skydiveLogs-api/DataContract/TunnelFlightResp.cs @@ -0,0 +1,17 @@ +using System; + +namespace skydiveLogs_api.DataContract +{ + public class TunnelFlightResp + { + 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; } + } +} \ No newline at end of file diff --git a/Back/skydiveLogs-api/Mapper/ModelProfile.cs b/Back/skydiveLogs-api/Mapper/ModelProfile.cs index b18d291..fdfb83c 100644 --- a/Back/skydiveLogs-api/Mapper/ModelProfile.cs +++ b/Back/skydiveLogs-api/Mapper/ModelProfile.cs @@ -33,6 +33,7 @@ namespace skydiveLogs_api.Mapper CreateMap(); CreateMap(); CreateMap(); + CreateMap(); CreateMap(); }