Adds the consumption activity access policy and repository interfaces

This commit is contained in:
BinaryAlley committed 2026-10-24 15:29:43 +03:00
1 parent 822ccc9adc
commit 2ffacb5360
7 files changed
+251

No files matched your search

@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.MediaConsumption;
/// <summary>
/// Interface for the repository for the consumption records used to build consumption statistics.
/// </summary>
public interface IConsumptionStatisticsRepository : IRepository<MediaConsumptionRecordEntity>
{
/// <summary>
/// Gets the consumption records of the user identified by <paramref name="userId"/>, optionally limited to a media library, a media kind, and a date
/// range.
/// </summary>
/// <param name="userId">The Id of the user whose consumption records are retrieved.</param>
/// <param name="libraryId">The Id of the media library to restrict the records to, or <see langword="null"/> for every library.</param>
/// <param name="mediaKind">The kind of media to restrict the records to, or <see langword="null"/> for every kind.</param>
/// <param name="fromUtc">The start of the date range, or <see langword="null"/> when the range has no start.</param>
/// <param name="toUtc">The end of the date range, or <see langword="null"/> when the range has no end.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the consumption records of the user, or an error.</returns>
Task<Result<IReadOnlyList<MediaConsumptionRecordEntity>>> GetForUserAsync(Guid userId, Guid? libraryId, MediaKind? mediaKind, DateTime? fromUtc, DateTime? toUtc, CancellationToken cancellationToken);
/// <summary>
/// Gets the consumption records of every user, optionally limited to a media library, a media kind, and a date range.
/// </summary>
/// <param name="libraryId">The Id of the media library to restrict the records to, or <see langword="null"/> for every library.</param>
/// <param name="mediaKind">The kind of media to restrict the records to, or <see langword="null"/> for every kind.</param>
/// <param name="fromUtc">The start of the date range, or <see langword="null"/> when the range has no start.</param>
/// <param name="toUtc">The end of the date range, or <see langword="null"/> when the range has no end.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the consumption records of every user, or an error.</returns>
Task<Result<IReadOnlyList<MediaConsumptionRecordEntity>>> GetForAllUsersAsync(Guid? libraryId, MediaKind? mediaKind, DateTime? fromUtc, DateTime? toUtc, CancellationToken cancellationToken);
}
@@ -0,0 +1,59 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Domain.Common.Primitives;
using System;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.MediaConsumption;
/// <summary>
/// Interface for the repository for media consumption records.
/// </summary>
public interface IMediaConsumptionRecordRepository : IRepository<MediaConsumptionRecordEntity>,
IInsertRepositoryAction<MediaConsumptionRecordEntity>
{
/// <summary>
/// Gets the consumption record identified by <paramref name="id"/> when it belongs to the user identified by <paramref name="userId"/>, if it exists.
/// </summary>
/// <param name="id">The Id of the consumption record to get.</param>
/// <param name="userId">The Id of the user the consumption record must belong to.</param>
/// <param name="shouldTrackEntities">Whether the retrieved record should be tracked by the persistence medium, so that changes to it can be saved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either the consumption record identified by <paramref name="id"/> and owned by
/// <paramref name="userId"/>, <see langword="null"/> when no such record exists, or an error.
/// </returns>
Task<Result<MediaConsumptionRecordEntity?>> GetByIdForUserAsync(Guid id, Guid userId, bool shouldTrackEntities = true, CancellationToken cancellationToken = default);
/// <summary>
/// Updates the consumption record of the user identified by <paramref name="userId"/>, when the record belongs to that user and still holds the
/// version it was read with.
/// </summary>
/// <param name="data">The consumption record whose editable values are applied to the stored record. Its owner must match <paramref name="userId"/>.</param>
/// <param name="userId">The Id of the user the consumption record must belong to. It is authoritative for locating the stored record; the owner carried by <paramref name="data"/> is not used to select it.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful update, or an error.</returns>
Task<Result<Updated>> UpdateForUserAsync(MediaConsumptionRecordEntity data, Guid userId, CancellationToken cancellationToken);
/// <summary>
/// Deletes the consumption record identified by <paramref name="id"/> when it belongs to the user identified by <paramref name="userId"/>. A record
/// that does not exist is not an error.
/// </summary>
/// <param name="id">The Id of the consumption record to delete.</param>
/// <param name="userId">The Id of the user the consumption record must belong to.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful deletion, or an error.</returns>
Task<Result<Deleted>> DeleteForUserAsync(Guid id, Guid userId, CancellationToken cancellationToken);
/// <summary>
/// Deletes every consumption record of the user identified by <paramref name="userId"/>.
/// </summary>
/// <param name="userId">The Id of the user whose consumption records are deleted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful deletion, or an error.</returns>
Task<Result<Deleted>> DeleteAllForUserAsync(Guid userId, CancellationToken cancellationToken);
}
@@ -0,0 +1,70 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.MediaConsumption;
/// <summary>
/// Interface for the repository for media resume points.
/// </summary>
public interface IMediaResumePointRepository : IRepository<MediaResumePointEntity>
{
/// <summary>
/// Gets the resume point of the user identified by <paramref name="userId"/> for the media item identified by <paramref name="mediaKind"/> and
/// <paramref name="mediaItemId"/>, if it exists.
/// </summary>
/// <param name="userId">The Id of the user the resume point must belong to.</param>
/// <param name="mediaKind">The kind of the media item to resume.</param>
/// <param name="mediaItemId">The Id of the media item to resume.</param>
/// <param name="shouldTrackEntities">Whether the retrieved resume point should be tracked by the persistence medium, so that changes to it can be saved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either the resume point of the user for the media item, <see langword="null"/> when no such resume
/// point exists, or an error.
/// </returns>
Task<Result<MediaResumePointEntity?>> GetForUserAndMediaItemAsync(Guid userId, MediaKind mediaKind, Guid mediaItemId, bool shouldTrackEntities = true, CancellationToken cancellationToken = default);
/// <summary>
/// Saves the resume point of the user identified by <paramref name="userId"/>, inserting it when it does not exist and updating it otherwise. The
/// business key of the resume point, made of the user, the media kind, and the media item, is preserved.
/// </summary>
/// <param name="data">The resume point whose values are saved. Its owner must match <paramref name="userId"/>.</param>
/// <param name="userId">The Id of the user the resume point must belong to. It is authoritative for locating the stored resume point and for the owner of a new one; the owner carried by <paramref name="data"/> is not used to select it.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful save, or an error.</returns>
Task<Result<Updated>> UpsertForUserAsync(MediaResumePointEntity data, Guid userId, CancellationToken cancellationToken);
/// <summary>
/// Deletes the resume point of the user identified by <paramref name="userId"/> for the media item identified by <paramref name="mediaKind"/> and
/// <paramref name="mediaItemId"/>. A resume point that does not exist is not an error.
/// </summary>
/// <param name="userId">The Id of the user the resume point must belong to.</param>
/// <param name="mediaKind">The kind of the media item to resume.</param>
/// <param name="mediaItemId">The Id of the media item to resume.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful deletion, or an error.</returns>
Task<Result<Deleted>> DeleteForUserAndMediaItemAsync(Guid userId, MediaKind mediaKind, Guid mediaItemId, CancellationToken cancellationToken);
/// <summary>
/// Deletes every resume point of the user identified by <paramref name="userId"/>.
/// </summary>
/// <param name="userId">The Id of the user whose resume points are deleted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful deletion, or an error.</returns>
Task<Result<Deleted>> DeleteAllForUserAsync(Guid userId, CancellationToken cancellationToken);
/// <summary>
/// Deletes every resume point of the user identified by <paramref name="userId"/> in the media library identified by <paramref name="libraryId"/>.
/// </summary>
/// <param name="userId">The Id of the user whose resume points are deleted.</param>
/// <param name="libraryId">The Id of the media library whose resume points are deleted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful deletion, or an error.</returns>
Task<Result<Deleted>> DeleteAllForUserInLibraryAsync(Guid userId, Guid libraryId, CancellationToken cancellationToken);
}