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 gear data in the database.
|
||||
/// Provides operations to add, retrieve, count, and update gear records per user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This repository interacts with LiteDB to perform CRUD operations on gear items.
|
||||
/// Each gear item is associated with a user, allowing for user-specific gear management.
|
||||
/// </remarks>
|
||||
public class GearRepository : IGearRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GearRepository"/> class
|
||||
/// Initializes a new instance of the <see cref="GearRepository"/> 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 gear data operations.
|
||||
/// The data provider manages the underlying LiteDatabase connection and provides
|
||||
/// typed collection accessors for different entity types.
|
||||
/// </remarks>
|
||||
public GearRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
@@ -25,10 +40,16 @@ namespace skydiveLogs_api.Infrastructure
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new gear item to the database
|
||||
/// Adds a new gear item to the database.
|
||||
/// </summary>
|
||||
/// <param name="newGear">The gear instance to add</param>
|
||||
/// <returns>The number of rows affected (0 if insert failed)</returns>
|
||||
/// <param name="newGear">The gear 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 gear item into the database using LiteDB.
|
||||
/// The gear item 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(Gear newGear)
|
||||
{
|
||||
int result;
|
||||
@@ -47,19 +68,29 @@ namespace skydiveLogs_api.Infrastructure
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all gear items from the database
|
||||
/// Retrieves all gear items from the database.
|
||||
/// </summary>
|
||||
/// <returns>A collection of all gear instances</returns>
|
||||
/// <returns>An enumerable collection containing all gear instances 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 gear records from the database, potentially filtered by user.
|
||||
/// </remarks>
|
||||
/// <exception cref="NotImplementedException">Thrown when the method is called.</exception>
|
||||
public IEnumerable<Gear> GetAll()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all gear items for a specific user
|
||||
/// Retrieves all gear items for a specific user.
|
||||
/// </summary>
|
||||
/// <param name="user">The user whose gear items to retrieve</param>
|
||||
/// <returns>A collection of gear instances belonging to the user</returns>
|
||||
/// <param name="user">The user whose gear items to retrieve.</param>
|
||||
/// <returns>An enumerable collection containing all gear instances belonging to the specified user.</returns>
|
||||
/// <remarks>
|
||||
/// Queries the gear collection and retrieves all records where the user ID matches the provided user.
|
||||
/// Each returned gear record includes navigation properties to the associated user entity.
|
||||
/// Returns an empty collection if the user has no gear items.
|
||||
/// </remarks>
|
||||
public IEnumerable<Gear> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
@@ -69,29 +100,45 @@ namespace skydiveLogs_api.Infrastructure
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a gear item by its unique identifier
|
||||
/// Retrieves a gear item by its unique identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the gear</param>
|
||||
/// <returns>The gear instance or null if not found</returns>
|
||||
/// <param name="id">The unique identifier of the gear item to retrieve.</param>
|
||||
/// <returns>The gear item instance if found, otherwise null.</returns>
|
||||
/// <remarks>
|
||||
/// Searches the gear collection for a record with the specified ID.
|
||||
/// Returns null if no gear item with the matching ID is found in the database.
|
||||
/// </remarks>
|
||||
public Gear GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total count of gear items in the database
|
||||
/// Gets the total count of gear items for a specific user.
|
||||
/// </summary>
|
||||
/// <returns>The total number of gear items</returns>
|
||||
/// <param name="user">The user whose gear items to count.</param>
|
||||
/// <returns>The total number of gear items 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 gear items 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 gear item in the database
|
||||
/// Updates an existing gear item in the database.
|
||||
/// </summary>
|
||||
/// <param name="updatedGear">The gear instance to update</param>
|
||||
/// <returns>True if the update was successful, false otherwise</returns>
|
||||
/// <param name="updatedGear">The gear item instance containing the updated data.</param>
|
||||
/// <returns><see langword="true"/> if the update was successful; otherwise, <see langword="false"/>.</returns>
|
||||
/// <remarks>
|
||||
/// Updates the gear record in the database with the provided gear item instance.
|
||||
/// The gear item must have a valid ID to be updated.
|
||||
/// The method returns the result of the underlying LiteDB update operation.
|
||||
/// If the gear item does not exist, the update operation will return 0.
|
||||
/// </remarks>
|
||||
public bool Update(Gear updatedGear)
|
||||
{
|
||||
return _col.Update(updatedGear);
|
||||
@@ -101,7 +148,14 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Private Fields
|
||||
|
||||
/// <summary>
|
||||
/// The LiteDB collection for gear records.
|
||||
/// </summary>
|
||||
private readonly ILiteCollection<Gear> _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