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,29 @@
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 aircraft data in the database.
/// Provides operations to add, retrieve, count, and update aircraft records.
/// </summary>
public class AircraftRepository : IAircraftRepository
{
#region Public Constructors
/// <summary>
/// Initializes a new instance of the <see cref="AircraftRepository"/> class
/// Initializes a new instance of the <see cref="AircraftRepository"/> 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 aircraft data operations.
/// </remarks>
public AircraftRepository(IDataProvider dataProvider)
{
_dataProvider = dataProvider;
@@ -26,10 +35,14 @@ namespace skydiveLogs_api.Infrastructure
#region Public Methods
/// <summary>
/// Adds a new aircraft to the database
/// Adds a new aircraft to the database.
/// </summary>
/// <param name="newAircraft">The aircraft instance to add</param>
/// <returns>The number of rows affected (0 if insert failed)</returns>
/// <param name="newAircraft">The aircraft 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 aircraft into the database using LiteDB.
/// If an exception occurs during insertion, the method returns 0.
/// </remarks>
public int Add(Aircraft newAircraft)
{
int result;
@@ -48,38 +61,54 @@ namespace skydiveLogs_api.Infrastructure
}
/// <summary>
/// Retrieves all aircraft from the database
/// Retrieves all aircraft from the database.
/// </summary>
/// <returns>A collection of all aircraft instances</returns>
/// <returns>An enumerable collection containing all aircraft instances stored in the database</returns>
/// <remarks>
/// Queries the aircraft collection and retrieves all records,
/// then converts the result to a List for enumeration.
/// </remarks>
public IEnumerable<Aircraft> GetAll()
{
return _col.FindAll().ToList();
}
/// <summary>
/// Retrieves an aircraft by its unique identifier
/// Retrieves an aircraft by its unique identifier.
/// </summary>
/// <param name="id">The unique identifier of the aircraft</param>
/// <returns>The aircraft instance or null if not found</returns>
/// <param name="id">The unique identifier of the aircraft to retrieve</param>
/// <returns>The aircraft instance if found, otherwise null</returns>
/// <remarks>
/// Searches the aircraft collection for a record with the specified ID
/// and returns the found aircraft or null if no match exists.
/// </remarks>
public Aircraft GetById(int id)
{
return _col.FindById(new BsonValue(id));
}
/// <summary>
/// Gets the total count of aircraft in the database
/// Gets the total count of aircraft in the database.
/// </summary>
/// <returns>The total number of aircraft</returns>
/// <returns>The total number of aircraft stored in the database</returns>
/// <remarks>
/// This method is not currently implemented and throws
/// a <see cref="NotImplementedException"/> when called.
/// </remarks>
public int GetCount()
{
throw new System.NotImplementedException();
throw new NotImplementedException();
}
/// <summary>
/// Updates an existing aircraft in the database
/// Updates an existing aircraft in the database.
/// </summary>
/// <param name="aircraft">The aircraft instance to update</param>
/// <returns>True if the update was successful, false otherwise</returns>
/// <param name="aircraft">The aircraft instance containing the updated data</param>
/// <returns><see langword="true"/> if the update was successful; otherwise, <see langword="false"/></returns>
/// <remarks>
/// Updates the aircraft record in the database with the provided aircraft instance.
/// The method returns the result of the underlying LiteDB update operation.
/// </remarks>
public bool Update(Aircraft aircraft)
{
return _col.Update(aircraft);
@@ -89,7 +118,14 @@ namespace skydiveLogs_api.Infrastructure
#region Private Fields
/// <summary>
/// The LiteDB collection for aircraft records.
/// </summary>
private readonly ILiteCollection<Aircraft> _col;
/// <summary>
/// The data provider used for database access operations.
/// </summary>
private readonly IDataProvider _dataProvider;
#endregion Private Fields