Files
MilkyShots/Lactose/Repositories/IAlbumRepository.cs
T

145 lines
7.4 KiB
C#

using Butter.Dtos;
using Butter.Dtos.Album;
using Butter.Types;
using Lactose.Models;
namespace Lactose.Repositories;
/// <summary>
/// Interface for album repository operations.
/// </summary>
public interface IAlbumRepository : IDisposable {
/// <summary>
/// Inserts a new album into the database.
/// </summary>
/// <param name="album">The album to insert.</param>
void Insert(Album album);
/// <summary>
/// Updates an album in the database.
/// </summary>
/// <param name="album">The album to update.</param>
void Update(Album album);
/// <summary>
/// Updates multiple albums in the database.
/// </summary>
/// <param name="albums">The albums to update.</param>
void UpdateBulk(IEnumerable<Album> albums);
/// <summary>
/// Saves changes to the database.
/// </summary>
/// <param name="cancellationToken">Token to cancel the operation.</param>
Task SaveAsync(CancellationToken cancellationToken);
/// <summary>
/// Finds an album by its ID.
/// </summary>
/// <param name="id">The ID of the album.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>The album if found; otherwise, null.</returns>
Task<Album?> FindAsync(Guid id, CancellationToken cancellationToken);
/// <summary>
/// Finds an album by its ID with its assets loaded for collection replacement.
/// </summary>
/// <param name="id">The ID of the album.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>The album with its asset collection loaded if found; otherwise, null.</returns>
Task<Album?> FindWithAssetsAsync(Guid id, CancellationToken cancellationToken);
/// <summary>
/// Finds an album by its ID with assets filtered by the requesting user's access level.
/// </summary>
/// <param name="id">The ID of the album.</param>
/// <param name="userId">The requesting user's ID for visibility-scoped asset filtering.</param>
/// <param name="accessLevel">The requesting user's access level.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>The album if found; otherwise, null.</returns>
Task<Album?> FindVisibleAsync(Guid id, Guid? userId, EAccessLevel accessLevel, CancellationToken cancellationToken);
/// <summary>
/// Finds albums by the person's ID.
/// </summary>
/// <param name="personId">The ID of the person.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>A collection of albums associated with the specified person.</returns>
Task<List<Album>> FindByPersonAsync(Guid personId, CancellationToken cancellationToken);
/// <summary>
/// Finds albums owned by any of the specified people.
/// </summary>
/// <param name="personIds">The IDs of the people.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>A collection of albums associated with the specified people.</returns>
Task<List<Album>> FindByPersonIdsAsync(IEnumerable<Guid> personIds, CancellationToken cancellationToken);
/// <summary>
/// Bulk-updates the visibility of all albums owned by the specified people via a single SQL UPDATE.
/// </summary>
/// <param name="personIds">The IDs of the people.</param>
/// <param name="visibility">The target visibility level.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>The number of albums updated.</returns>
Task<int> BulkSetVisibilityByPersonIdsAsync(IEnumerable<Guid> personIds, EVisibility visibility, CancellationToken cancellationToken);
/// <summary>
/// Finds multiple albums by their IDs.
/// </summary>
/// <param name="ids">The IDs of the albums.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>A collection of albums with the specified IDs.</returns>
Task<List<Album>> FindBulkAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken);
/// <summary>
/// Finds albums within a specified date range.
/// </summary>
/// <param name="from">The start date of the range.</param>
/// <param name="to">The end date of the range.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>A collection of albums created or updated within the specified date range.</returns>
Task<List<Album>> FindByDateRangeAsync(DateTime from, DateTime to, CancellationToken cancellationToken);
/// <summary>
/// Merges multiple source albums into a destination album.
/// All assets from source albums are moved to the destination, then source albums are hard-deleted.
/// </summary>
/// <param name="destId">The ID of the destination album.</param>
/// <param name="sourceIds">The IDs of the source albums to merge.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
Task MergeAlbumsAsync(Guid destId, List<Guid> sourceIds, CancellationToken cancellationToken);
/// <summary>
/// Removes an album from the database.
/// </summary>
/// <param name="album">The album to remove.</param>
void Remove(Album album);
/// <summary>
/// Searches for albums based on a query string with optional sorting, filtering, and access-level scoping.
/// </summary>
/// <param name="query">The search query string to filter by title.</param>
/// <param name="page">The page number for pagination (default is 0).</param>
/// <param name="pageSize">The number of results per page (default is <see cref="PagedParametersDto.MaxPageSize"/>).</param>
/// <param name="sortBy">The field to sort by (e.g. "name", "created", "updated", "assets", "person"). When <c>null</c>, defaults to created descending.</param>
/// <param name="sortAsc">Whether to sort ascending. Default is <c>false</c> (descending).</param>
/// <param name="unassigned">When <c>true</c>, only return albums with no person assigned.</param>
/// <param name="userId">The current user's ID for access-level filtering.</param>
/// <param name="accessLevel">The current user's access level. Regular users only see albums with visible assets.</param>
/// <param name="uploadedBy">Optional filter for albums containing assets uploaded by a specific user.</param>
/// <param name="personOwnerId">Optional filter for albums owned by a specific person.</param>
/// <param name="cancellationToken">Token to cancel the operation.</param>
/// <returns>A list of album previews matching the search query.</returns>
Task<List<AlbumPreviewDto>> SearchQueryAsync(string query, int page, int pageSize, string? sortBy, bool sortAsc, bool unassigned, Guid userId, EAccessLevel accessLevel, Guid? uploadedBy, Guid? personOwnerId, CancellationToken cancellationToken);
/// <summary>
/// Executes the given operation inside an explicit transaction on the shared database context,
/// committing on success and rolling back on failure.
/// </summary>
/// <typeparam name="TResult">The type returned by the operation.</typeparam>
/// <param name="operation">The work to run inside the transaction.</param>
/// <returns>The operation's result, or null if the operation returned null.</returns>
Task<TResult?> ExecuteInTransactionAsync<TResult>(Func<Task<TResult?>> operation);
}