Add comments by AI
This commit is contained in:
@@ -11,6 +11,11 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AircraftService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="aircraftRepository">The aircraft repository for data access.</param>
|
||||
/// <param name="cacheService">The cache service for caching operations.</param>
|
||||
public AircraftService(IAircraftRepository aircraftRepository,
|
||||
ICacheService cacheService)
|
||||
{
|
||||
@@ -22,23 +27,40 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new aircraft to the system.
|
||||
/// </summary>
|
||||
/// <param name="newAircraft">The Aircraft entity containing the data for the new aircraft.</param>
|
||||
public void AddNewAircraft(Aircraft newAircraft)
|
||||
{
|
||||
_aircraftRepository.Add(newAircraft);
|
||||
_cacheService.Delete(CacheType.Aircraft);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an aircraft by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The aircraft ID to delete.</param>
|
||||
public void DeleteAircraftById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an aircraft by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The aircraft ID to retrieve.</param>
|
||||
/// <returns>An Aircraft entity containing the aircraft details.</returns>
|
||||
public Aircraft GetAircraftById(int id)
|
||||
{
|
||||
var allAircrafts = GetAllAircrafts();
|
||||
return allAircrafts.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all aircrafts.
|
||||
/// </summary>
|
||||
/// <returns>A collection of Aircraft entities containing all aircraft data.</returns>
|
||||
public IEnumerable<Aircraft> GetAllAircrafts()
|
||||
{
|
||||
if (!_cacheService.Contains(CacheType.Aircraft))
|
||||
@@ -49,6 +71,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return _cacheService.Get<IEnumerable<Aircraft>>(CacheType.Aircraft);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing aircraft.
|
||||
/// </summary>
|
||||
/// <param name="id">The aircraft ID to update.</param>
|
||||
/// <param name="aircraft">Aircraft entity containing the updated aircraft data.</param>
|
||||
/// <param name="resetCache">Whether to reset the cache after update.</param>
|
||||
/// <returns>True if the update was successful, false otherwise.</returns>
|
||||
public bool UpdateAircraft(int id, Aircraft aircraft, bool resetCache = true)
|
||||
{
|
||||
aircraft.Id = id;
|
||||
|
||||
@@ -24,24 +24,50 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a specific cache entry exists for a given type and user ID.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of data to check for in the cache.</param>
|
||||
/// <param name="userId">Optional user ID to distinguish cache entries. Default is 0.</param>
|
||||
/// <returns>True if the cache entry exists and is valid, otherwise false.</returns>
|
||||
public bool Contains(CacheType type, int userId = 0)
|
||||
{
|
||||
var key = GetKey(userId, type);
|
||||
return _memoryCache.Contains(key.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a cache entry from the store.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of data to remove from the cache.</param>
|
||||
/// <param name="userId">Optional user ID to identify the cache entry. Default is 0.</param>
|
||||
public void Delete(CacheType type, int userId = 0)
|
||||
{
|
||||
var key = GetKey(userId, type);
|
||||
_memoryCache.Remove(key.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves data from the cache for a specified type and user ID.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The expected type of the cached data.</typeparam>
|
||||
/// <param name="type">The type of data to retrieve from the cache.</param>
|
||||
/// <param name="userId">Optional user ID to identify the cache entry. Default is 0.</param>
|
||||
/// <returns>The cached data cast to type T, or default(T) if not found or expired.</returns>
|
||||
public T Get<T>(CacheType type, int userId = 0)
|
||||
{
|
||||
var key = GetKey(userId, type);
|
||||
return (T)_memoryCache.Get(key.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stores data in the cache with a specified expiry time.
|
||||
/// </summary>
|
||||
/// <param name="type">The unique identifier for the cache key.</param>
|
||||
/// <param name="value">The object data to be cached.</param>
|
||||
/// <param name="duration">The duration in milliseconds before the cache entry expires.</param>
|
||||
/// <param name="userId">Optional user ID to distinguish cache entries. Default is 0.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when duration is less than or equal to zero.</exception>
|
||||
public void Put(CacheType type, object value, int duration, int userId = 0)
|
||||
{
|
||||
var key = GetKey(userId, type);
|
||||
@@ -56,6 +82,12 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
_memoryCache.Set(key.ToString(), value, policy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a cache key by combining the user ID and cache type.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user ID to include in the key.</param>
|
||||
/// <param name="type">The cache type to include in the key.</param>
|
||||
/// <returns>A concatenated string key combining userId and type.</returns>
|
||||
private string GetKey(int userId, CacheType type)
|
||||
{
|
||||
return $"{userId}-{type}";
|
||||
|
||||
@@ -26,12 +26,21 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new drop zone to the system.
|
||||
/// </summary>
|
||||
/// <param name="newdropZone">The DropZone entity containing the new drop zone data.</param>
|
||||
public void AddNewDz(DropZone newdropZone)
|
||||
{
|
||||
_dropZoneRepository.Add(newdropZone);
|
||||
_cacheService.Delete(CacheType.DropZone);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a drop zone to the user's favorites.
|
||||
/// </summary>
|
||||
/// <param name="dzId">The drop zone ID to add to favorites.</param>
|
||||
/// <returns>True if the drop zone was added to favorites, false otherwise.</returns>
|
||||
public bool AddToFavorite(int dzId)
|
||||
{
|
||||
var dzToAddToFavorite = GetDzById(dzId);
|
||||
@@ -47,11 +56,19 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a drop zone by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The drop zone ID to delete.</param>
|
||||
public void DeleteDzById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a list of all drop zones with favorites status.
|
||||
/// </summary>
|
||||
/// <returns>A collection of DropZone entities containing all drop zones with their favorite status.</returns>
|
||||
public IEnumerable<DropZone> GetAllDzs()
|
||||
{
|
||||
var results = Enumerable.Empty<DropZone>();
|
||||
@@ -78,12 +95,22 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return results.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a drop zone by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The drop zone ID to retrieve.</param>
|
||||
/// <returns>A DropZone entity containing the drop zone details.</returns>
|
||||
public DropZone GetDzById(int id)
|
||||
{
|
||||
var allDzs = GetAllRefDzs();
|
||||
return allDzs.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a drop zone from the user's favorites.
|
||||
/// </summary>
|
||||
/// <param name="dzId">The drop zone ID to remove from favorites.</param>
|
||||
/// <returns>True if the drop zone was removed from favorites, false otherwise.</returns>
|
||||
public bool RemoveToFavorite(int dzId)
|
||||
{
|
||||
var result = _favoriteDropZoneRepository.Delete(dzId, _identityService.ConnectedUser.Id);
|
||||
@@ -92,6 +119,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing drop zone.
|
||||
/// </summary>
|
||||
/// <param name="id">The drop zone ID to update.</param>
|
||||
/// <param name="dropZone">DropZone entity containing the updated drop zone data.</param>
|
||||
/// <param name="resetCache">Whether to reset the cache after update.</param>
|
||||
/// <returns>True if the update was successful, false otherwise.</returns>
|
||||
public bool UpdateDz(int id, DropZone dropZone, bool resetCache = true)
|
||||
{
|
||||
dropZone.Id = id;
|
||||
|
||||
@@ -32,6 +32,10 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
var userId = _identityService.ConnectedUser.Id;
|
||||
_cacheService.Delete(CacheType.Gear, userId: userId);
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds a new gear item to the system.
|
||||
/// </summary>
|
||||
/// <param name="newGear">The Gear entity containing the new gear data.</param>
|
||||
|
||||
public void AddRentalGear(User newUser)
|
||||
{
|
||||
@@ -49,11 +53,19 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
_gearRepository.Add(rentalGear);
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds rental gear to the system for a new user.
|
||||
/// </summary>
|
||||
/// <param name="newUser">The new user for whom rental gear should be added.</param>
|
||||
|
||||
public void DeleteGearById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Deletes a gear item by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The gear ID to delete.</param>
|
||||
|
||||
public IEnumerable<Gear> GetAllGears()
|
||||
{
|
||||
@@ -66,12 +78,21 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
return _cacheService.Get<IEnumerable<Gear>>(CacheType.Gear, userId: userId);
|
||||
}
|
||||
/// <summary>
|
||||
/// Retrieves all gear items.
|
||||
/// </summary>
|
||||
/// <returns>A collection of Gear entities containing all gear data.</returns>
|
||||
|
||||
public Gear GetGearById(int id)
|
||||
{
|
||||
var allGears = GetAllGears();
|
||||
return allGears.Single(g => g.Id == id);
|
||||
}
|
||||
/// <summary>
|
||||
/// Retrieves a gear item by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The gear ID to retrieve.</param>
|
||||
/// <returns>A Gear entity containing the gear details.</returns>
|
||||
|
||||
public bool UpdateGear(int id, Gear gear)
|
||||
{
|
||||
@@ -79,6 +100,12 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
return _gearRepository.Update(gear);
|
||||
}
|
||||
/// <summary>
|
||||
/// Updates an existing gear item.
|
||||
/// </summary>
|
||||
/// <param name="id">The gear ID to update.</param>
|
||||
/// <param name="gear">Gear entity containing the updated gear data.</param>
|
||||
/// <returns>True if the update was successful, false otherwise.</returns>
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Updates the existing data in the database.
|
||||
/// </summary>
|
||||
public void Update()
|
||||
{
|
||||
UpdateAircrafts();
|
||||
@@ -38,6 +41,9 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
_cacheService.Delete(CacheType.JumpType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates the database structure and initial data.
|
||||
/// </summary>
|
||||
public void GenerateDb()
|
||||
{
|
||||
LoadAircrafts();
|
||||
|
||||
@@ -28,6 +28,14 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new jump to the system.
|
||||
/// </summary>
|
||||
/// <param name="aircraftId">The ID of the aircraft to use for this jump.</param>
|
||||
/// <param name="dzId">The ID of the drop zone for this jump.</param>
|
||||
/// <param name="jumpTypeId">The ID of the jump type for this jump.</param>
|
||||
/// <param name="gearId">The ID of the gear for this jump.</param>
|
||||
/// <param name="jump">Jump entity containing the new jump data.</param>
|
||||
public void AddNewJump(int aircraftId,
|
||||
int dzId,
|
||||
int jumpTypeId,
|
||||
@@ -48,31 +56,59 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
_jumpRepository.Add(jump);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a jump by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The jump ID to delete.</param>
|
||||
public void DeleteJumpById(int id)
|
||||
{
|
||||
_jumpRepository.DeleteById(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all jumps for the current user.
|
||||
/// </summary>
|
||||
/// <returns>A collection of Jump entities containing all jumps.</returns>
|
||||
public IEnumerable<Jump> GetAllJumps()
|
||||
{
|
||||
return _jumpRepository.GetAll(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a jump by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The jump ID to retrieve.</param>
|
||||
/// <returns>A Jump entity containing the jump details.</returns>
|
||||
public Jump GetJumpById(int id)
|
||||
{
|
||||
return _jumpRepository.GetById(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the total count of jumps for the current user.
|
||||
/// </summary>
|
||||
/// <returns>The total number of jumps.</returns>
|
||||
public int GetJumpCount()
|
||||
{
|
||||
return _jumpRepository.GetCount(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a range of jumps for the current user with pagination.
|
||||
/// </summary>
|
||||
/// <param name="beginIndex">The starting index for pagination.</param>
|
||||
/// <param name="endIndex">The ending index for pagination.</param>
|
||||
/// <returns>A collection of Jump entities containing the requested range.</returns>
|
||||
public IEnumerable<Jump> GetJumpsByIndexes(int beginIndex, int endIndex)
|
||||
{
|
||||
return _jumpRepository.GetBetweenIndex(_identityService.ConnectedUser, beginIndex, endIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing jump.
|
||||
/// </summary>
|
||||
/// <param name="id">The jump ID to update.</param>
|
||||
/// <param name="updatedJump">Jump entity containing the updated jump data.</param>
|
||||
public void UpdateJump(int id, Jump updatedJump)
|
||||
{
|
||||
var myJump = GetJumpById(id);
|
||||
|
||||
Reference in New Issue
Block a user