Adds music play history persistence and reporting endpoints

This commit is contained in:
BinaryAlley committed 2026-10-19 22:16:09 +03:00
1 parent 9919965a73
commit 009a0c8156
55 files changed
+6426 -3

No files matched your search

@@ -0,0 +1,93 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
/// <summary>
/// Repository entity for a recorded play of a track.
/// </summary>
[DebuggerDisplay("Id: {Id}; TrackId: {TrackId}; Status: {Status}")]
public class MusicPlayRecordEntity : IStorageEntity, IAuditableEntity
{
/// <summary>
/// Gets the Id of the play record.
/// </summary>
public required Guid Id { get; init; }
/// <summary>
/// Gets or sets the Id of the user that started the play.
/// </summary>
public required Guid UserId { get; set; }
/// <summary>
/// Gets or sets the Id of the track that was played.
/// </summary>
public required Guid TrackId { get; set; }
/// <summary>
/// Gets or sets the Id of the media library that contains the track.
/// </summary>
public required Guid LibraryId { get; set; }
/// <summary>
/// Gets or sets the Id of the album that contains the track.
/// </summary>
public required Guid AlbumId { get; set; }
/// <summary>
/// Gets or sets the Id of the artist that produced the track.
/// </summary>
public required Guid ArtistId { get; set; }
/// <summary>
/// Gets or sets the state of the recorded play.
/// </summary>
public PlaybackRecordStatus Status { get; set; }
/// <summary>
/// Gets or sets the last position reported by the player, in milliseconds. It is stored as a whole number of milliseconds so that the
/// stored value is independent of the persistence medium's support for time values.
/// </summary>
public long LastPositionMilliseconds { get; set; }
/// <summary>
/// Gets or sets the duration the user has listened to, in milliseconds. It is stored as a whole number of milliseconds so that the
/// stored value is independent of the persistence medium's support for time values.
/// </summary>
public long ListenedDurationMilliseconds { get; set; }
/// <summary>
/// Gets or sets the date and time when the play completed or stopped, if it has ended.
/// </summary>
public DateTime? EndedOnUtc { get; set; }
/// <summary>
/// Gets or sets the version of the stored row. It is used as an optimistic concurrency token, so that a report that read the play
/// before another report ended it can never overwrite the newer state.
/// </summary>
public long Version { get; set; }
/// <summary>
/// Gets or sets the time and date when the entity was added. It is also the date and time when the play started.
/// </summary>
public required DateTime CreatedOnUtc { get; set; }
/// <summary>
/// Gets or sets the Id of the user that created the entity.
/// </summary>
public required Guid CreatedBy { get; set; }
/// <summary>
/// Gets or sets the optional time and date when the entity was updated.
/// </summary>
public DateTime? UpdatedOnUtc { get; set; }
/// <summary>
/// Gets or sets the optional Id of the user that updated the entity.
/// </summary>
public required Guid? UpdatedBy { get; set; }
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
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.MusicLibrary;
/// <summary>
/// Interface for the repository for recorded music plays.
/// </summary>
public interface IMusicPlayRecordRepository : IRepository<MusicPlayRecordEntity>,
IInsertRepositoryAction<MusicPlayRecordEntity>
{
/// <summary>
/// Gets the play 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 play record to get.</param>
/// <param name="userId">The Id of the user the play 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 play 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<MusicPlayRecordEntity?>> GetByIdForUserAsync(Guid id, Guid userId, bool shouldTrackEntities = true, CancellationToken cancellationToken = default);
/// <summary>
/// Updates the play 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 play record whose editable values are applied to the stored record.</param>
/// <param name="userId">The Id of the user the play 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 update, or an error.</returns>
Task<Result<Updated>> UpdateForUserAsync(MusicPlayRecordEntity data, Guid userId, CancellationToken cancellationToken);
}
@@ -150,6 +150,11 @@ public interface IUnitOfWork
/// </summary>
IUserSettingsRepository UserSettingsRepository { get; }
/// <summary>
/// Gets the music play record repository.
/// </summary>
IMusicPlayRecordRepository MusicPlayRecordRepository { get; }
/// <summary>
/// Saves the changes made to the database.
/// </summary>