Différencier Tunnel et TunnelFlight
This commit is contained in:
@@ -16,6 +16,8 @@ namespace skydiveLogs_api.Domain
|
||||
|
||||
public DateTime FlightDate { get; set; }
|
||||
|
||||
public User User { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,6 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
|
||||
Tunnel GetTunnelById(int id);
|
||||
|
||||
void AddNewFlight(int tunnelId, TunnelFlight newFlight);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
73
Back/skydiveLogs-api.DomainBusiness/TunnelFlightService.cs
Normal file
73
Back/skydiveLogs-api.DomainBusiness/TunnelFlightService.cs
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
public IEnumerable<TunnelFlight> 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)
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace skydiveLogs_api.Ioc
|
||||
_services.AddScoped<IUserImageService, UserImageService>();
|
||||
_services.AddScoped<IInitDbService, InitDbService>();
|
||||
_services.AddScoped<ITunnelService, TunnelService>();
|
||||
_services.AddScoped<ITunnelFlightService, TunnelFlightService>();
|
||||
|
||||
_services.AddSingleton<ICacheService, CacheService>();
|
||||
_services.AddScoped<IIdentityService, IdentityService>();
|
||||
@@ -51,6 +52,7 @@ namespace skydiveLogs_api.Ioc
|
||||
_services.AddScoped<IUserImageRepository, UserImageRepository>();
|
||||
_services.AddScoped<IFavoriteDropZoneRepository, FavoriteDropZoneRepository>();
|
||||
_services.AddScoped<IUserStatsRepository, UserStatsRepository>();
|
||||
_services.AddScoped<ITunnelFlightRepository, TunnelFlightRepository>();
|
||||
|
||||
string connectionString = _configuration.GetConnectionString("DefaultConnection");
|
||||
_services.AddSingleton<IDataProvider>(c => new LiteDbProvider(connectionString));
|
||||
|
||||
@@ -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<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
|
||||
|
||||
#region Private Fields
|
||||
|
||||
78
Back/skydiveLogs-api/Controllers/TunnelFlightController.cs
Normal file
78
Back/skydiveLogs-api/Controllers/TunnelFlightController.cs
Normal 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
|
||||
}
|
||||
}
|
||||
17
Back/skydiveLogs-api/DataContract/TunnelFlightResp.cs
Normal file
17
Back/skydiveLogs-api/DataContract/TunnelFlightResp.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ namespace skydiveLogs_api.Mapper
|
||||
CreateMap<User, DataContract.UserResp>();
|
||||
CreateMap<UserImage, DataContract.ImageResp>();
|
||||
CreateMap<Tunnel, DataContract.TunnelResp>();
|
||||
CreateMap<TunnelFlight, DataContract.TunnelFlightResp>();
|
||||
|
||||
CreateMap<SimpleSummary, DataContract.SimpleSummaryResp>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user