Files
SkydiveLogs/Back/skydiveLogs-api.Infrastructure/FavoriteDropZoneRepository.cs
T
2026-04-17 17:26:20 +02:00

120 lines
4.0 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 FavoriteDropZoneRepository : IFavoriteDropZoneRepository
{
#region Public Constructors
/// <summary>
/// Initializes a new instance of the <see cref="FavoriteDropZoneRepository"/> class
/// </summary>
/// <param name="dataProvider">The data provider to use for data access</param>
public FavoriteDropZoneRepository(IDataProvider dataProvider)
{
_dataProvider = dataProvider;
_col = _dataProvider.CollOfFavoriteDropZone;
}
#endregion Public Constructors
#region Public Methods
/// <summary>
/// Adds a new favorite drop zone to the database
/// </summary>
/// <param name="favoriteToAdd">The favorite drop zone instance to add</param>
/// <returns>The number of rows affected (0 if insert failed)</returns>
public int Add(FavoriteDropZone favoriteToAdd)
{
int result;
try
{
var tmp = _col.Insert(favoriteToAdd);
result = tmp.AsInt32;
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// Deletes a favorite drop zone by drop zone ID and user ID
/// </summary>
/// <param name="dropZoneId">The unique identifier of the drop zone</param>
/// <param name="userId">The unique identifier of the user</param>
/// <returns>The number of rows affected (0 if delete failed)</returns>
public int Delete(int dropZoneId, int userId)
{
return _col.DeleteMany(d => d.DropZone.Id == dropZoneId && d.User.Id == userId);
}
/// <summary>
/// Retrieves all favorite drop zones for a specific user
/// </summary>
/// <param name="user">The user whose favorite drop zones to retrieve</param>
/// <returns>A collection of favorite drop zone instances belonging to the user</returns>
public IEnumerable<FavoriteDropZone> GetAll(User user)
{
return _col.Query()
.Where(j => j.User.Id == user.Id)
.ToList();
}
/// <summary>
/// Retrieves all favorite drop zones from the database
/// </summary>
/// <returns>A collection of all favorite drop zone instances</returns>
public IEnumerable<FavoriteDropZone> GetAll()
{
throw new System.NotImplementedException();
}
/// <summary>
/// Retrieves a favorite drop zone by its unique identifier
/// </summary>
/// <param name="id">The unique identifier of the favorite drop zone</param>
/// <returns>The favorite drop zone instance or null if not found</returns>
public FavoriteDropZone GetById(int id)
{
throw new System.NotImplementedException();
}
/// <summary>
/// Gets the total count of favorite drop zones in the database
/// </summary>
/// <returns>The total number of favorite drop zones</returns>
public int GetCount()
{
throw new System.NotImplementedException();
}
/// <summary>
/// Updates an existing favorite drop zone in the database
/// </summary>
/// <param name="updated">The favorite drop zone instance to update</param>
/// <returns>True if the update was successful, false otherwise</returns>
public bool Update(FavoriteDropZone updated)
{
throw new System.NotImplementedException();
}
#endregion Public Methods
#region Private Fields
private readonly ILiteCollection<FavoriteDropZone> _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}