Add comments by AI
This commit is contained in:
@@ -1,19 +1,35 @@
|
||||
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 jump data in the database.
|
||||
/// Provides operations to add, delete, retrieve, and update jump records per user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This repository interacts with LiteDB to perform CRUD operations on jump records.
|
||||
/// Each jump record is associated with a user, aircraft, drop zone, gear, and jump type.
|
||||
/// Navigation properties are included for related entities to enable eager loading.
|
||||
/// </remarks>
|
||||
public class JumpRepository : IJumpRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JumpRepository"/> class
|
||||
/// Initializes a new instance of the <see cref="JumpRepository"/> 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 jump data operations.
|
||||
/// The data provider manages the underlying LiteDatabase connection and provides
|
||||
/// typed collection accessors for different entity types.
|
||||
/// </remarks>
|
||||
public JumpRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
@@ -25,10 +41,16 @@ namespace skydiveLogs_api.Infrastructure
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new jump to the database
|
||||
/// Adds a new jump record to the database.
|
||||
/// </summary>
|
||||
/// <param name="newJump">The jump instance to add</param>
|
||||
/// <returns>The number of rows affected (0 if insert failed)</returns>
|
||||
/// <param name="newJump">The jump 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 jump record into the database using LiteDB.
|
||||
/// The jump record should have all required properties set before insertion.
|
||||
/// 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(Jump newJump)
|
||||
{
|
||||
int result;
|
||||
@@ -47,20 +69,30 @@ namespace skydiveLogs_api.Infrastructure
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a jump by its unique identifier
|
||||
/// Deletes a jump record by its unique identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the jump to delete</param>
|
||||
/// <returns>True if the deletion was successful, false otherwise</returns>
|
||||
/// <param name="id">The unique identifier of the jump to delete.</param>
|
||||
/// <returns><see langword="true"/> if the deletion was successful; otherwise, <see langword="false"/>.</returns>
|
||||
/// <remarks>
|
||||
/// Deletes the jump record with the specified ID from the database.
|
||||
/// The method uses the <see cref="ILiteCollection{T}.Delete"/> method to remove the record.
|
||||
/// </remarks>
|
||||
public bool DeleteById(int id)
|
||||
{
|
||||
return _col.Delete(new BsonValue(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all jumps for a specific user
|
||||
/// Retrieves all jump records for a specific user.
|
||||
/// </summary>
|
||||
/// <param name="user">The user whose jumps to retrieve</param>
|
||||
/// <returns>A collection of jump instances belonging to the user</returns>
|
||||
/// <param name="user">The user whose jump records to retrieve.</param>
|
||||
/// <returns>An enumerable collection containing all jump records belonging to the specified user.</returns>
|
||||
/// <remarks>
|
||||
/// Queries the jump collection and retrieves all records where the user ID matches the provided user.
|
||||
/// Each returned jump record includes navigation properties to the associated aircraft, drop zone,
|
||||
/// gear, and jump type entities for eager loading.
|
||||
/// Returns an empty collection if the user has no jump records.
|
||||
/// </remarks>
|
||||
public IEnumerable<Jump> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.Aircraft)
|
||||
@@ -71,21 +103,31 @@ namespace skydiveLogs_api.Infrastructure
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all jumps from the database
|
||||
/// Retrieves all jump records from the database.
|
||||
/// </summary>
|
||||
/// <returns>A collection of all jump instances</returns>
|
||||
/// <returns>An enumerable collection containing all jump records stored 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 jump records from the database without filtering.
|
||||
/// </remarks>
|
||||
/// <exception cref="NotImplementedException">Thrown when the method is called.</exception>
|
||||
public IEnumerable<Jump> GetAll()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a range of jumps for a specific user
|
||||
/// Retrieves a range of jump records for a specific user with pagination.
|
||||
/// </summary>
|
||||
/// <param name="user">The user whose jumps to retrieve</param>
|
||||
/// <param name="beginIndex">The starting index</param>
|
||||
/// <param name="endIndex">The ending index</param>
|
||||
/// <returns>A collection of jump instances</returns>
|
||||
/// <param name="user">The user whose jump records to retrieve.</param>
|
||||
/// <param name="beginIndex">The starting index for pagination (inclusive).</param>
|
||||
/// <param name="endIndex">The ending index for pagination (exclusive).</param>
|
||||
/// <returns>An enumerable collection containing the requested range of jump records.</returns>
|
||||
/// <remarks>
|
||||
/// Retrieves a paginated range of jump records for the specified user, ordered by jump date in descending order.
|
||||
/// Uses LiteDB query operators to limit and offset the results for efficient pagination.
|
||||
/// Each jump record includes navigation properties to related entities.
|
||||
/// </remarks>
|
||||
public IEnumerable<Jump> GetBetweenIndex(User user, int beginIndex, int endIndex)
|
||||
{
|
||||
return _col.Include(x => x.Aircraft)
|
||||
@@ -101,39 +143,59 @@ namespace skydiveLogs_api.Infrastructure
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a jump by its unique identifier
|
||||
/// Retrieves a jump record by its unique identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the jump</param>
|
||||
/// <returns>The jump instance or null if not found</returns>
|
||||
/// <param name="id">The unique identifier of the jump to retrieve.</param>
|
||||
/// <returns>The jump record instance if found, otherwise null.</returns>
|
||||
/// <remarks>
|
||||
/// Searches the jump collection for a record with the specified ID.
|
||||
/// Returns null if no jump record with the matching ID is found in the database.
|
||||
/// </remarks>
|
||||
public Jump GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total count of jumps for a specific user
|
||||
/// Gets the total count of jump records for a specific user.
|
||||
/// </summary>
|
||||
/// <param name="user">The user whose jumps to count</param>
|
||||
/// <returns>The total number of jumps</returns>
|
||||
/// <param name="user">The user whose jump records to count.</param>
|
||||
/// <returns>The total number of jump records 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 jump records per user.
|
||||
/// </remarks>
|
||||
/// <exception cref="NotImplementedException">Thrown when the method is called.</exception>
|
||||
public int GetCount(User user)
|
||||
{
|
||||
return _col.Count(j => j.User.Id == user.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total count of jumps in the database
|
||||
/// Gets the total count of jump records in the database.
|
||||
/// </summary>
|
||||
/// <returns>The total number of jumps</returns>
|
||||
/// <returns>The total number of jump records stored in the database.</returns>
|
||||
/// <remarks>
|
||||
/// This method is not currently implemented and throws a <see cref="NotImplementedException"/> when called.
|
||||
/// Implement this method to retrieve the count of all jump records.
|
||||
/// </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 jump in the database
|
||||
/// Updates an existing jump record in the database.
|
||||
/// </summary>
|
||||
/// <param name="updatedJump">The jump instance to update</param>
|
||||
/// <returns>True if the update was successful, false otherwise</returns>
|
||||
/// <param name="updatedJump">The jump record instance containing the updated data.</param>
|
||||
/// <returns><see langword="true"/> if the update was successful; otherwise, <see langword="false"/>.</returns>
|
||||
/// <remarks>
|
||||
/// Updates the jump record in the database with the provided jump record instance.
|
||||
/// The jump record must have a valid ID to be updated.
|
||||
/// The method returns the result of the underlying LiteDB update operation.
|
||||
/// If the jump record does not exist, the update operation will return 0.
|
||||
/// </remarks>
|
||||
public bool Update(Jump updatedJump)
|
||||
{
|
||||
return _col.Update(updatedJump);
|
||||
@@ -143,7 +205,14 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// The LiteDB collection for jump records.
|
||||
/// </summary>
|
||||
private readonly ILiteCollection<Jump> _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