Différencier Tunnel et TunnelFlight

This commit is contained in:
Sébastien ANDRE
2023-06-12 16:02:48 +02:00
parent 7856989866
commit da09a8d23b
14 changed files with 216 additions and 51 deletions

View File

@@ -15,6 +15,8 @@ namespace skydiveLogs_api.Domain
public string Notes { get; set; } public string Notes { get; set; }
public DateTime FlightDate { get; set; } public DateTime FlightDate { get; set; }
public User User { get; set; }
#endregion Public Properties #endregion Public Properties
} }

View File

@@ -0,0 +1,22 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface ITunnelFlightService
{
#region Public Methods
IEnumerable<TunnelFlight> GetAllTunnelFlights();
TunnelFlight GetTunnelFlightById(int id);
int GetTunnelFlightCount();
IEnumerable<TunnelFlight> GetTunnelFlightsByIndexes(int beginIndex, int endIndex);
void AddNewFlight(int tunnelId, TunnelFlight newFlight);
#endregion Public Methods
}
}

View File

@@ -11,8 +11,6 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
Tunnel GetTunnelById(int id); Tunnel GetTunnelById(int id);
void AddNewFlight(int tunnelId, TunnelFlight newFlight);
#endregion Public Methods #endregion Public Methods
} }
} }

View File

@@ -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<TunnelFlight> 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<TunnelFlight> 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
}
}

View File

@@ -12,13 +12,11 @@ namespace skydiveLogs_api.DomainBusiness
#region Public Constructors #region Public Constructors
public TunnelService(IDropZoneRepository dropZoneRepository, public TunnelService(IDropZoneRepository dropZoneRepository,
ITunnelFlightepository tunnelFlightRepository,
IDropZoneService dropZoneService, IDropZoneService dropZoneService,
ICacheService cacheService) ICacheService cacheService)
{ {
_dropZoneRepository = dropZoneRepository; _dropZoneRepository = dropZoneRepository;
_dropZoneService = dropZoneService; _dropZoneService = dropZoneService;
_tunnelFlightRepository = tunnelFlightRepository;
_cacheService = cacheService; _cacheService = cacheService;
} }
@@ -37,24 +35,6 @@ namespace skydiveLogs_api.DomainBusiness
return allTunnels.Single(g => g.Id == id); 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 #endregion Public Methods
#region Private Methods #region Private Methods
@@ -87,7 +67,6 @@ namespace skydiveLogs_api.DomainBusiness
private readonly ICacheService _cacheService; private readonly ICacheService _cacheService;
private readonly IDropZoneService _dropZoneService; private readonly IDropZoneService _dropZoneService;
private readonly IDropZoneRepository _dropZoneRepository; private readonly IDropZoneRepository _dropZoneRepository;
private readonly ITunnelFlightepository _tunnelFlightRepository;
#endregion Private Fields #endregion Private Fields
} }

View File

@@ -12,6 +12,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\skydiveLogs-api.DomainService\skydiveLogs-api.DomainService.csproj" /> <ProjectReference Include="..\skydiveLogs-api.DomainService\skydiveLogs-api.DomainService.csproj" />
<ProjectReference Include="..\skydiveLogs-api.Domain\skydiveLogs-api.Domain.csproj" /> <ProjectReference Include="..\skydiveLogs-api.Domain\skydiveLogs-api.Domain.csproj" />
<ProjectReference Include="..\skydiveLogs-api.Infrastructure\skydiveLogs-api.Infrastructure.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -0,0 +1,18 @@
using skydiveLogs_api.Domain;
using System.Collections.Generic;
namespace skydiveLogs_api.DomainService.Repositories
{
public interface ITunnelFlightRepository : IRepository<TunnelFlight>
{
#region Public Methods
IEnumerable<TunnelFlight> GetAll(User user);
IEnumerable<TunnelFlight> GetBetweenIndex(User user, int beginIndex, int endIndex);
int GetCount(User user);
#endregion Public Methods
}
}

View File

