Add a cache system on the referential info
+ Add an identity service
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -39,3 +39,4 @@
|
||||
/Back/skydiveLogs-api/Data/JumpsDb.db
|
||||
Back/skydiveLogs-api/Data/JumpsDb.db
|
||||
Back/skydiveLogs-api/Data/JumpsDb-log.db
|
||||
/Back/skydiveLogs-api.Domain/bin/Release/net5.0/skydiveLogs-api.Domain.deps.json
|
||||
|
||||
10
Back/skydiveLogs-api.Domain/CacheType.cs
Normal file
10
Back/skydiveLogs-api.Domain/CacheType.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public enum CacheType
|
||||
{
|
||||
Gear,
|
||||
JumpType,
|
||||
Aircraft,
|
||||
DropZone
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,31 @@
|
||||
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 AircraftService : IAircraftService
|
||||
{
|
||||
public AircraftService(IAircraftRepository aircraftRepository)
|
||||
#region Public Constructors
|
||||
|
||||
public AircraftService(IAircraftRepository aircraftRepository,
|
||||
ICacheService cacheService)
|
||||
{
|
||||
_aircraftRepository = aircraftRepository;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddNewAircraft(Aircraft newAircraft)
|
||||
{
|
||||
_aircraftRepository.Add(newAircraft);
|
||||
_cacheService.Delete(CacheType.Aircraft);
|
||||
}
|
||||
|
||||
public void DeleteAircraftById(int id)
|
||||
@@ -27,12 +35,18 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
public Aircraft GetAircraftById(int id)
|
||||
{
|
||||
return _aircraftRepository.GetById(id);
|
||||
var allAircrafts = GetAllAircrafts();
|
||||
return allAircrafts.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
public IEnumerable<Aircraft> GetAllAircrafts()
|
||||
{
|
||||
return _aircraftRepository.GetAll();
|
||||
if (!_cacheService.Contains(CacheType.Aircraft))
|
||||
_cacheService.Put(CacheType.Aircraft,
|
||||
_aircraftRepository.GetAll(),
|
||||
5 * 60 * 1000);
|
||||
|
||||
return _cacheService.Get<IEnumerable<Aircraft>>(CacheType.Aircraft);
|
||||
}
|
||||
|
||||
public void UpdateAircraft(int id, Aircraft aircraft)
|
||||
@@ -40,6 +54,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IAircraftRepository _aircraftRepository;
|
||||
private readonly ICacheService _cacheService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
51
Back/skydiveLogs-api.DomainBusiness/CacheService.cs
Normal file
51
Back/skydiveLogs-api.DomainBusiness/CacheService.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using System;
|
||||
using System.Runtime.Caching;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class CacheService : ICacheService
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
public bool Contains(CacheType type, int id = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
return MemoryCache.Default[key.ToString()] != null;
|
||||
}
|
||||
|
||||
public void Delete(CacheType type, int id = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
MemoryCache.Default.Remove(key.ToString());
|
||||
}
|
||||
|
||||
public T Get<T>(CacheType type, int id = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
return (T)MemoryCache.Default[key.ToString()];
|
||||
}
|
||||
|
||||
public void Put(CacheType type, object value, int duration, int id = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
if (duration <= 0)
|
||||
throw new ArgumentException("Duration cannot be less or equal to zero", "duration");
|
||||
|
||||
var policy = new CacheItemPolicy
|
||||
{
|
||||
AbsoluteExpiration = DateTime.Now.AddMilliseconds(duration)
|
||||
};
|
||||
|
||||
MemoryCache.Default.Set(key.ToString(), value, policy);
|
||||
}
|
||||
|
||||
private string GetKey(int id, CacheType type)
|
||||
{
|
||||
return $"{id}-{type}";
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Back/skydiveLogs-api.DomainBusiness/IdentityService.cs
Normal file
34
Back/skydiveLogs-api.DomainBusiness/IdentityService.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class IdentityService : IIdentityService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public IdentityService(ClaimsPrincipal user)
|
||||
{
|
||||
if (user != null
|
||||
&& user.Claims.Any())
|
||||
{
|
||||
var claims = user.Claims;
|
||||
|
||||
ConnectedUser = new User();
|
||||
ConnectedUser.Login = claims.Single(c => c.Type == ClaimTypes.Name).Value;
|
||||
ConnectedUser.Id = Convert.ToInt32(claims.Single(c => c.Type == ClaimTypes.UserData).Value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public User ConnectedUser { get; init; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class InitDbService : IInitDbService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public InitDbService(IAircraftService aircraftService,
|
||||
IJumpTypeService jumpTypeService,
|
||||
IDropZoneService dropZoneService,
|
||||
@@ -21,6 +21,10 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void GenerateDb()
|
||||
{
|
||||
LoadAircrafts();
|
||||
@@ -29,6 +33,39 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
AddAdmin();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void AddAdmin()
|
||||
{
|
||||
var adminUser = new User
|
||||
{
|
||||
FirstName = "Admin",
|
||||
LastName = "Admin",
|
||||
Login = "administrator",
|
||||
Password = "logsadmin",
|
||||
Email = "admin@nomail.com"
|
||||
};
|
||||
_userService.AddNewUser(adminUser, true);
|
||||
}
|
||||
|
||||
private void LoadAircrafts()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/aircraft.json");
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
var jsonModel = JsonSerializer.Deserialize<List<Aircraft>>(jsonString, options);
|
||||
|
||||
foreach (var item in jsonModel)
|
||||
{
|
||||
_aircraftService.AddNewAircraft(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadDropZones()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/dropZone.json");
|
||||
@@ -61,41 +98,16 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadAircrafts()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/aircraft.json");
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
var jsonModel = JsonSerializer.Deserialize<List<Aircraft>>(jsonString, options);
|
||||
#endregion Private Methods
|
||||
|
||||
foreach (var item in jsonModel)
|
||||
{
|
||||
_aircraftService.AddNewAircraft(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddAdmin()
|
||||
{
|
||||
var adminUser = new User
|
||||
{
|
||||
FirstName = "Admin",
|
||||
LastName = "Admin",
|
||||
Login = "administrator",
|
||||
Password = "logsadmin",
|
||||
Email = "admin@nomail.com"
|
||||
};
|
||||
_userService.AddNewUser(adminUser, true);
|
||||
}
|
||||
#region Private Fields
|
||||
|
||||
private readonly IAircraftService _aircraftService;
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
|
||||
private readonly IDropZoneService _dropZoneService;
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface ICacheService
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
bool Contains(CacheType type, int id = 0);
|
||||
|
||||
void Delete(CacheType type, int id = 0);
|
||||
|
||||
T Get<T>(CacheType type, int id = 0);
|
||||
|
||||
void Put(CacheType type, object value, int duration, int id = 0);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IDropZoneService
|
||||
{
|
||||
IEnumerable<DropZone> GetAllDzs(User connectedUser);
|
||||
|
||||
DropZone GetDzById(int id);
|
||||
|
||||
void DeleteDzById(int id);
|
||||
|
||||
bool UpdateDz(int id, DropZone dropZone);
|
||||
#region Public Methods
|
||||
|
||||
void AddNewDz(DropZone dropZone);
|
||||
|
||||
bool AddToFavorite(int dzId, User connectedUser);
|
||||
bool AddToFavorite(int dzId);
|
||||
|
||||
bool RemoveToFavorite(int dzId, User connectedUser);
|
||||
void DeleteDzById(int id);
|
||||
|
||||
IEnumerable<DropZone> GetAllDzs();
|
||||
|
||||
DropZone GetDzById(int id);
|
||||
|
||||
bool RemoveToFavorite(int dzId);
|
||||
|
||||
bool UpdateDz(int id, DropZone dropZone);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IGearService
|
||||
{
|
||||
IEnumerable<Gear> GetAllGears(User connectedUser);
|
||||
#region Public Methods
|
||||
|
||||
Gear GetGearById(int id);
|
||||
void AddNewGear(Gear gear);
|
||||
|
||||
void AddRentalGear(User newUser);
|
||||
|
||||
void DeleteGearById(int id);
|
||||
|
||||
void UpdateGear(int id, Gear gear);
|
||||
IEnumerable<Gear> GetAllGears();
|
||||
|
||||
void AddNewGear(Gear gear, User connectedUser);
|
||||
Gear GetGearById(int id);
|
||||
|
||||
void AddRentalGear(User connectedUser);
|
||||
bool UpdateGear(int id, Gear gear);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IIdentityService
|
||||
{
|
||||
User ConnectedUser { get; }
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,26 @@
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IJumpService
|
||||
{
|
||||
IEnumerable<Jump> GetAllJumps(User connectedUser);
|
||||
|
||||
Jump GetJumpById(int id);
|
||||
#region Public Methods
|
||||
|
||||
void AddNewJump(int aircraftId,
|
||||
int dzId,
|
||||
int jumpTypeId,
|
||||
int gearId,
|
||||
Jump jump,
|
||||
User connectedUser);
|
||||
Jump jump);
|
||||
|
||||
void DeleteJumpById(int id);
|
||||
|
||||
IEnumerable<Jump> GetAllJumps();
|
||||
|
||||
Jump GetJumpById(int id);
|
||||
|
||||
void UpdateJump(int id, Jump jump);
|
||||
|
||||
void DeleteJumpById(int id);
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IStatsService
|
||||
{
|
||||
IEnumerable<Statistic> GetStatsByDz(User connectedUser);
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStatsByAircraft(User connectedUser);
|
||||
SimpleSummary GetSimpleSummary();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByJumpType(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsByAircraft();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByGear(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsByDz();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByYear(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsByGear();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByDz(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsByJumpType();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByJumpType(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsByYear();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByDz(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByDz();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByJumpType(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByJumpType();
|
||||
|
||||
SimpleSummary GetSimpleSummary(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsForLastYearByDz();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByJumpType();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,22 @@
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IUserImageService
|
||||
{
|
||||
IEnumerable<UserImage> GetAllImages(User connectedUser);
|
||||
#region Public Methods
|
||||
|
||||
void AddNewImage(UserImage image);
|
||||
|
||||
void DeleteImageById(int id);
|
||||
|
||||
IEnumerable<UserImage> GetAllImages();
|
||||
|
||||
UserImage GetImageById(int id);
|
||||
|
||||
void AddNewImage(UserImage image, User connectedUser);
|
||||
|
||||
void UpdateImage(int id, UserImage image);
|
||||
|
||||
void DeleteImageById(int id);
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +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;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class JumpService : IJumpService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public JumpService(IJumpTypeService jumpTypeService,
|
||||
IAircraftService aircraftService,
|
||||
IDropZoneService dropZoneService,
|
||||
IGearService gearService,
|
||||
IJumpRepository jumpRepository)
|
||||
IJumpRepository jumpRepository,
|
||||
IIdentityService identityService)
|
||||
{
|
||||
_jumpTypeService = jumpTypeService;
|
||||
_aircraftService = aircraftService;
|
||||
_dropZoneService = dropZoneService;
|
||||
_gearService = gearService;
|
||||
_jumpRepository = jumpRepository;
|
||||
_identityService = identityService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddNewJump(int aircraftId,
|
||||
int dzId,
|
||||
int jumpTypeId,
|
||||
int gearId,
|
||||
Jump jump,
|
||||
User connectedUser)
|
||||
Jump jump)
|
||||
{
|
||||
var selectedGear = _gearService.GetGearById(gearId);
|
||||
var selectedJumpType = _jumpTypeService.GetJumpTypeById(jumpTypeId);
|
||||
@@ -39,7 +44,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
jump.JumpType = selectedJumpType;
|
||||
jump.DropZone = selectedDropZone;
|
||||
jump.Gear = selectedGear;
|
||||
jump.User = connectedUser;
|
||||
jump.User = _identityService.ConnectedUser;
|
||||
|
||||
_jumpRepository.Add(jump);
|
||||
}
|
||||
@@ -49,9 +54,9 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<Jump> GetAllJumps(User connectedUser)
|
||||
public IEnumerable<Jump> GetAllJumps()
|
||||
{
|
||||
return _jumpRepository.GetAll(connectedUser);
|
||||
return _jumpRepository.GetAll(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
public Jump GetJumpById(int id)
|
||||
@@ -64,14 +69,17 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IJumpRepository _jumpRepository;
|
||||
#endregion Public Methods
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
#region Private Fields
|
||||
|
||||
private readonly IAircraftService _aircraftService;
|
||||
|
||||
private readonly IDropZoneService _dropZoneService;
|
||||
|
||||
private readonly IGearService _gearService;
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpRepository _jumpRepository;
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,31 @@
|
||||
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 JumpTypeService : IJumpTypeService
|
||||
{
|
||||
public JumpTypeService(IJumpTypeRepository jumpTypeRepository)
|
||||
#region Public Constructors
|
||||
|
||||
public JumpTypeService(IJumpTypeRepository jumpTypeRepository,
|
||||
ICacheService cacheService)
|
||||
{
|
||||
_jumpTypeRepository = jumpTypeRepository;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddNewJumpType(JumpType newJumpType)
|
||||
{
|
||||
_jumpTypeRepository.Add(newJumpType);
|
||||
_cacheService.Delete(CacheType.JumpType);
|
||||
}
|
||||
|
||||
public void DeleteJumpTypeById(int id)
|
||||
@@ -27,12 +35,18 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
public IEnumerable<JumpType> GetAllJumpTypes()
|
||||
{
|
||||
return _jumpTypeRepository.GetAll();
|
||||
if (!_cacheService.Contains(CacheType.JumpType))
|
||||
_cacheService.Put(CacheType.JumpType,
|
||||
_jumpTypeRepository.GetAll(),
|
||||
5 * 60 * 1000);
|
||||
|
||||
return _cacheService.Get<IEnumerable<JumpType>>(CacheType.JumpType);
|
||||
}
|
||||
|
||||
public JumpType GetJumpTypeById(int id)
|
||||
{
|
||||
return _jumpTypeRepository.GetById(id);
|
||||
var allJumpTypes = GetAllJumpTypes();
|
||||
return allJumpTypes.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
public void UpdateJumpType(int id, JumpType value)
|
||||
@@ -40,6 +54,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly IJumpTypeRepository _jumpTypeRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,220 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class StatsService : IStatsService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public StatsService(IJumpService jumpService)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByAircraft(User connectedUser)
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public SimpleSummary GetSimpleSummary()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.Gear.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||
.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
|
||||
.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public SimpleSummary GetSimpleSummary(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new SimpleSummary();
|
||||
|
||||
if (allJumps.Any())
|
||||
@@ -232,6 +38,210 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.Gear.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
|
||||
.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||
.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IJumpService _jumpService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class UserImageService : IUserImageService
|
||||
{
|
||||
public UserImageService(IUserImageRepository imageRepository)
|
||||
#region Public Constructors
|
||||
|
||||
public UserImageService(IUserImageRepository imageRepository,
|
||||
IIdentityService identityService)
|
||||
{
|
||||
_imageRepository = imageRepository;
|
||||
_identityService = identityService;
|
||||
}
|
||||
|
||||
public void AddNewImage(UserImage newImage, User connectedUser)
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddNewImage(UserImage newImage)
|
||||
{
|
||||
newImage.User = connectedUser;
|
||||
newImage.User = _identityService.ConnectedUser;
|
||||
_imageRepository.Add(newImage);
|
||||
}
|
||||
|
||||
@@ -26,21 +32,28 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<UserImage> GetAllImages()
|
||||
{
|
||||
return _imageRepository.GetAll(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
public UserImage GetImageById(int id)
|
||||
{
|
||||
return _imageRepository.GetById(id);
|
||||
}
|
||||
|
||||
public IEnumerable<UserImage> GetAllImages(User connectedUser)
|
||||
{
|
||||
return _imageRepository.GetAll(connectedUser);
|
||||
}
|
||||
|
||||
public void UpdateImage(int id, UserImage Image)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IUserImageRepository _imageRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class UserService : IUserService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public UserService(IUserRepository userRepository,
|
||||
IGearService gearService)
|
||||
{
|
||||
@@ -19,15 +19,9 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
_gearService = gearService;
|
||||
}
|
||||
|
||||
public User GetById(int userId)
|
||||
{
|
||||
return _userRepository.GetById(userId);
|
||||
}
|
||||
#endregion Public Constructors
|
||||
|
||||
public User GetByLogin(string login, string password)
|
||||
{
|
||||
return _userRepository.GetByLogin(login, EncryptPassword(password));
|
||||
}
|
||||
#region Public Methods
|
||||
|
||||
public bool AddNewUser(User newUser, bool isAdmin = false)
|
||||
{
|
||||
@@ -51,9 +45,23 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return result;
|
||||
}
|
||||
|
||||
public User GetById(int userId)
|
||||
{
|
||||
return _userRepository.GetById(userId);
|
||||
}
|
||||
|
||||
public User GetByLogin(string login, string password)
|
||||
{
|
||||
return _userRepository.GetByLogin(login, EncryptPassword(password));
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string EncryptPassword(string password)
|
||||
{
|
||||
var encryptionKey = "skydivelogsangular"; //we can change the code converstion key as per our requirement
|
||||
var encryptionKey = "skydivelogsangular"; //we can change the code converstion key as per our requirement
|
||||
byte[] clearBytes = Encoding.Unicode.GetBytes(password);
|
||||
var encryptedPassword = string.Empty;
|
||||
|
||||
@@ -78,8 +86,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return encryptedPassword;
|
||||
}
|
||||
|
||||
private readonly IUserRepository _userRepository;
|
||||
#endregion Private Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IGearService _gearService;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@
|
||||
<RootNamespace>skydiveLogs_api.DomainBusiness</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Runtime.Caching" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\skydiveLogs-api.DomainService\skydiveLogs-api.DomainService.csproj" />
|
||||
<ProjectReference Include="..\skydiveLogs-api.Domain\skydiveLogs-api.Domain.csproj" />
|
||||
|
||||
@@ -1,37 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using LiteDB;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class JumpRepository : IJumpRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public JumpRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfJump;
|
||||
}
|
||||
|
||||
public IEnumerable<Jump> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.Aircraft)
|
||||
.Include(x => x.DropZone)
|
||||
.Include(x => x.Gear)
|
||||
.Include(x => x.JumpType)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.ToList();
|
||||
}
|
||||
#endregion Public Constructors
|
||||
|
||||
public Jump GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
#region Public Methods
|
||||
|
||||
public int Add(Jump newJump)
|
||||
{
|
||||
@@ -50,9 +37,15 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool Update(Jump updatedJump)
|
||||
public IEnumerable<Jump> GetAll(User user)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
return _col.Include(x => x.Aircraft)
|
||||
.Include(x => x.DropZone)
|
||||
.Include(x => x.Gear)
|
||||
.Include(x => x.JumpType)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<Jump> GetAll()
|
||||
@@ -60,8 +53,23 @@ namespace skydiveLogs_api.Infrastructure
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
public Jump GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
public bool Update(Jump updatedJump)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly ILiteCollection<Jump> _col;
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using skydiveLogs_api.DomainBusiness;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainBusiness;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Ioc
|
||||
{
|
||||
public class IocService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public IocService(IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
@@ -19,6 +20,10 @@ namespace skydiveLogs_api.Ioc
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void Configure()
|
||||
{
|
||||
_services.AddScoped<IAircraftService, AircraftService>();
|
||||
@@ -31,6 +36,10 @@ namespace skydiveLogs_api.Ioc
|
||||
_services.AddScoped<IUserImageService, UserImageService>();
|
||||
_services.AddScoped<IInitDbService, InitDbService>();
|
||||
|
||||
_services.AddSingleton<ICacheService, CacheService>();
|
||||
_services.AddScoped<IIdentityService, IdentityService>();
|
||||
_services.AddScoped(s => s.GetService<IHttpContextAccessor>()?.HttpContext.User);
|
||||
|
||||
_services.AddScoped<IAircraftRepository, AircraftRepository>();
|
||||
_services.AddScoped<IDropZoneRepository, DropZoneRepository>();
|
||||
_services.AddScoped<IJumpRepository, JumpRepository>();
|
||||
@@ -39,13 +48,18 @@ namespace skydiveLogs_api.Ioc
|
||||
_services.AddScoped<IUserRepository, UserRepository>();
|
||||
_services.AddScoped<IUserImageRepository, UserImageRepository>();
|
||||
_services.AddScoped<IFavoriteDropZoneRepository, FavoriteDropZoneRepository>();
|
||||
|
||||
|
||||
string connectionString = _configuration.GetConnectionString("DefaultConnection");
|
||||
_services.AddSingleton<IDataProvider>(c => new LiteDbProvider(connectionString));
|
||||
}
|
||||
|
||||
private readonly IServiceCollection _services;
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IServiceCollection _services;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@
|
||||
<RootNamespace>skydiveLogs_api.Ioc</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\skydiveLogs-api.Infrastructure\skydiveLogs-api.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\skydiveLogs-api.DomainBusiness\skydiveLogs-api.DomainBusiness.csproj" />
|
||||
|
||||
@@ -8,11 +8,12 @@ using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DataContract;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
public class DropZoneController : Base
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public DropZoneController(IDropZoneService dropZoneService,
|
||||
IMapper mapper)
|
||||
{
|
||||
@@ -20,12 +21,32 @@ namespace skydiveLogs_api.Controllers
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// PUT: api/DropZone/AddToFavorite/5
|
||||
[HttpPut("AddToFavorite/{id}")]
|
||||
[EnableCors]
|
||||
public bool AddToFavorite(int id)
|
||||
{
|
||||
return _dropZoneService.AddToFavorite(id);
|
||||
}
|
||||
|
||||
// DELETE: api/ApiWithActions
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_dropZoneService.DeleteDzById(id);
|
||||
}
|
||||
|
||||
// GET: api/DropZone
|
||||
[HttpGet]
|
||||
[EnableCors]
|
||||
public IEnumerable<DropZoneResp> Get()
|
||||
{
|
||||
var result = _dropZoneService.GetAllDzs(ConnectedUser);
|
||||
var result = _dropZoneService.GetAllDzs();
|
||||
|
||||
return _mapper.Map<IEnumerable<DropZoneResp>>(result);
|
||||
}
|
||||
@@ -56,31 +77,21 @@ namespace skydiveLogs_api.Controllers
|
||||
return _dropZoneService.UpdateDz(id, _mapper.Map<DropZone>(value));
|
||||
}
|
||||
|
||||
// DELETE: api/ApiWithActions
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_dropZoneService.DeleteDzById(id);
|
||||
}
|
||||
|
||||
// PUT: api/DropZone/AddToFavorite/5
|
||||
[HttpPut("AddToFavorite/{id}")]
|
||||
[EnableCors]
|
||||
public bool AddToFavorite(int id)
|
||||
{
|
||||
return _dropZoneService.AddToFavorite(id, ConnectedUser);
|
||||
}
|
||||
|
||||
// PUT: api/DropZone/RemoveToFavorite/15
|
||||
[HttpPut("RemoveToFavorite/{id}")]
|
||||
[EnableCors]
|
||||
public bool RemoveToFavorite(int id)
|
||||
{
|
||||
return _dropZoneService.RemoveToFavorite(id, ConnectedUser);
|
||||
return _dropZoneService.RemoveToFavorite(id);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IDropZoneService _dropZoneService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,12 @@ using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DataContract;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
public class GearController : Base
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public GearController(IGearService gearService,
|
||||
IMapper mapper)
|
||||
{
|
||||
@@ -20,12 +21,25 @@ namespace skydiveLogs_api.Controllers
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// DELETE: api/ApiWithActions/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_gearService.DeleteGearById(id);
|
||||
}
|
||||
|
||||
// GET: api/Gear
|
||||
[HttpGet]
|
||||
[EnableCors]
|
||||
public IEnumerable<GearResp> Get()
|
||||
{
|
||||
var result = _gearService.GetAllGears(ConnectedUser);
|
||||
//var result = _gearService.GetAllGears(ConnectedUser);
|
||||
var result = _gearService.GetAllGears();
|
||||
return _mapper.Map<IEnumerable<GearResp>>(result);
|
||||
}
|
||||
|
||||
@@ -43,7 +57,7 @@ namespace skydiveLogs_api.Controllers
|
||||
[EnableCors]
|
||||
public void Post([FromBody] GearReq value)
|
||||
{
|
||||
_gearService.AddNewGear(_mapper.Map<Gear>(value), ConnectedUser);
|
||||
_gearService.AddNewGear(_mapper.Map<Gear>(value));
|
||||
}
|
||||
|
||||
// PUT: api/Gear/5
|
||||
@@ -54,16 +68,14 @@ namespace skydiveLogs_api.Controllers
|
||||
_gearService.UpdateGear(id, _mapper.Map<Gear>(value));
|
||||
}
|
||||
|
||||
// DELETE: api/ApiWithActions/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_gearService.DeleteGearById(id);
|
||||
}
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IGearService _gearService;
|
||||
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,12 @@ using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DataContract;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
public class ImageController : Base
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public ImageController(IUserImageService imageService,
|
||||
IMapper mapper)
|
||||
{
|
||||
@@ -20,12 +21,24 @@ namespace skydiveLogs_api.Controllers
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// DELETE: api/Image/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_imageService.DeleteImageById(id);
|
||||
}
|
||||
|
||||
// GET: api/Image
|
||||
[HttpGet]
|
||||
[EnableCors]
|
||||
public IEnumerable<ImageResp> Get()
|
||||
{
|
||||
var result = _imageService.GetAllImages(ConnectedUser);
|
||||
var result = _imageService.GetAllImages();
|
||||
return _mapper.Map<IEnumerable<ImageResp>>(result);
|
||||
}
|
||||
|
||||
@@ -43,7 +56,7 @@ namespace skydiveLogs_api.Controllers
|
||||
[EnableCors]
|
||||
public void Post([FromBody] ImageReq value)
|
||||
{
|
||||
_imageService.AddNewImage(_mapper.Map<UserImage>(value), ConnectedUser);
|
||||
_imageService.AddNewImage(_mapper.Map<UserImage>(value));
|
||||
}
|
||||
|
||||
// PUT: api/Image/5
|
||||
@@ -54,15 +67,13 @@ namespace skydiveLogs_api.Controllers
|
||||
_imageService.UpdateImage(id, _mapper.Map<UserImage>(value));
|
||||
}
|
||||
|
||||
// DELETE: api/Image/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_imageService.DeleteImageById(id);
|
||||
}
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IUserImageService _imageService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DataContract;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
public class JumpController : Base
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public JumpController(IJumpService jumpService,
|
||||
IMapper mapper)
|
||||
{
|
||||
@@ -20,12 +19,24 @@ namespace skydiveLogs_api.Controllers
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// DELETE: api/Jump/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_jumpService.DeleteJumpById(id);
|
||||
}
|
||||
|
||||
// GET: api/Jump
|
||||
[HttpGet]
|
||||
[EnableCors]
|
||||
public IEnumerable<JumpResp> Get()
|
||||
{
|
||||
var result = _jumpService.GetAllJumps(ConnectedUser);
|
||||
var result = _jumpService.GetAllJumps();
|
||||
|
||||
return _mapper.Map<IEnumerable<JumpResp>>(result);
|
||||
}
|
||||
@@ -48,8 +59,7 @@ namespace skydiveLogs_api.Controllers
|
||||
value.DropZoneId,
|
||||
value.JumpTypeId,
|
||||
value.GearId,
|
||||
_mapper.Map<Jump>(value),
|
||||
ConnectedUser);
|
||||
_mapper.Map<Jump>(value));
|
||||
}
|
||||
|
||||
// PUT: api/Jump/5
|
||||
@@ -60,15 +70,13 @@ namespace skydiveLogs_api.Controllers
|
||||
_jumpService.UpdateJump(id, _mapper.Map<Jump>(value));
|
||||
}
|
||||
|
||||
// DELETE: api/Jump/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_jumpService.DeleteJumpById(id);
|
||||
}
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IJumpService _jumpService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using skydiveLogs_api.DataContract;
|
||||
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
public class StatsController : Base
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public StatsController(IStatsService statsService,
|
||||
IMapper mapper)
|
||||
{
|
||||
@@ -19,38 +18,24 @@ namespace skydiveLogs_api.Controllers
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("Simple")]
|
||||
[EnableCors]
|
||||
public SimpleSummaryResp Simple()
|
||||
{
|
||||
var result = _statsService.GetSimpleSummary(ConnectedUser);
|
||||
#endregion Public Constructors
|
||||
|
||||
return _mapper.Map<SimpleSummaryResp>(result);
|
||||
#region Public Methods
|
||||
|
||||
[HttpGet("ByAircraft")]
|
||||
[EnableCors]
|
||||
public IEnumerable<StatisticResp> ByAircraft()
|
||||
{
|
||||
var result = _statsService.GetStatsByAircraft();
|
||||
|
||||
return _mapper.Map<IEnumerable<StatisticResp>>(result);
|
||||
}
|
||||
|
||||
[HttpGet("ByDz")]
|
||||
[EnableCors]
|
||||
public IEnumerable<StatisticResp> ByDz()
|
||||
{
|
||||
var result = _statsService.GetStatsByDz(ConnectedUser);
|
||||
|
||||
return _mapper.Map<IEnumerable<StatisticResp>>(result);
|
||||
}
|
||||
|
||||
[HttpGet("ByAircraft")]
|
||||
[EnableCors]
|
||||
public IEnumerable<StatisticResp> ByAircraft()
|
||||
{
|
||||
var result = _statsService.GetStatsByAircraft(ConnectedUser);
|
||||
|
||||
return _mapper.Map<IEnumerable<StatisticResp>>(result);
|
||||
}
|
||||
|
||||
[HttpGet("ByJumpType")]
|
||||
[EnableCors]
|
||||
public IEnumerable<StatisticResp> ByJumpType()
|
||||
{
|
||||
var result = _statsService.GetStatsByJumpType(ConnectedUser);
|
||||
var result = _statsService.GetStatsByDz();
|
||||
|
||||
return _mapper.Map<IEnumerable<StatisticResp>>(result);
|
||||
}
|
||||
@@ -59,7 +44,16 @@ namespace skydiveLogs_api.Controllers
|
||||
[EnableCors]
|
||||
public IEnumerable<StatisticResp> ByGear()
|
||||
{
|
||||
var result = _statsService.GetStatsByGear(ConnectedUser);
|
||||
var result = _statsService.GetStatsByGear();
|
||||
|
||||
return _mapper.Map<IEnumerable<StatisticResp>>(result);
|
||||
}
|
||||
|
||||
[HttpGet("ByJumpType")]
|
||||
[EnableCors]
|
||||
public IEnumerable<StatisticResp> ByJumpType()
|
||||
{
|
||||
var result = _statsService.GetStatsByJumpType();
|
||||
|
||||
return _mapper.Map<IEnumerable<StatisticResp>>(result);
|
||||
}
|
||||
@@ -68,31 +62,17 @@ namespace skydiveLogs_api.Controllers
|
||||
[EnableCors]
|
||||
public IEnumerable<StatisticResp> ByYear()
|
||||
{
|
||||
var result = _statsService.GetStatsByYear(ConnectedUser);
|
||||
var result = _statsService.GetStatsByYear();
|
||||
|
||||
return _mapper.Map<IEnumerable<StatisticResp>>(result);
|
||||
}
|
||||
|
||||
[HttpGet("ForLastYear")]
|
||||
[EnableCors]
|
||||
public StatisticForLastYearResp ForLastYear()
|
||||
{
|
||||
var resultByDz = _statsService.GetStatsForLastYearByDz(ConnectedUser);
|
||||
var resultByJumpType = _statsService.GetStatsForLastYearByJumpType(ConnectedUser);
|
||||
|
||||
var result = new StatisticForLastYearResp();
|
||||
result.ByDz = _mapper.Map<IEnumerable<StatisticResp>>(resultByDz);
|
||||
result.ByJumpType = _mapper.Map<IEnumerable<StatisticResp>>(resultByJumpType);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet("ForLastMonth")]
|
||||
[EnableCors]
|
||||
public StatisticForLastMonthResp ForLastMonth()
|
||||
{
|
||||
var resultByDz = _statsService.GetStatsForLastMonthByDz(ConnectedUser);
|
||||
var resultByJumpType = _statsService.GetStatsForLastMonthByJumpType(ConnectedUser);
|
||||
var resultByDz = _statsService.GetStatsForLastMonthByDz();
|
||||
var resultByJumpType = _statsService.GetStatsForLastMonthByJumpType();
|
||||
|
||||
var result = new StatisticForLastMonthResp();
|
||||
result.ByDz = _mapper.Map<IEnumerable<StatisticResp>>(resultByDz);
|
||||
@@ -101,10 +81,36 @@ namespace skydiveLogs_api.Controllers
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet("ForLastYear")]
|
||||
[EnableCors]
|
||||
public StatisticForLastYearResp ForLastYear()
|
||||
{
|
||||
var resultByDz = _statsService.GetStatsForLastYearByDz();
|
||||
var resultByJumpType = _statsService.GetStatsForLastYearByJumpType();
|
||||
|
||||
var result = new StatisticForLastYearResp();
|
||||
result.ByDz = _mapper.Map<IEnumerable<StatisticResp>>(resultByDz);
|
||||
result.ByJumpType = _mapper.Map<IEnumerable<StatisticResp>>(resultByJumpType);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet("Simple")]
|
||||
[EnableCors]
|
||||
public SimpleSummaryResp Simple()
|
||||
{
|
||||
var result = _statsService.GetSimpleSummary();
|
||||
|
||||
return _mapper.Map<SimpleSummaryResp>(result);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private properties
|
||||
private readonly IStatsService _statsService;
|
||||
|
||||
private readonly IMapper _mapper;
|
||||
#endregion
|
||||
private readonly IStatsService _statsService;
|
||||
|
||||
#endregion Private properties
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,22 +13,48 @@ using skydiveLogs_api.Ioc;
|
||||
using skydiveLogs_api.Settings;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.EnvironmentName == "Development")
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseCors();
|
||||
app.UseAuthentication();
|
||||
|
||||
app.UseMvc();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddMvc(options => { options.EnableEndpointRouting = false; })
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
|
||||
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
// JWT
|
||||
var jwtSection = Configuration.GetSection("JWT");
|
||||
services.Configure<JwtSettings>(jwtSection);
|
||||
@@ -77,24 +103,9 @@ namespace skydiveLogs_api
|
||||
CheckAndInitDb(services);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.EnvironmentName == "Development")
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
#endregion Public Methods
|
||||
|
||||
app.UseCors();
|
||||
app.UseAuthentication();
|
||||
|
||||
app.UseMvc();
|
||||
}
|
||||
#region Private Methods
|
||||
|
||||
private void CheckAndInitDb(IServiceCollection services)
|
||||
{
|
||||
@@ -109,6 +120,12 @@ namespace skydiveLogs_api
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user