Add comments by AI

This commit is contained in:
2026-04-22 22:54:13 +02:00
parent 41669e670a
commit 8e61574242
6 changed files with 446 additions and 134 deletions
@@ -1,20 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using LiteDB;
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainService.Repositories;
using skydiveLogs_api.Infrastructure.Interfaces;
using System.Collections.Generic;
using System.Linq;
namespace skydiveLogs_api.Infrastructure
{
/// <summary>
/// Repository class for managing drop zone data in the database.
/// Provides operations to add, retrieve, count, and update drop zone records.
/// </summary>
/// <remarks>
/// This repository interacts with LiteDB to perform CRUD operations on drop zones.
/// </remarks>
public class DropZoneRepository : IDropZoneRepository
{
#region Public Constructors
/// <summary>
/// Initializes a new instance of the <see cref="DropZoneRepository"/> class
/// Initializes a new instance of the <see cref="DropZoneRepository"/> 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 drop zone data operations.
/// The data provider manages the underlying LiteDatabase connection.
/// </remarks>
public DropZoneRepository(IDataProvider dataProvider)
{
_dataProvider = dataProvider;
@@ -26,10 +39,15 @@ namespace skydiveLogs_api.Infrastructure
#region Public Methods
/// <summary>
/// Adds a new drop zone to the database
/// Adds a new drop zone to the database.
/// </summary>
/// <param name="newDropZone">The drop zone instance to add</param>
/// <returns>The number of rows affected (0 if insert failed)</returns>
/// <param name="newDropZone">The 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 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(DropZone newDropZone)
{
int result;
@@ -48,38 +66,60 @@ namespace skydiveLogs_api.Infrastructure
}
/// <summary>
/// Retrieves all drop zones from the database
/// Retrieves all drop zones from the database.
/// </summary>
/// <returns>A collection of all drop zone instances</returns>
/// <returns>An enumerable collection containing all drop zone instances stored in the database.</returns>
/// <remarks>
/// Queries the drop zone collection and retrieves all records,
/// then converts the result to a List for enumeration.
/// Returns an empty list if no drop zones exist in the database.
/// </remarks>
public IEnumerable<DropZone> GetAll()
{
return _col.FindAll().ToList();
}
/// <summary>
/// Retrieves a drop zone by its unique identifier
/// Retrieves a drop zone by its unique identifier.
/// </summary>
/// <param name="id">The unique identifier of the drop zone</param>
/// <returns>The drop zone instance or null if not found</returns>
/// <param name="id">The unique identifier of the drop zone to retrieve.</param>
/// <returns>The drop zone instance if found, otherwise null.</returns>
/// <remarks>
/// Searches the drop zone collection for a record with the specified ID
/// and returns the found drop zone or null if no match exists.
/// Use <see cref="GetAll"/> to retrieve all drop zones or filter by criteria.
/// </remarks>
public DropZone GetById(int id)
{
return _col.FindById(new BsonValue(id));
}
/// <summary>
/// Gets the total count of drop zones in the database
/// Gets the total count of drop zones in the database.
/// </summary>
/// <returns>The total number of drop zones</returns>
/// <returns>The total number of drop zones 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 drop zones.
/// </remarks>
/// <exception cref="NotImplementedException">Thrown when the count is requested.</exception>
public int GetCount()
{
throw new System.NotImplementedException();
throw new NotImplementedException();
}
/// <summary>
/// Updates an existing drop zone in the database
/// Updates an existing drop zone in the database.
/// </summary>
/// <param name="dropZone">The drop zone instance to update</param>
/// <returns>True if the update was successful, false otherwise</returns>
/// <param name="dropZone">The drop zone instance containing the updated data.</param>
/// <returns><see langword="true"/> if the update was successful; otherwise, <see langword="false"/>.</returns>
/// <remarks>
/// Updates the drop zone record in the database with the provided drop zone instance.
/// The drop zone must have a valid ID to be updated.
/// The method returns the result of the underlying LiteDB update operation.
/// If the drop zone does not exist, the update operation will return 0.
/// </remarks>
public bool Update(DropZone dropZone)
{
return _col.Update(dropZone);
@@ -89,7 +129,14 @@ namespace skydiveLogs_api.Infrastructure
#region Private Fields
/// <summary>
/// The LiteDB collection for drop zone records.
/// </summary>
private readonly ILiteCollection<DropZone> _col;
/// <summary>
/// The data provider used for database access operations.
/// </summary>
private readonly IDataProvider _dataProvider;
#endregion Private Fields