Add controler, domain and service about "Tunnel"
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
Gear,
|
||||
JumpType,
|
||||
Aircraft,
|
||||
DropZone
|
||||
DropZone,
|
||||
Tunnel
|
||||
}
|
||||
}
|
||||
19
Back/skydiveLogs-api.Domain/Tunnel.cs
Normal file
19
Back/skydiveLogs-api.Domain/Tunnel.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class Tunnel
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public string Address { get; set; }
|
||||
public string Email { get; set; }
|
||||
public int Id { get; set; }
|
||||
public string Latitude { get; set; }
|
||||
public string Longitude { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Website { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
public bool RemoveToFavorite(int dzId)
|
||||
{
|
||||
var result = _favoriteDropZoneRepository.Delete(dzId, _identityService.ConnectedUser.Id);
|
||||
_cacheService.Delete(CacheType.DropZone);
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
@@ -95,7 +96,11 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
dropZone.Id = id;
|
||||
|
||||
return _dropZoneRepository.Update(dropZone);
|
||||
var result = _dropZoneRepository.Update(dropZone);
|
||||
if (result)
|
||||
_cacheService.Delete(CacheType.DropZone);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private IEnumerable<DropZone> GetAllRefDzs()
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface ITunnelService
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Tunnel> GetAllTunnels();
|
||||
|
||||
Tunnel GetTunnelById(int id);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
67
Back/skydiveLogs-api.DomainBusiness/TunnelService.cs
Normal file
67
Back/skydiveLogs-api.DomainBusiness/TunnelService.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class TunnelService : ITunnelService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public TunnelService(IDropZoneRepository dropZoneRepository,
|
||||
ICacheService cacheService)
|
||||
{
|
||||
_dropZoneRepository = dropZoneRepository;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public IEnumerable<Tunnel> GetAllTunnels()
|
||||
{
|
||||
return GetAllRefTunnels();
|
||||
}
|
||||
|
||||
public Tunnel GetTunnelById(int id)
|
||||
{
|
||||
var allTunnels = GetAllRefTunnels();
|
||||
return allTunnels.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
private IEnumerable<Tunnel> GetAllRefTunnels()
|
||||
{
|
||||
if (!_cacheService.Contains(CacheType.Tunnel))
|
||||
{
|
||||
var tmp = _dropZoneRepository.GetAll()
|
||||
.Where(d => d.Type.Contains("tunnel"))
|
||||
.Select(t => new Tunnel
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
Website = t.Website,
|
||||
Address = t.Address,
|
||||
Email = t.Email,
|
||||
Latitude = t.Latitude,
|
||||
Longitude = t.Longitude
|
||||
});
|
||||
_cacheService.Put(CacheType.Tunnel, tmp, 5 * 60 * 1000);
|
||||
}
|
||||
|
||||
return _cacheService.Get<IEnumerable<Tunnel>>(CacheType.Tunnel);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly IDropZoneRepository _dropZoneRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ namespace skydiveLogs_api.Ioc
|
||||
_services.AddScoped<IUserService, UserService>();
|
||||
_services.AddScoped<IUserImageService, UserImageService>();
|
||||
_services.AddScoped<IInitDbService, InitDbService>();
|
||||
_services.AddScoped<ITunnelService, TunnelService>();
|
||||
|
||||
_services.AddSingleton<ICacheService, CacheService>();
|
||||
_services.AddScoped<IIdentityService, IdentityService>();
|
||||
|
||||
76
Back/skydiveLogs-api/Controllers/TunnelController.cs
Normal file
76
Back/skydiveLogs-api/Controllers/TunnelController.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
public class TunnelController : Base
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public TunnelController(ITunnelService tunnelService,
|
||||
IMapper mapper)
|
||||
{
|
||||
_tunnelService = tunnelService;
|
||||
_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/Tunnel
|
||||
[HttpGet]
|
||||
[EnableCors]
|
||||
public IEnumerable<TunnelResp> Get()
|
||||
{
|
||||
var result = _tunnelService.GetAllTunnels();
|
||||
return _mapper.Map<IEnumerable<TunnelResp>>(result);
|
||||
}
|
||||
|
||||
// GET: api/Tunnel/5
|
||||
[HttpGet("{id}")]
|
||||
[EnableCors]
|
||||
public TunnelResp Get(int id)
|
||||
{
|
||||
var result = _tunnelService.GetTunnelById(id);
|
||||
return _mapper.Map<TunnelResp>(result);
|
||||
}
|
||||
|
||||
// POST: api/Tunnel
|
||||
//[HttpPost]
|
||||
//[EnableCors]
|
||||
//public void Post([FromBody] TunnelReq value)
|
||||
//{
|
||||
// _tunnelService.AddNewJumpType(_mapper.Map<Tunnel>(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 ITunnelService _tunnelService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
21
Back/skydiveLogs-api/DataContract/TunnelReq.cs
Normal file
21
Back/skydiveLogs-api/DataContract/TunnelReq.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
19
Back/skydiveLogs-api/DataContract/TunnelResp.cs
Normal file
19
Back/skydiveLogs-api/DataContract/TunnelResp.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace skydiveLogs_api.DataContract
|
||||
{
|
||||
public class TunnelResp
|
||||
{
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ namespace skydiveLogs_api.Mapper
|
||||
CreateMap<DataContract.GearReq, Gear>();
|
||||
CreateMap<DataContract.UserReq, User>();
|
||||
CreateMap<DataContract.ImageReq, UserImage>();
|
||||
CreateMap<DataContract.TunnelReq, Tunnel>();
|
||||
|
||||
CreateMap<Gear, DataContract.GearResp>();
|
||||
CreateMap<Jump, DataContract.JumpResp>().ForMember(dest => dest.AircraftId, opt => opt.MapFrom(s => s.Aircraft.Id))
|
||||
@@ -31,6 +32,7 @@ namespace skydiveLogs_api.Mapper
|
||||
CreateMap<Statistic, DataContract.StatisticResp>();
|
||||
CreateMap<User, DataContract.UserResp>();
|
||||
CreateMap<UserImage, DataContract.ImageResp>();
|
||||
CreateMap<Tunnel, DataContract.TunnelResp>();
|
||||
|
||||
CreateMap<SimpleSummary, DataContract.SimpleSummaryResp>();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.6" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.28.1" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.30.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user