Add a cache system on the referential info
+ Add an identity service
This commit is contained in:
@@ -1,25 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class DropZoneService : IDropZoneService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public DropZoneService(IDropZoneRepository dropZoneRepository,
|
||||
IFavoriteDropZoneRepository favoriteDropZoneRepository)
|
||||
IFavoriteDropZoneRepository favoriteDropZoneRepository,
|
||||
IIdentityService identityService,
|
||||
ICacheService cacheService)
|
||||
{
|
||||
_dropZoneRepository = dropZoneRepository;
|
||||
_favoriteDropZoneRepository = favoriteDropZoneRepository;
|
||||
_identityService = identityService;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddNewDz(DropZone newdropZone)
|
||||
{
|
||||
_dropZoneRepository.Add(newdropZone);
|
||||
_cacheService.Delete(CacheType.DropZone);
|
||||
}
|
||||
|
||||
public bool AddToFavorite(int dzId)
|
||||
{
|
||||
var dzToAddToFavorite = GetDzById(dzId);
|
||||
|
||||
var favoriteDz = new FavoriteDropZone
|
||||
{
|
||||
DropZone = dzToAddToFavorite,
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
|
||||
var result = _favoriteDropZoneRepository.Add(favoriteDz);
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
public void DeleteDzById(int id)
|
||||
@@ -27,12 +52,12 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<DropZone> GetAllDzs(User connectedUser)
|
||||
public IEnumerable<DropZone> GetAllDzs()
|
||||
{
|
||||
var results = Enumerable.Empty<DropZone>();
|
||||
|
||||
var dropzones = _dropZoneRepository.GetAll();
|
||||
var favorites = _favoriteDropZoneRepository.GetAll(connectedUser);
|
||||
var dropzones = GetAllRefDzs();
|
||||
var favorites = _favoriteDropZoneRepository.GetAll(_identityService.ConnectedUser);
|
||||
|
||||
results = from dropZone in dropzones
|
||||
join favorite in favorites on dropZone.Id equals favorite.DropZone.Id into tmp
|
||||
@@ -55,7 +80,15 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
public DropZone GetDzById(int id)
|
||||
{
|
||||
return _dropZoneRepository.GetById(id);
|
||||
var allDzs = GetAllRefDzs();
|
||||
return allDzs.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
public bool RemoveToFavorite(int dzId)
|
||||
{
|
||||
var result = _favoriteDropZoneRepository.Delete(dzId, _identityService.ConnectedUser.Id);
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
public bool UpdateDz(int id, DropZone dropZone)
|
||||
@@ -65,30 +98,25 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return _dropZoneRepository.Update(dropZone);
|
||||
}
|
||||
|
||||
public bool AddToFavorite(int dzId, User connectedUser)
|
||||
private IEnumerable<DropZone> GetAllRefDzs()
|
||||
{
|
||||
var dzToAddToFavorite = GetDzById(dzId);
|
||||
if (!_cacheService.Contains(CacheType.DropZone))
|
||||
_cacheService.Put(CacheType.DropZone,
|
||||
_dropZoneRepository.GetAll(),
|
||||
5 * 60 * 1000);
|
||||
|
||||
var favoriteDz = new FavoriteDropZone
|
||||
{
|
||||
DropZone = dzToAddToFavorite,
|
||||
User = connectedUser
|
||||
};
|
||||
|
||||
var result = _favoriteDropZoneRepository.Add(favoriteDz);
|
||||
|
||||
return result > 0;
|
||||
return _cacheService.Get<IEnumerable<DropZone>>(CacheType.DropZone);
|
||||
}
|
||||
|
||||
public bool RemoveToFavorite(int dzId, User connectedUser)
|
||||
{
|
||||
var result = _favoriteDropZoneRepository.Delete(dzId, connectedUser.Id);
|
||||
#endregion Public Methods
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
#region Private Fields
|
||||
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly IDropZoneRepository _dropZoneRepository;
|
||||
|
||||
private readonly IFavoriteDropZoneRepository _favoriteDropZoneRepository;
|
||||
private readonly IIdentityService _identityService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user