@@ -55,7 +55,7 @@ namespace skydiveLogs_api.Infrastructure
public IEnumerable<TunnelFlight> GetBetweenIndex(User user, int beginIndex, int endIndex) public IEnumerable<TunnelFlight> GetBetweenIndex(User user, int beginIndex, int endIndex)
{ {
return _col.Include(x => x.DropZone) return _col.Include(x => x.Tunnel)
.Query() .Query()
.OrderByDescending(j => j.FlightDate) .OrderByDescending(j => j.FlightDate)
.Where(j => j.User.Id == user.Id) .Where(j => j.User.Id == user.Id)

View File

@@ -37,6 +37,7 @@ namespace skydiveLogs_api.Ioc
_services.AddScoped<IUserImageService, UserImageService>(); _services.AddScoped<IUserImageService, UserImageService>();
_services.AddScoped<IInitDbService, InitDbService>(); _services.AddScoped<IInitDbService, InitDbService>();
_services.AddScoped<ITunnelService, TunnelService>(); _services.AddScoped<ITunnelService, TunnelService>();
_services.AddScoped<ITunnelFlightService, TunnelFlightService>();
_services.AddSingleton<ICacheService, CacheService>(); _services.AddSingleton<ICacheService, CacheService>();
_services.AddScoped<IIdentityService, IdentityService>(); _services.AddScoped<IIdentityService, IdentityService>();
@@ -51,6 +52,7 @@ namespace skydiveLogs_api.Ioc
_services.AddScoped<IUserImageRepository, UserImageRepository>(); _services.AddScoped<IUserImageRepository, UserImageRepository>();
_services.AddScoped<IFavoriteDropZoneRepository, FavoriteDropZoneRepository>(); _services.AddScoped<IFavoriteDropZoneRepository, FavoriteDropZoneRepository>();
_services.AddScoped<IUserStatsRepository, UserStatsRepository>(); _services.AddScoped<IUserStatsRepository, UserStatsRepository>();
_services.AddScoped<ITunnelFlightRepository, TunnelFlightRepository>();
string connectionString = _configuration.GetConnectionString("DefaultConnection"); string connectionString = _configuration.GetConnectionString("DefaultConnection");
_services.AddSingleton<IDataProvider>(c => new LiteDbProvider(connectionString)); _services.AddSingleton<IDataProvider>(c => new LiteDbProvider(connectionString));

View File

@@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using skydiveLogs_api.DataContract; using skydiveLogs_api.DataContract;
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DomainBusiness.Interfaces;
using System.Collections.Generic; using System.Collections.Generic;
@@ -23,14 +22,6 @@ namespace skydiveLogs_api.Controllers
#region Public Methods #region Public Methods
// DELETE: api/Tunnel/5
//[HttpDelete("{id}")]
//[EnableCors]
//public void Delete(int id)
//{
// _tunnelService.DeleteTunnelById(id);
//}
// GET: api/Tunnel // GET: api/Tunnel
[HttpGet] [HttpGet]
[EnableCors] [EnableCors]
@@ -49,23 +40,6 @@ namespace skydiveLogs_api.Controllers
return _mapper.Map<TunnelResp>(result); return _mapper.Map<TunnelResp>(result);
} }
// POST: api/Tunnel
[HttpPost]
[EnableCors]
public void Post([FromBody] TunnelFlightReq value)
{
_tunnelService.AddNewFlight(value.TunnelId,
_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));
//}
#endregion Public Methods #endregion Public Methods
#region Private Fields #region Private Fields

View File

@@ -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<TunnelFlightResp> Get()
{
var result = _tunnelFlightService.GetAllTunnelFlights();
return _mapper.Map<IEnumerable<TunnelFlightResp>>(result);
}
// GET: api/TunnelFlight/5
[HttpGet("{id}")]
[EnableCors]
public TunnelFlightResp Get(int id)
{
var result = _tunnelFlightService.GetTunnelFlightById(id);
return _mapper.Map<TunnelFlightResp>(result);
}
// POST: api/Tunnel
[HttpPost]
[EnableCors]
public void Post([FromBody] TunnelFlightReq value)
{
_tunnelFlightService.AddNewFlight(value.TunnelId,
_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));
//}
#endregion Public Methods
#region Private Fields
private readonly ITunnelFlightService _tunnelFlightService;
private readonly IMapper _mapper;
#endregion Private Fields
}
}

View File

@@ -14,4 +14,4 @@ namespace skydiveLogs_api.DataContract
public DateTime FlightDate { get; set; } public DateTime FlightDate { get; set; }
} }
} }

View File

@@ -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; }
}
}

View File

@@ -33,6 +33,7 @@ namespace skydiveLogs_api.Mapper
CreateMap<User, DataContract.UserResp>(); CreateMap<User, DataContract.UserResp>();
CreateMap<UserImage, DataContract.ImageResp>(); CreateMap<UserImage, DataContract.ImageResp>();
CreateMap<Tunnel, DataContract.TunnelResp>(); CreateMap<Tunnel, DataContract.TunnelResp>();
CreateMap<TunnelFlight, DataContract.TunnelFlightResp>();
CreateMap<SimpleSummary, DataContract.SimpleSummaryResp>(); CreateMap<SimpleSummary, DataContract.SimpleSummaryResp>();
} }