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

@@ -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);
void AddNewFlight(int tunnelId, TunnelFlight newFlight);
#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
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
}

View File

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