diff --git a/Back/skydiveLogs-api.DomainBusiness/AircraftService.cs b/Back/skydiveLogs-api.DomainBusiness/AircraftService.cs index c26b042..db6e921 100644 --- a/Back/skydiveLogs-api.DomainBusiness/AircraftService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/AircraftService.cs @@ -11,6 +11,11 @@ namespace skydiveLogs_api.DomainBusiness { #region Public Constructors + /// + /// Initializes a new instance of the class. + /// + /// The aircraft repository for data access. + /// The cache service for caching operations. public AircraftService(IAircraftRepository aircraftRepository, ICacheService cacheService) { @@ -22,23 +27,40 @@ namespace skydiveLogs_api.DomainBusiness #region Public Methods + /// + /// Adds a new aircraft to the system. + /// + /// The Aircraft entity containing the data for the new aircraft. public void AddNewAircraft(Aircraft newAircraft) { _aircraftRepository.Add(newAircraft); _cacheService.Delete(CacheType.Aircraft); } + /// + /// Deletes an aircraft by its ID. + /// + /// The aircraft ID to delete. public void DeleteAircraftById(int id) { throw new NotImplementedException(); } + /// + /// Retrieves an aircraft by its ID. + /// + /// The aircraft ID to retrieve. + /// An Aircraft entity containing the aircraft details. public Aircraft GetAircraftById(int id) { var allAircrafts = GetAllAircrafts(); return allAircrafts.Single(g => g.Id == id); } + /// + /// Retrieves all aircrafts. + /// + /// A collection of Aircraft entities containing all aircraft data. public IEnumerable GetAllAircrafts() { if (!_cacheService.Contains(CacheType.Aircraft)) @@ -49,6 +71,13 @@ namespace skydiveLogs_api.DomainBusiness return _cacheService.Get>(CacheType.Aircraft); } + /// + /// Updates an existing aircraft. + /// + /// The aircraft ID to update. + /// Aircraft entity containing the updated aircraft data. + /// Whether to reset the cache after update. + /// True if the update was successful, false otherwise. public bool UpdateAircraft(int id, Aircraft aircraft, bool resetCache = true) { aircraft.Id = id; @@ -69,4 +98,4 @@ namespace skydiveLogs_api.DomainBusiness #endregion Private Fields } -} \ No newline at end of file +} diff --git a/Back/skydiveLogs-api.DomainBusiness/CacheService.cs b/Back/skydiveLogs-api.DomainBusiness/CacheService.cs index 01edbfa..f958047 100644 --- a/Back/skydiveLogs-api.DomainBusiness/CacheService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/CacheService.cs @@ -24,24 +24,50 @@ namespace skydiveLogs_api.DomainBusiness #region Public Methods + /// + /// Checks if a specific cache entry exists for a given type and user ID. + /// + /// The type of data to check for in the cache. + /// Optional user ID to distinguish cache entries. Default is 0. + /// True if the cache entry exists and is valid, otherwise false. public bool Contains(CacheType type, int userId = 0) { var key = GetKey(userId, type); return _memoryCache.Contains(key.ToString()); } + /// + /// Removes a cache entry from the store. + /// + /// The type of data to remove from the cache. + /// Optional user ID to identify the cache entry. Default is 0. public void Delete(CacheType type, int userId = 0) { var key = GetKey(userId, type); _memoryCache.Remove(key.ToString()); } + /// + /// Retrieves data from the cache for a specified type and user ID. + /// + /// The expected type of the cached data. + /// The type of data to retrieve from the cache. + /// Optional user ID to identify the cache entry. Default is 0. + /// The cached data cast to type T, or default(T) if not found or expired. public T Get(CacheType type, int userId = 0) { var key = GetKey(userId, type); return (T)_memoryCache.Get(key.ToString()); } + /// + /// Stores data in the cache with a specified expiry time. + /// + /// The unique identifier for the cache key. + /// The object data to be cached. + /// The duration in milliseconds before the cache entry expires. + /// Optional user ID to distinguish cache entries. Default is 0. + /// Thrown when duration is less than or equal to zero. 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); } + /// + /// Generates a cache key by combining the user ID and cache type. + /// + /// The user ID to include in the key. + /// The cache type to include in the key. + /// A concatenated string key combining userId and type. private string GetKey(int userId, CacheType type) { return $"{userId}-{type}"; @@ -63,4 +95,4 @@ namespace skydiveLogs_api.DomainBusiness #endregion Public Methods } -} \ No newline at end of file +} diff --git a/Back/skydiveLogs-api.DomainBusiness/DropZoneService.cs b/Back/skydiveLogs-api.DomainBusiness/DropZoneService.cs index c598ca3..2a63c48 100644 --- a/Back/skydiveLogs-api.DomainBusiness/DropZoneService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/DropZoneService.cs @@ -26,12 +26,21 @@ namespace skydiveLogs_api.DomainBusiness #region Public Methods + /// + /// Adds a new drop zone to the system. + /// + /// The DropZone entity containing the new drop zone data. public void AddNewDz(DropZone newdropZone) { _dropZoneRepository.Add(newdropZone); _cacheService.Delete(CacheType.DropZone); } + /// + /// Adds a drop zone to the user's favorites. + /// + /// The drop zone ID to add to favorites. + /// True if the drop zone was added to favorites, false otherwise. public bool AddToFavorite(int dzId) { var dzToAddToFavorite = GetDzById(dzId); @@ -47,11 +56,19 @@ namespace skydiveLogs_api.DomainBusiness return result > 0; } + /// + /// Deletes a drop zone by its ID. + /// + /// The drop zone ID to delete. public void DeleteDzById(int id) { throw new NotImplementedException(); } + /// + /// Retrieves a list of all drop zones with favorites status. + /// + /// A collection of DropZone entities containing all drop zones with their favorite status. public IEnumerable GetAllDzs() { var results = Enumerable.Empty(); @@ -78,12 +95,22 @@ namespace skydiveLogs_api.DomainBusiness return results.ToList(); } + /// + /// Retrieves a drop zone by its ID. + /// + /// The drop zone ID to retrieve. + /// A DropZone entity containing the drop zone details. public DropZone GetDzById(int id) { var allDzs = GetAllRefDzs(); return allDzs.Single(g => g.Id == id); } + /// + /// Removes a drop zone from the user's favorites. + /// + /// The drop zone ID to remove from favorites. + /// True if the drop zone was removed from favorites, false otherwise. public bool RemoveToFavorite(int dzId) { var result = _favoriteDropZoneRepository.Delete(dzId, _identityService.ConnectedUser.Id); @@ -92,6 +119,13 @@ namespace skydiveLogs_api.DomainBusiness return result > 0; } + /// + /// Updates an existing drop zone. + /// + /// The drop zone ID to update. + /// DropZone entity containing the updated drop zone data. + /// Whether to reset the cache after update. + /// True if the update was successful, false otherwise. public bool UpdateDz(int id, DropZone dropZone, bool resetCache = true) { dropZone.Id = id; @@ -124,4 +158,4 @@ namespace skydiveLogs_api.DomainBusiness #endregion Private Fields } -} \ No newline at end of file +} diff --git a/Back/skydiveLogs-api.DomainBusiness/GearService.cs b/Back/skydiveLogs-api.DomainBusiness/GearService.cs index 1e51c64..2af5772 100644 --- a/Back/skydiveLogs-api.DomainBusiness/GearService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/GearService.cs @@ -32,6 +32,10 @@ namespace skydiveLogs_api.DomainBusiness var userId = _identityService.ConnectedUser.Id; _cacheService.Delete(CacheType.Gear, userId: userId); } + /// + /// Adds a new gear item to the system. + /// + /// The Gear entity containing the new gear data. public void AddRentalGear(User newUser) { @@ -49,11 +53,19 @@ namespace skydiveLogs_api.DomainBusiness _gearRepository.Add(rentalGear); } + /// + /// Adds rental gear to the system for a new user. + /// + /// The new user for whom rental gear should be added. public void DeleteGearById(int id) { throw new NotImplementedException(); } + /// + /// Deletes a gear item by its ID. + /// + /// The gear ID to delete. public IEnumerable GetAllGears() { @@ -66,12 +78,21 @@ namespace skydiveLogs_api.DomainBusiness return _cacheService.Get>(CacheType.Gear, userId: userId); } + /// + /// Retrieves all gear items. + /// + /// A collection of Gear entities containing all gear data. public Gear GetGearById(int id) { var allGears = GetAllGears(); return allGears.Single(g => g.Id == id); } + /// + /// Retrieves a gear item by its ID. + /// + /// The gear ID to retrieve. + /// A Gear entity containing the gear details. public bool UpdateGear(int id, Gear gear) { @@ -79,6 +100,12 @@ namespace skydiveLogs_api.DomainBusiness return _gearRepository.Update(gear); } + /// + /// Updates an existing gear item. + /// + /// The gear ID to update. + /// Gear entity containing the updated gear data. + /// True if the update was successful, false otherwise. #endregion Public Methods @@ -90,4 +117,4 @@ namespace skydiveLogs_api.DomainBusiness #endregion Private Fields } -} \ No newline at end of file +} diff --git a/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs b/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs index 541d8bc..ceca1ea 100644 --- a/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs @@ -27,6 +27,9 @@ namespace skydiveLogs_api.DomainBusiness #region Public Methods + /// + /// Updates the existing data in the database. + /// public void Update() { UpdateAircrafts(); @@ -38,6 +41,9 @@ namespace skydiveLogs_api.DomainBusiness _cacheService.Delete(CacheType.JumpType); } + /// + /// Generates the database structure and initial data. + /// public void GenerateDb() { LoadAircrafts(); @@ -193,4 +199,4 @@ namespace skydiveLogs_api.DomainBusiness #endregion Private Fields } -} \ No newline at end of file +} diff --git a/Back/skydiveLogs-api.DomainBusiness/JumpService.cs b/Back/skydiveLogs-api.DomainBusiness/JumpService.cs index c96e120..b445fa1 100644 --- a/Back/skydiveLogs-api.DomainBusiness/JumpService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/JumpService.cs @@ -28,6 +28,14 @@ namespace skydiveLogs_api.DomainBusiness #region Public Methods + /// + /// Adds a new jump to the system. + /// + /// The ID of the aircraft to use for this jump. + /// The ID of the drop zone for this jump. + /// The ID of the jump type for this jump. + /// The ID of the gear for this jump. + /// Jump entity containing the new jump data. public void AddNewJump(int aircraftId, int dzId, int jumpTypeId, @@ -48,31 +56,59 @@ namespace skydiveLogs_api.DomainBusiness _jumpRepository.Add(jump); } + /// + /// Deletes a jump by its ID. + /// + /// The jump ID to delete. public void DeleteJumpById(int id) { _jumpRepository.DeleteById(id); } + /// + /// Retrieves all jumps for the current user. + /// + /// A collection of Jump entities containing all jumps. public IEnumerable GetAllJumps() { return _jumpRepository.GetAll(_identityService.ConnectedUser); } + /// + /// Retrieves a jump by its ID. + /// + /// The jump ID to retrieve. + /// A Jump entity containing the jump details. public Jump GetJumpById(int id) { return _jumpRepository.GetById(id); } + /// + /// Retrieves the total count of jumps for the current user. + /// + /// The total number of jumps. public int GetJumpCount() { return _jumpRepository.GetCount(_identityService.ConnectedUser); } + /// + /// Retrieves a range of jumps for the current user with pagination. + /// + /// The starting index for pagination. + /// The ending index for pagination. + /// A collection of Jump entities containing the requested range. public IEnumerable GetJumpsByIndexes(int beginIndex, int endIndex) { return _jumpRepository.GetBetweenIndex(_identityService.ConnectedUser, beginIndex, endIndex); } + /// + /// Updates an existing jump. + /// + /// The jump ID to update. + /// Jump entity containing the updated jump data. public void UpdateJump(int id, Jump updatedJump) { var myJump = GetJumpById(id); @@ -96,4 +132,4 @@ namespace skydiveLogs_api.DomainBusiness #endregion Private Fields } -} \ No newline at end of file +}