Add controler, domain and service about "Tunnel"

This commit is contained in:
Sébastien ANDRE
2023-05-03 14:23:07 +02:00
parent 738b0aa439
commit 8b5a3f274e
11 changed files with 230 additions and 3 deletions

View File

@@ -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()

View File

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

View 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
}
}