Files
SkydiveLogs/Back/skydiveLogs-api.Infrastructure/StatsByGearRepository.cs
sandre ceed44f997 Little test with AI + Add the equipment (#8)
Tests using local LLM AI to add comments in the C# files
For the flights tunnel, show the total to day/hours
For the jump, add the equipment (now just with the wingsuit)

Reviewed-on: #8
Co-authored-by: sandre <perso@sebastienandre.com>
Co-committed-by: sandre <perso@sebastienandre.com>
2026-05-16 09:24:13 +00:00

100 lines
3.1 KiB
C#

using LiteDB;
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainService.Repositories;
using skydiveLogs_api.Infrastructure.Interfaces;
using System.Collections.Generic;
namespace skydiveLogs_api.Infrastructure
{
public class StatsByGearRepository : IStatsByGearRepository
{
#region Public Constructors
/// <summary>
/// Initializes a new instance of the <see cref="StatsByGearRepository"/> class
/// </summary>
/// <param name="dataProvider">The data provider to use for data access</param>
public StatsByGearRepository(IDataProvider dataProvider)
{
_dataProvider = dataProvider;
_col = _dataProvider.CollOfStatsByGear;
}
#endregion Public Constructors
#region Public Methods
/// <summary>
/// Adds a new collection of stats by gear to the database
/// </summary>
/// <param name="newStats">The collection of stats by gear instances to add</param>
/// <returns>The number of rows affected</returns>
public int Add(IEnumerable<StatsByGear> newStats)
{
int result = 0;
try
{
foreach (var newStat in newStats)
{
var tmp = _col.Insert(newStats);
result = tmp;
}
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// Retrieves all stats by gear for a specific user
/// </summary>
/// <param name="user">The user whose stats by gear to retrieve</param>
/// <returns>A collection of stats by gear instances belonging to the user</returns>
public IEnumerable<StatsByGear> GetAll(User user)
{
return _col.Include(x => x.User)
.Query()
.Where(j => j.User.Id == user.Id)
.ToList();
}
/// <summary>
/// Updates existing stats by gear in the database
/// </summary>
/// <param name="updatedStats">The stats by gear instances to update</param>
/// <param name="user">The user whose stats to update</param>
/// <returns>True if the update was successful, false otherwise</returns>
public bool Update(IEnumerable<StatsByGear> updatedStats, User user)
{
Delete(user);
var tmp = Add(updatedStats);
return tmp != 0;
}
/// <summary>
/// Deletes all stats by gear for a specific user
/// </summary>
/// <param name="user">The user whose stats by gear to delete</param>
/// <returns>True if the delete was successful, false otherwise</returns>
public bool Delete(User user)
{
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
return tmp != 0;
}
#endregion Public Methods
#region Private Fields
private readonly ILiteCollection<StatsByGear> _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}