Add comments by AI
This commit is contained in:
@@ -1,19 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LiteDB;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// Repository class for managing favorite drop zone data in the database.
|
||||
/// Provides operations to add, delete, retrieve, and manage favorite drop zones per user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This repository interacts with LiteDB to perform operations on favorite drop zones,
|
||||
/// where each favorite drop zone is associated with both a user and a drop zone.
|
||||
/// </remarks>
|
||||
public class FavoriteDropZoneRepository : IFavoriteDropZoneRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FavoriteDropZoneRepository"/> class
|
||||
/// Initializes a new instance of the <see cref="FavoriteDropZoneRepository"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dataProvider">The data provider to use for data access</param>
|
||||
/// <param name="dataProvider">The data provider used for database access operations.</param>
|
||||
/// <remarks>
|
||||
/// This constructor initializes the repository with a reference to the data provider
|
||||
/// and sets up the collection for favorite drop zone data operations.
|
||||
/// The data provider manages the underlying LiteDatabase connection and provides
|
||||
/// typed collection accessors for different entity types.
|
||||
/// </remarks>
|
||||
public FavoriteDropZoneRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
@@ -25,10 +40,15 @@ namespace skydiveLogs_api.Infrastructure
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new favorite drop zone to the database
|
||||
/// Adds a new favorite drop zone to the database.
|
||||
/// </summary>
|
||||
/// <param name="favoriteToAdd">The favorite drop zone instance to add</param>
|
||||
/// <returns>The number of rows affected (0 if insert failed)</returns>
|
||||
/// <param name="favoriteToAdd">The favorite drop zone instance to insert into the database.</param>
|
||||
/// <returns>The number of rows affected. Returns 0 if the insert operation failed.</returns>
|
||||
/// <remarks>
|
||||
/// Attempts to insert the new favorite drop zone into the database using LiteDB.
|
||||
/// If an exception occurs during insertion, the method returns 0.
|
||||
/// The returned value indicates the number of records affected by the insert operation.
|
||||
/// </remarks>
|
||||
public int Add(FavoriteDropZone favoriteToAdd)
|
||||
{
|
||||
int result;
|
||||
@@ -47,21 +67,30 @@ namespace skydiveLogs_api.Infrastructure
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a favorite drop zone by drop zone ID and user ID
|
||||
/// Deletes favorite drop zone entries by drop zone ID and user ID.
|
||||
/// </summary>
|
||||
/// <param name="dropZoneId">The unique identifier of the drop zone</param>
|
||||
/// <param name="userId">The unique identifier of the user</param>
|
||||
/// <returns>The number of rows affected (0 if delete failed)</returns>
|
||||
/// <param name="dropZoneId">The unique identifier of the drop zone to delete favorites for.</param>
|
||||
/// <param name="userId">The unique identifier of the user whose favorites to delete.</param>
|
||||
/// <returns>The number of rows affected. Returns 0 if the delete operation failed or no records matched.</returns>
|
||||
/// <remarks>
|
||||
/// Deletes all favorite drop zone records where both the drop zone ID and user ID match the provided values.
|
||||
/// This operation is commonly used to remove a specific user's favorites for a particular drop zone.
|
||||
/// </remarks>
|
||||
public int Delete(int dropZoneId, int userId)
|
||||
{
|
||||
return _col.DeleteMany(d => d.DropZone.Id == dropZoneId && d.User.Id == userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all favorite drop zones for a specific user
|
||||
/// Retrieves all favorite drop zones for a specific user.
|
||||
/// </summary>
|
||||
/// <param name="user">The user whose favorite drop zones to retrieve</param>
|
||||
/// <returns>A collection of favorite drop zone instances belonging to the user</returns>
|
||||
/// <param name="user">The user whose favorite drop zones to retrieve.</param>
|
||||
/// <returns>An enumerable collection containing all favorite drop zone instances belonging to the specified user.</returns>
|
||||
/// <remarks>
|
||||
/// Queries the favorite drop zone collection and retrieves all records where the user ID matches the provided user.
|
||||
/// Each returned record includes navigation properties to the associated user and drop zone entities.
|
||||
/// Returns an empty collection if the user has no favorite drop zones.
|
||||
/// </remarks>
|
||||
public IEnumerable<FavoriteDropZone> GetAll(User user)
|
||||
{
|
||||
return _col.Query()
|
||||
@@ -70,48 +99,78 @@ namespace skydiveLogs_api.Infrastructure
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all favorite drop zones from the database
|
||||
/// Retrieves all favorite drop zones from the database.
|
||||
/// </summary>
|
||||
/// <returns>A collection of all favorite drop zone instances</returns>
|
||||
/// <returns>An enumerable collection containing all favorite drop zone instances in the database.</returns>
|
||||
/// <remarks>
|
||||
/// This method is not currently implemented and throws a <see cref="NotImplementedException"/> when called.
|
||||
/// Implement this method to retrieve all favorite drop zones across all users in the system.
|
||||
/// </remarks>
|
||||
/// <exception cref="NotImplementedException">Thrown when the method is called.</exception>
|
||||
public IEnumerable<FavoriteDropZone> GetAll()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a favorite drop zone by its unique identifier
|
||||
/// Retrieves a favorite drop zone by its unique identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the favorite drop zone</param>
|
||||
/// <returns>The favorite drop zone instance or null if not found</returns>
|
||||
/// <param name="id">The unique identifier of the favorite drop zone to retrieve.</param>
|
||||
/// <returns>The favorite drop zone instance if found, otherwise null.</returns>
|
||||
/// <remarks>
|
||||
/// Searches the favorite drop zone collection for a record with the specified ID.
|
||||
/// This method currently returns null as it's not implemented with proper filtering by ID.
|
||||
/// Implement this method to retrieve a specific favorite drop zone by its database ID.
|
||||
/// </remarks>
|
||||
/// <exception cref="NotImplementedException">Thrown when attempting to retrieve by ID.</exception>
|
||||
public FavoriteDropZone GetById(int id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total count of favorite drop zones in the database
|
||||
/// Gets the total count of favorite drop zones for a specific user.
|
||||
/// </summary>
|
||||
/// <returns>The total number of favorite drop zones</returns>
|
||||
/// <param name="user">The user whose favorite drop zones to count.</param>
|
||||
/// <returns>The total number of favorite drop zones for the specified user.</returns>
|
||||
/// <remarks>
|
||||
/// This method is not currently implemented and throws a <see cref="NotImplementedException"/> when called.
|
||||
/// Implement this method to retrieve the count of favorite drop zones per user.
|
||||
/// </remarks>
|
||||
/// <exception cref="NotImplementedException">Thrown when the method is called.</exception>
|
||||
public int GetCount()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing favorite drop zone in the database
|
||||
/// Updates an existing favorite drop zone in the database.
|
||||
/// </summary>
|
||||
/// <param name="updated">The favorite drop zone instance to update</param>
|
||||
/// <returns>True if the update was successful, false otherwise</returns>
|
||||
/// <param name="updated">The favorite drop zone instance containing the updated data.</param>
|
||||
/// <returns><see langword="true"/> if the update was successful; otherwise, <see langword="false"/>.</returns>
|
||||
/// <remarks>
|
||||
/// This method is not currently implemented and throws a <see cref="NotImplementedException"/> when called.
|
||||
/// Implement this method to update existing favorite drop zone records in the database.
|
||||
/// Note: Favorite drop zones may not typically be updated; consider using Add for new favorites.
|
||||
/// </remarks>
|
||||
/// <exception cref="NotImplementedException">Thrown when attempting to update.</exception>
|
||||
public bool Update(FavoriteDropZone updated)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// The LiteDB collection for favorite drop zone records.
|
||||
/// </summary>
|
||||
private readonly ILiteCollection<FavoriteDropZone> _col;
|
||||
|
||||
/// <summary>
|
||||
/// The data provider used for database access operations.
|
||||
/// </summary>
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
Reference in New Issue
Block a user