Add a cache system on the referential info
+ Add an identity service
This commit is contained in:
@@ -1,28 +1,39 @@
|
||||
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 GearService : IGearService
|
||||
{
|
||||
public GearService(IGearRepository gearRepository)
|
||||
#region Public Constructors
|
||||
|
||||
public GearService(IGearRepository gearRepository,
|
||||
ICacheService cacheService,
|
||||
IIdentityService identityService)
|
||||
{
|
||||
_gearRepository = gearRepository;
|
||||
_cacheService = cacheService;
|
||||
_identityService = identityService;
|
||||
}
|
||||
|
||||
public void AddNewGear(Gear newGear,
|
||||
User connectedUser)
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddNewGear(Gear newGear)
|
||||
{
|
||||
newGear.User = connectedUser;
|
||||
newGear.User = _identityService.ConnectedUser;
|
||||
_gearRepository.Add(newGear);
|
||||
|
||||
var userId = _identityService.ConnectedUser.Id;
|
||||
_cacheService.Delete(CacheType.Gear, id: userId);
|
||||
}
|
||||
|
||||
public void AddRentalGear(User connectedUser)
|
||||
public void AddRentalGear(User newUser)
|
||||
{
|
||||
var rentalGear = new Gear
|
||||
{
|
||||
@@ -33,7 +44,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
MaxSize = 280,
|
||||
MinSize = 190,
|
||||
ReserveCanopy = "?",
|
||||
User = connectedUser
|
||||
User = newUser
|
||||
};
|
||||
|
||||
_gearRepository.Add(rentalGear);
|
||||
@@ -44,21 +55,39 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<Gear> GetAllGears()
|
||||
{
|
||||
var userId = _identityService.ConnectedUser.Id;
|
||||
if (!_cacheService.Contains(CacheType.Gear, id: userId))
|
||||
_cacheService.Put(CacheType.Gear,
|
||||
_gearRepository.GetAll(_identityService.ConnectedUser),
|
||||
5 * 60 * 1000,
|
||||
id: userId);
|
||||
|
||||
return _cacheService.Get<IEnumerable<Gear>>(CacheType.Gear, id: userId);
|
||||
}
|
||||
|
||||
public Gear GetGearById(int id)
|
||||
{
|
||||
return _gearRepository.GetById(id);
|
||||
var allGears = GetAllGears();
|
||||
return allGears.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
public IEnumerable<Gear> GetAllGears(User connectedUser)
|
||||
public bool UpdateGear(int id, Gear gear)
|
||||
{
|
||||
return _gearRepository.GetAll(connectedUser);
|
||||
gear.Id = id;
|
||||
|
||||
return _gearRepository.Update(gear);
|
||||
}
|
||||
|
||||
public void UpdateGear(int id, Gear Gear)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly IGearRepository _gearRepository;
|
||||
private readonly IIdentityService _identityService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user