diff --git a/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsDto.cs b/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsDto.cs
deleted file mode 100644
index d3a2a618..00000000
--- a/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsDto.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Data transfer object for the listening statistics of the current user.
-///
-/// The total duration the user listened to, over every recorded play, in milliseconds.
-/// The number of recorded plays that count as plays. An in-progress play counts once it reaches the threshold, so this total can exceed the completed and stopped plays together.
-/// The number of recorded plays that completed.
-/// The number of recorded plays that stopped before the track completed and count as plays.
-/// The fraction of the plays that count as plays that completed, between 0 and 1, or 0 when there is no counted play.
-[DebuggerDisplay("TotalPlayCount: {TotalPlayCount}; CompletedPlayCount: {CompletedPlayCount}")]
-public sealed record MusicPlayStatisticsDto(
- long TotalListeningDurationMilliseconds,
- int TotalPlayCount,
- int CompletedPlayCount,
- int StoppedPlayCount,
- double CompletionRate
-);
diff --git a/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackDto.cs b/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackDto.cs
deleted file mode 100644
index 1ba82882..00000000
--- a/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackDto.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Data transfer object for a track of the listening statistics of the current user, together with its aggregated play counts.
-///
-/// The Id of the track.
-/// The Id of the media library that contains the track.
-/// The Id of the album that contains the track.
-/// The Id of the artist that produced the track.
-/// The title of the track, if it still exists and the user can access its library.
-/// The title of the album that contains the track, if it still exists and the user can access its library.
-/// The name of the artist that produced the track, if it still exists and the user can access its library.
-/// The path of the cover art of the album, if available.
-/// The date and time of the last recorded activity of the track's most recent play.
-/// The number of plays of the track that count as plays.
-/// The number of plays of the track that completed.
-/// The duration the user listened to the track, over all of its counted plays, in milliseconds.
-[DebuggerDisplay("TrackId: {TrackId}; PlayCount: {PlayCount}")]
-public sealed record PlayedTrackDto(
- Guid TrackId,
- Guid LibraryId,
- Guid AlbumId,
- Guid ArtistId,
- string? Title,
- string? AlbumTitle,
- string? ArtistName,
- string? CoverPath,
- DateTime LastPlayedOnUtc,
- int PlayCount,
- int CompletedPlayCount,
- long ListenedDurationMilliseconds
-);
diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicPlayRecordEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicPlayRecordEntity.cs
deleted file mode 100644
index 630e7d3e..00000000
--- a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicPlayRecordEntity.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-#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;
-
-///
-/// Repository entity for a recorded play of a track.
-///
-[DebuggerDisplay("Id: {Id}; TrackId: {TrackId}; Status: {Status}")]
-public class MusicPlayRecordEntity : IStorageEntity, IAuditableEntity
-{
- ///
- /// Gets the Id of the play record.
- ///
- public required Guid Id { get; init; }
-
- ///
- /// Gets or sets the Id of the user that started the play.
- ///
- public required Guid UserId { get; set; }
-
- ///
- /// Gets or sets the Id of the track that was played.
- ///
- public required Guid TrackId { get; set; }
-
- ///
- /// Gets or sets the Id of the media library that contains the track.
- ///
- public required Guid LibraryId { get; set; }
-
- ///
- /// Gets or sets the Id of the album that contains the track.
- ///
- public required Guid AlbumId { get; set; }
-
- ///
- /// Gets or sets the Id of the artist that produced the track.
- ///
- public required Guid ArtistId { get; set; }
-
- ///
- /// Gets or sets the state of the recorded play.
- ///
- public PlaybackRecordStatus Status { get; set; }
-
- ///
- /// 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.
- ///
- public long LastPositionMilliseconds { get; set; }
-
- ///
- /// 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.
- ///
- public long ListenedDurationMilliseconds { get; set; }
-
- ///
- /// Gets or sets the date and time when the play completed or stopped, if it has ended.
- ///
- public DateTime? EndedOnUtc { get; set; }
-
- ///
- /// 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.
- ///
- public long Version { get; set; }
-
- ///
- /// Gets or sets the time and date when the entity was added. It is also the date and time when the play started.
- ///
- public required DateTime CreatedOnUtc { get; set; }
-
- ///
- /// Gets or sets the Id of the user that created the entity.
- ///
- public required Guid CreatedBy { get; set; }
-
- ///
- /// Gets or sets the optional time and date when the entity was updated.
- ///
- public DateTime? UpdatedOnUtc { get; set; }
-
- ///
- /// Gets or sets the optional Id of the user that updated the entity.
- ///
- public required Guid? UpdatedBy { get; set; }
-}
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IMusicPlayRecordRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IMusicPlayRecordRepository.cs
deleted file mode 100644
index 47b1eecc..00000000
--- a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IMusicPlayRecordRepository.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-#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.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-#endregion
-
-namespace Lumina.Application.Common.DataAccess.Repositories.MusicLibrary;
-
-///
-/// Interface for the repository for recorded music plays.
-///
-public interface IMusicPlayRecordRepository : IRepository,
- IInsertRepositoryAction
-{
- ///
- /// Gets the play record identified by when it belongs to the user identified by , if it exists.
- ///
- /// The Id of the play record to get.
- /// The Id of the user the play record must belong to.
- /// Whether the retrieved record should be tracked by the persistence medium, so that changes to it can be saved.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An containing either the play record identified by and owned by ,
- /// when no such record exists, or an error.
- ///
- Task> GetByIdForUserAsync(Guid id, Guid userId, bool shouldTrackEntities = true, CancellationToken cancellationToken = default);
-
- ///
- /// Gets the play records of the user identified by .
- ///
- /// The Id of the user whose play records are retrieved.
- /// Cancellation token that can be used to stop the execution.
- /// An containing either the play records of the user, or an error.
- Task>> GetForUserAsync(Guid userId, CancellationToken cancellationToken);
-
- ///
- /// Updates the play record of the user identified by , when the record belongs to that user and still holds the
- /// version it was read with.
- ///
- /// The play record whose editable values are applied to the stored record.
- /// The Id of the user the play record must belong to.
- /// Cancellation token that can be used to stop the execution.
- /// An representing either a successful update, or an error.
- Task> UpdateForUserAsync(MusicPlayRecordEntity data, Guid userId, CancellationToken cancellationToken);
-}
diff --git a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
index 65ab73cd..dd1cb2c6 100644
--- a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
+++ b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
@@ -153,11 +153,6 @@ public interface IUnitOfWork
///
IUserSettingsRepository UserSettingsRepository { get; }
- ///
- /// Gets the music play record repository.
- ///
- IMusicPlayRecordRepository MusicPlayRecordRepository { get; }
-
///
/// Gets the playlist repository.
///
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/CompletePlayRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/CompletePlayRequestMapping.cs
deleted file mode 100644
index 499ed894..00000000
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/CompletePlayRequestMapping.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.CompletePlay;
-using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-#endregion
-
-namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Extension methods for converting .
-///
-public static class CompletePlayRequestMapping
-{
- ///
- /// Converts to .
- ///
- /// The request to be converted.
- /// The Id of the play record, taken from the route.
- /// The converted command.
- public static CompletePlayCommand ToCommand(this CompletePlayRequest request, string? playRecordId)
- {
- return new CompletePlayCommand(
- playRecordId,
- request.PositionInSeconds,
- request.ListenedDurationInSeconds
- );
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayedRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayedRequestMapping.cs
deleted file mode 100644
index 4b40666e..00000000
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayedRequestMapping.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.DTO.Pagination;
-using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetMostPlayed;
-using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-#endregion
-
-namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Extension methods for converting .
-///
-public static class GetMostPlayedRequestMapping
-{
- ///
- /// Converts to .
- ///
- /// The request to be converted.
- /// The converted query.
- public static GetMostPlayedQuery ToQuery(this GetMostPlayedRequest request)
- {
- PaginationDataDto? paginationData = null;
- if (request.CurrentPage is not null || request.PerPage is not null)
- paginationData = new PaginationDataDto
- {
- CurrentPage = request.CurrentPage ?? 1,
- PerPage = request.PerPage ?? 50
- };
-
- return new GetMostPlayedQuery(paginationData);
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayedRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayedRequestMapping.cs
deleted file mode 100644
index dfd96ce4..00000000
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayedRequestMapping.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.DTO.Pagination;
-using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetRecentlyPlayed;
-using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-#endregion
-
-namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Extension methods for converting .
-///
-public static class GetRecentlyPlayedRequestMapping
-{
- ///
- /// Converts to .
- ///
- /// The request to be converted.
- /// The converted query.
- public static GetRecentlyPlayedQuery ToQuery(this GetRecentlyPlayedRequest request)
- {
- PaginationDataDto? paginationData = null;
- if (request.CurrentPage is not null || request.PerPage is not null)
- paginationData = new PaginationDataDto
- {
- CurrentPage = request.CurrentPage ?? 1,
- PerPage = request.PerPage ?? 50
- };
-
- return new GetRecentlyPlayedQuery(paginationData);
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayRecordEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayRecordEntityMapping.cs
deleted file mode 100644
index 5cb47d47..00000000
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayRecordEntityMapping.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Lumina.Application.Common.Utilities;
-using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Domain.Common.Primitives;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.AudioLibraryBoundedContext.MusicLibraryAggregate;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.ValueObjects;
-using System;
-#endregion
-
-namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Extension methods for converting .
-///
-public static class MusicPlayRecordEntityMapping
-{
- ///
- /// Converts to .
- ///
- /// The repository entity to be converted.
- ///
- /// An containing either a successfully converted , or an error message.
- ///
- public static Result ToDomainEntity(this MusicPlayRecordEntity repositoryEntity)
- {
- return MusicPlayRecord.Create(
- MusicPlayRecordId.Create(repositoryEntity.Id),
- UserId.Create(repositoryEntity.UserId),
- TrackId.Create(repositoryEntity.TrackId),
- LibraryId.Create(repositoryEntity.LibraryId),
- AlbumId.Create(repositoryEntity.AlbumId),
- ArtistId.Create(repositoryEntity.ArtistId),
- repositoryEntity.Status,
- MusicPlayPosition.Create(repositoryEntity.LastPositionMilliseconds.ToClampedTimeSpan()),
- repositoryEntity.ListenedDurationMilliseconds.ToClampedTimeSpan(),
- Optional.FromNullable(repositoryEntity.EndedOnUtc),
- repositoryEntity.CreatedOnUtc,
- Optional.FromNullable(repositoryEntity.UpdatedOnUtc)
- );
- }
-
- ///
- /// Converts to .
- ///
- /// The repository entity to be converted.
- /// The converted response.
- public static PlayRecordResponse ToResponse(this MusicPlayRecordEntity repositoryEntity)
- {
- return new PlayRecordResponse(
- repositoryEntity.Id,
- repositoryEntity.TrackId,
- repositoryEntity.LibraryId,
- repositoryEntity.AlbumId,
- repositoryEntity.ArtistId,
- repositoryEntity.Status,
- repositoryEntity.LastPositionMilliseconds.ToClampedTimeSpan().TotalSeconds,
- repositoryEntity.ListenedDurationMilliseconds.ToClampedTimeSpan().TotalSeconds,
- repositoryEntity.CreatedOnUtc,
- repositoryEntity.EndedOnUtc,
- repositoryEntity.UpdatedOnUtc
- );
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayRecordMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayRecordMapping.cs
deleted file mode 100644
index 5a1c25cf..00000000
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayRecordMapping.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate;
-using System;
-#endregion
-
-namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Extension methods for converting .
-///
-public static class MusicPlayRecordMapping
-{
- ///
- /// Converts to .
- ///
- /// The domain entity to be converted.
- /// The converted repository entity.
- public static MusicPlayRecordEntity ToRepositoryEntity(this MusicPlayRecord domainEntity)
- {
- return new MusicPlayRecordEntity
- {
- Id = domainEntity.Id.Value,
- UserId = domainEntity.UserId.Value,
- TrackId = domainEntity.TrackId.Value,
- LibraryId = domainEntity.LibraryId.Value,
- AlbumId = domainEntity.AlbumId.Value,
- ArtistId = domainEntity.ArtistId.Value,
- Status = domainEntity.Status,
- // Stored time is truncated to whole milliseconds instead of rounded, so a retried report of the same fractional second maps to
- // the same stored value and is not rejected as a decrease by the domain.
- LastPositionMilliseconds = (long)domainEntity.LastPosition.Offset.TotalMilliseconds,
- ListenedDurationMilliseconds = (long)domainEntity.ListenedDuration.TotalMilliseconds,
- EndedOnUtc = domainEntity.EndedOnUtc.HasValue ? domainEntity.EndedOnUtc.Value : null,
- Version = 1,
- CreatedOnUtc = domainEntity.CreatedOnUtc,
- CreatedBy = Guid.Empty,
- // The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
- UpdatedOnUtc = null,
- UpdatedBy = null
- };
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsDtoMapping.cs
deleted file mode 100644
index 0c659a52..00000000
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsDtoMapping.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Application.Common.Utilities;
-using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-#endregion
-
-namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Extension methods for converting .
-///
-public static class MusicPlayStatisticsDtoMapping
-{
- ///
- /// Converts to .
- ///
- /// The listening statistics data to be converted.
- /// The converted response.
- public static MusicPlayStatisticsResponse ToResponse(this MusicPlayStatisticsDto data)
- {
- return new MusicPlayStatisticsResponse(
- data.TotalListeningDurationMilliseconds.ToClampedTimeSpan().TotalSeconds,
- data.TotalPlayCount,
- data.CompletedPlayCount,
- data.StoppedPlayCount,
- data.CompletionRate
- );
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackDtoMapping.cs
deleted file mode 100644
index 26d10553..00000000
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackDtoMapping.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Application.Common.DTO.Pagination;
-using Lumina.Application.Common.Utilities;
-using Lumina.Contracts.Responses.Common;
-using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using System;
-using System.Linq;
-#endregion
-
-namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Extension methods for converting .
-///
-public static class PlayedTrackDtoMapping
-{
- ///
- /// Converts to .
- ///
- /// The played track data to be converted.
- /// The converted response.
- public static PlayedTrackResponse ToResponse(this PlayedTrackDto data)
- {
- return new PlayedTrackResponse(
- data.TrackId,
- data.LibraryId,
- data.AlbumId,
- data.ArtistId,
- data.Title,
- data.AlbumTitle,
- data.ArtistName,
- data.CoverPath,
- // The repository reads the stored play time through SQLite, which returns it as an unspecified kind, and the JSON response must not
- // present a UTC wall clock as a local time. The value is UTC when it was stored, so it is marked as such before it is serialized.
- DateTime.SpecifyKind(data.LastPlayedOnUtc, DateTimeKind.Utc),
- data.PlayCount,
- data.CompletedPlayCount,
- data.ListenedDurationMilliseconds.ToClampedTimeSpan().TotalSeconds
- );
- }
-
- ///
- /// Converts to a paginated collection of .
- ///
- /// The paginated played track data to be converted.
- /// The converted paginated responses.
- public static PaginatedResponse ToResponses(this PaginatedResultDto data)
- {
- return new PaginatedResponse
- {
- Data = [.. data.Data.Select(track => track.ToResponse())],
- CurrentPage = data.CurrentPage,
- PerPage = data.PerPage,
- Count = data.Count,
- NumberOfPages = data.NumberOfPages
- };
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgressRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgressRequestMapping.cs
deleted file mode 100644
index 080a0c13..00000000
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgressRequestMapping.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.ReportPlayProgress;
-using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-#endregion
-
-namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Extension methods for converting .
-///
-public static class ReportPlayProgressRequestMapping
-{
- ///
- /// Converts to .
- ///
- /// The request to be converted.
- /// The Id of the play record, taken from the route.
- /// The converted command.
- public static ReportPlayProgressCommand ToCommand(this ReportPlayProgressRequest request, string? playRecordId)
- {
- return new ReportPlayProgressCommand(
- playRecordId,
- request.PositionInSeconds,
- request.ListenedDurationInSeconds
- );
- }
-}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/StopPlayRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/StopPlayRequestMapping.cs
deleted file mode 100644
index acd87f58..00000000
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/StopPlayRequestMapping.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StopPlay;
-using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-#endregion
-
-namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Extension methods for converting .
-///
-public static class StopPlayRequestMapping
-{
- ///
- /// Converts to .
- ///
- /// The request to be converted.
- /// The Id of the play record, taken from the route.
- /// The converted command.
- public static StopPlayCommand ToCommand(this StopPlayRequest request, string? playRecordId)
- {
- return new StopPlayCommand(
- playRecordId,
- request.PositionInSeconds,
- request.ListenedDurationInSeconds
- );
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommand.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommand.cs
deleted file mode 100644
index e0132e43..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommand.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.CompletePlay;
-
-///
-/// Command for reporting that a play of a track by the current user reached its end.
-///
-/// The Id of the play record, taken from the route.
-/// The last position reported by the player, in seconds.
-/// The duration the user listened to, in seconds.
-[DebuggerDisplay("PlayRecordId: {PlayRecordId}; PositionInSeconds: {PositionInSeconds}")]
-public record CompletePlayCommand(
- string? PlayRecordId,
- double? PositionInSeconds,
- double? ListenedDurationInSeconds
-) : ICommand;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommandHandler.cs
deleted file mode 100644
index 3d0f2bd0..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommandHandler.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Lumina.Application.Common.DataAccess.UoW;
-using Lumina.Application.Common.DomainEvents;
-using Lumina.Application.Common.Infrastructure.Authentication;
-using Lumina.Application.Common.Infrastructure.Validation;
-using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Domain.Common.Events;
-using Lumina.Domain.Common.Primitives;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.ValueObjects;
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
-using DomainErrors = Lumina.Domain.Common.Errors.Errors;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.CompletePlay;
-
-///
-/// Handler for the command to report that a play of a track by the current user reached its end.
-///
-public class CompletePlayCommandHandler : ICommandHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly ICurrentUserService _currentUserService;
- private readonly IDomainEventsQueue _domainEventsQueue;
- private readonly IValidator _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected service to retrieve the current user information.
- /// Injected service for the queue of domain events.
- /// Injected validator for application validation rules.
- public CompletePlayCommandHandler(
- IUnitOfWork unitOfWork,
- ICurrentUserService currentUserService,
- IDomainEventsQueue domainEventsQueue,
- IValidator validator)
- {
- _unitOfWork = unitOfWork;
- _currentUserService = currentUserService;
- _domainEventsQueue = domainEventsQueue;
- _validator = validator;
- }
-
- ///
- /// Handles the command to report that a play of a track by the current user reached its end.
- ///
- /// The command to be handled.
- /// Cancellation token that can be used to stop the execution.
- /// An representing either a successful update, or an error message.
- public async Task> HandleAsync(CompletePlayCommand command, CancellationToken cancellationToken)
- {
- List validationResult = _validator.Validate(command);
- if (validationResult.Count > 0)
- return validationResult;
-
- // An authenticated request must always carry a user identity.
- Guid? currentUserId = _currentUserService.UserId;
- if (currentUserId is null)
- return ApplicationErrors.Authorization.NotAuthorized;
- Guid userId = currentUserId.Value;
-
- // The validator guarantees that the route identifier and the reported times are valid before this point.
- Guid playRecordId = Guid.Parse(command.PlayRecordId!);
-
- // The record is loaded scoped to the current user, so a record of another user is indistinguishable from a missing one.
- Result getPlayRecordResult = await _unitOfWork.MusicPlayRecordRepository
- .GetByIdForUserAsync(playRecordId, userId, cancellationToken: cancellationToken).ConfigureAwait(false);
- if (getPlayRecordResult.IsFailure)
- return getPlayRecordResult.Errors;
- if (getPlayRecordResult.Value is null)
- return DomainErrors.MusicPlayHistory.MusicPlayRecordNotFound;
-
- Result toDomainEntityResult = getPlayRecordResult.Value.ToDomainEntity();
- if (toDomainEntityResult.IsFailure)
- return toDomainEntityResult.Errors;
- MusicPlayRecord playRecord = toDomainEntityResult.Value;
-
- Result completeResult = playRecord.Complete(
- MusicPlayPosition.Create(TimeSpan.FromSeconds(command.PositionInSeconds!.Value)),
- TimeSpan.FromSeconds(command.ListenedDurationInSeconds!.Value));
- if (completeResult.IsFailure)
- return completeResult.Errors;
-
- Result updateResult = await _unitOfWork.MusicPlayRecordRepository
- .UpdateForUserAsync(playRecord.ToRepositoryEntity(), userId, cancellationToken).ConfigureAwait(false);
- if (updateResult.IsFailure)
- return updateResult.Errors;
-
- Result saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
- if (saveChangesResult.IsFailure)
- return saveChangesResult.Errors;
-
- // Queue any domain events, to be published after the request has completed successfully.
- foreach (IDomainEvent domainEvent in playRecord.GetDomainEvents())
- _domainEventsQueue.Enqueue(domainEvent);
-
- return Result.Updated;
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommandValidator.cs
deleted file mode 100644
index 10da852f..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommandValidator.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.Infrastructure.Validation;
-using Lumina.Application.Common.Utilities;
-using Lumina.Domain.Common.Errors;
-using System;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.CompletePlay;
-
-///
-/// Validates the needed validation rules for .
-///
-public class CompletePlayCommandValidator : AbstractValidator
-{
- ///
- /// Initializes a new instance of the class.
- ///
- public CompletePlayCommandValidator()
- {
- RuleFor(command => command.PlayRecordId)
- .NotEmpty()
- .WithError(Errors.MusicPlayHistory.PlayRecordIdCannotBeEmpty);
-
- RuleFor(command => command.PlayRecordId)
- .Must(playRecordId => Guid.TryParse(playRecordId, out Guid parsedPlayRecordId) && parsedPlayRecordId != Guid.Empty)
- .When(command => command.PlayRecordId is not null && command.PlayRecordId.Length > 0)
- .WithError(Errors.MusicPlayHistory.PlayRecordIdCannotBeEmpty);
-
- RuleFor(command => command.PositionInSeconds)
- .NotNull()
- .WithError(Errors.MusicPlayHistory.PlaybackPositionCannotBeNull);
-
- RuleFor(command => command.PositionInSeconds)
- .Must(position => position is null || (double.IsFinite(position.Value) && position.Value >= 0))
- .WithError(Errors.MusicPlayHistory.PlaybackPositionMustBeNonNegative);
-
- RuleFor(command => command.PositionInSeconds)
- .Must(position => position is null || position.Value <= TimeSpan.MaxValue.TotalSeconds)
- .WithError(Errors.MusicPlayHistory.PlaybackPositionIsOutOfRange);
-
- RuleFor(command => command.ListenedDurationInSeconds)
- .NotNull()
- .WithError(Errors.MusicPlayHistory.ListenedDurationCannotBeNull);
-
- RuleFor(command => command.ListenedDurationInSeconds)
- .Must(listenedDuration => listenedDuration is null || (double.IsFinite(listenedDuration.Value) && listenedDuration.Value >= 0))
- .WithError(Errors.MusicPlayHistory.ListenedDurationMustBeNonNegative);
-
- RuleFor(command => command.ListenedDurationInSeconds)
- .Must(listenedDuration => listenedDuration is null || listenedDuration.Value <= TimeSpan.MaxValue.TotalSeconds)
- .WithError(Errors.MusicPlayHistory.ListenedDurationIsOutOfRange);
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommand.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommand.cs
deleted file mode 100644
index 23c3344a..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommand.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.ReportPlayProgress;
-
-///
-/// Command for reporting the progress of a play of a track by the current user.
-///
-/// The Id of the play record, taken from the route.
-/// The last position reported by the player, in seconds.
-/// The duration the user has listened to, in seconds.
-[DebuggerDisplay("PlayRecordId: {PlayRecordId}; PositionInSeconds: {PositionInSeconds}")]
-public record ReportPlayProgressCommand(
- string? PlayRecordId,
- double? PositionInSeconds,
- double? ListenedDurationInSeconds
-) : ICommand;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommandHandler.cs
deleted file mode 100644
index 05b6e5f2..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommandHandler.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Lumina.Application.Common.DataAccess.UoW;
-using Lumina.Application.Common.DomainEvents;
-using Lumina.Application.Common.Infrastructure.Authentication;
-using Lumina.Application.Common.Infrastructure.Validation;
-using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Domain.Common.Events;
-using Lumina.Domain.Common.Primitives;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.ValueObjects;
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
-using DomainErrors = Lumina.Domain.Common.Errors.Errors;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.ReportPlayProgress;
-
-///
-/// Handler for the command to report the progress of a play of a track by the current user.
-///
-public class ReportPlayProgressCommandHandler : ICommandHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly ICurrentUserService _currentUserService;
- private readonly IDomainEventsQueue _domainEventsQueue;
- private readonly IValidator _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected service to retrieve the current user information.
- /// Injected service for the queue of domain events.
- /// Injected validator for application validation rules.
- public ReportPlayProgressCommandHandler(
- IUnitOfWork unitOfWork,
- ICurrentUserService currentUserService,
- IDomainEventsQueue domainEventsQueue,
- IValidator validator)
- {
- _unitOfWork = unitOfWork;
- _currentUserService = currentUserService;
- _domainEventsQueue = domainEventsQueue;
- _validator = validator;
- }
-
- ///
- /// Handles the command to report the progress of a play of a track by the current user.
- ///
- /// The command to be handled.
- /// Cancellation token that can be used to stop the execution.
- /// An representing either a successful update, or an error message.
- public async Task> HandleAsync(ReportPlayProgressCommand command, CancellationToken cancellationToken)
- {
- List validationResult = _validator.Validate(command);
- if (validationResult.Count > 0)
- return validationResult;
-
- // An authenticated request must always carry a user identity.
- Guid? currentUserId = _currentUserService.UserId;
- if (currentUserId is null)
- return ApplicationErrors.Authorization.NotAuthorized;
- Guid userId = currentUserId.Value;
-
- // The validator guarantees that the route identifier and the reported times are valid before this point.
- Guid playRecordId = Guid.Parse(command.PlayRecordId!);
-
- // The record is loaded scoped to the current user, so a record of another user is indistinguishable from a missing one.
- Result getPlayRecordResult = await _unitOfWork.MusicPlayRecordRepository
- .GetByIdForUserAsync(playRecordId, userId, cancellationToken: cancellationToken).ConfigureAwait(false);
- if (getPlayRecordResult.IsFailure)
- return getPlayRecordResult.Errors;
- if (getPlayRecordResult.Value is null)
- return DomainErrors.MusicPlayHistory.MusicPlayRecordNotFound;
-
- Result toDomainEntityResult = getPlayRecordResult.Value.ToDomainEntity();
- if (toDomainEntityResult.IsFailure)
- return toDomainEntityResult.Errors;
- MusicPlayRecord playRecord = toDomainEntityResult.Value;
-
- Result reportProgressResult = playRecord.ReportProgress(
- MusicPlayPosition.Create(TimeSpan.FromSeconds(command.PositionInSeconds!.Value)),
- TimeSpan.FromSeconds(command.ListenedDurationInSeconds!.Value));
- if (reportProgressResult.IsFailure)
- return reportProgressResult.Errors;
-
- Result updateResult = await _unitOfWork.MusicPlayRecordRepository
- .UpdateForUserAsync(playRecord.ToRepositoryEntity(), userId, cancellationToken).ConfigureAwait(false);
- if (updateResult.IsFailure)
- return updateResult.Errors;
-
- Result saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
- if (saveChangesResult.IsFailure)
- return saveChangesResult.Errors;
-
- // Queue any domain events, to be published after the request has completed successfully.
- foreach (IDomainEvent domainEvent in playRecord.GetDomainEvents())
- _domainEventsQueue.Enqueue(domainEvent);
-
- return Result.Updated;
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommandValidator.cs
deleted file mode 100644
index 103e9e04..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommandValidator.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.Infrastructure.Validation;
-using Lumina.Application.Common.Utilities;
-using Lumina.Domain.Common.Errors;
-using System;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.ReportPlayProgress;
-
-///
-/// Validates the needed validation rules for .
-///
-public class ReportPlayProgressCommandValidator : AbstractValidator
-{
- ///
- /// Initializes a new instance of the class.
- ///
- public ReportPlayProgressCommandValidator()
- {
- RuleFor(command => command.PlayRecordId)
- .NotEmpty()
- .WithError(Errors.MusicPlayHistory.PlayRecordIdCannotBeEmpty);
-
- RuleFor(command => command.PlayRecordId)
- .Must(playRecordId => Guid.TryParse(playRecordId, out Guid parsedPlayRecordId) && parsedPlayRecordId != Guid.Empty)
- .When(command => command.PlayRecordId is not null && command.PlayRecordId.Length > 0)
- .WithError(Errors.MusicPlayHistory.PlayRecordIdCannotBeEmpty);
-
- RuleFor(command => command.PositionInSeconds)
- .NotNull()
- .WithError(Errors.MusicPlayHistory.PlaybackPositionCannotBeNull);
-
- RuleFor(command => command.PositionInSeconds)
- .Must(position => position is null || (double.IsFinite(position.Value) && position.Value >= 0))
- .WithError(Errors.MusicPlayHistory.PlaybackPositionMustBeNonNegative);
-
- RuleFor(command => command.PositionInSeconds)
- .Must(position => position is null || position.Value <= TimeSpan.MaxValue.TotalSeconds)
- .WithError(Errors.MusicPlayHistory.PlaybackPositionIsOutOfRange);
-
- RuleFor(command => command.ListenedDurationInSeconds)
- .NotNull()
- .WithError(Errors.MusicPlayHistory.ListenedDurationCannotBeNull);
-
- RuleFor(command => command.ListenedDurationInSeconds)
- .Must(listenedDuration => listenedDuration is null || (double.IsFinite(listenedDuration.Value) && listenedDuration.Value >= 0))
- .WithError(Errors.MusicPlayHistory.ListenedDurationMustBeNonNegative);
-
- RuleFor(command => command.ListenedDurationInSeconds)
- .Must(listenedDuration => listenedDuration is null || listenedDuration.Value <= TimeSpan.MaxValue.TotalSeconds)
- .WithError(Errors.MusicPlayHistory.ListenedDurationIsOutOfRange);
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommand.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommand.cs
deleted file mode 100644
index a35ed4a6..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommand.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StartPlay;
-
-///
-/// Command for recording the start of a play of a track by the current user.
-///
-/// The unique identifier of the media library that contains the track, taken from the route.
-/// The unique identifier of the artist that produced the track, taken from the route.
-/// The unique identifier of the album that contains the track, taken from the route.
-/// The unique identifier of the track that started playing, taken from the route.
-[DebuggerDisplay("TrackId: {TrackId}")]
-public record StartPlayCommand(
- string? LibraryId,
- string? ArtistId,
- string? AlbumId,
- string? TrackId
-) : ICommand;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommandHandler.cs
deleted file mode 100644
index 62a3f893..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommandHandler.cs
+++ /dev/null
@@ -1,148 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Lumina.Application.Common.DataAccess.UoW;
-using Lumina.Application.Common.DomainEvents;
-using Lumina.Application.Common.Infrastructure.Authentication;
-using Lumina.Application.Common.Infrastructure.Authorization;
-using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
-using Lumina.Application.Common.Infrastructure.Validation;
-using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Domain.Common.Events;
-using Lumina.Domain.Common.Primitives;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.AudioLibraryBoundedContext.MusicLibraryAggregate;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate;
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
-using DomainErrors = Lumina.Domain.Common.Errors.Errors;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StartPlay;
-
-///
-/// Handler for the command to record the start of a play of a track by the current user.
-///
-public class StartPlayCommandHandler : ICommandHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly ICurrentUserService _currentUserService;
- private readonly IAuthorizationService _authorizationService;
- private readonly IDomainEventsQueue _domainEventsQueue;
- private readonly IValidator _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected service to retrieve the current user information.
- /// Injected service for authorization related functionality.
- /// Injected service for the queue of domain events.
- /// Injected validator for application validation rules.
- public StartPlayCommandHandler(
- IUnitOfWork unitOfWork,
- ICurrentUserService currentUserService,
- IAuthorizationService authorizationService,
- IDomainEventsQueue domainEventsQueue,
- IValidator validator)
- {
- _unitOfWork = unitOfWork;
- _currentUserService = currentUserService;
- _authorizationService = authorizationService;
- _domainEventsQueue = domainEventsQueue;
- _validator = validator;
- }
-
- ///
- /// Handles the command to record the start of a play of a track by the current user.
- ///
- /// The command to be handled.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An containing either the created , or an error message.
- ///
- public async Task> HandleAsync(StartPlayCommand command, CancellationToken cancellationToken)
- {
- List validationResult = _validator.Validate(command);
- if (validationResult.Count > 0)
- return validationResult;
-
- // An authenticated request must always carry a user identity.
- Guid? currentUserId = _currentUserService.UserId;
- if (currentUserId is null)
- return ApplicationErrors.Authorization.NotAuthorized;
- Guid userId = currentUserId.Value;
-
- // The validator guarantees that the route identifiers are non-empty Guids before this point.
- Guid libraryId = Guid.Parse(command.LibraryId!);
- Guid artistId = Guid.Parse(command.ArtistId!);
- Guid albumId = Guid.Parse(command.AlbumId!);
- Guid trackId = Guid.Parse(command.TrackId!);
-
- // Admins can report plays of the tracks of all libraries; for everyone else, only the tracks of the libraries they own. Authorization
- // is evaluated before any album or track is read, so an unauthorized caller cannot tell whether the route's album or track exists.
- bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync(
- userId, new LibraryOwnershipPolicyContext(libraryId), cancellationToken).ConfigureAwait(false);
- if (!canAccessLibrary)
- return ApplicationErrors.Authorization.NotAuthorized;
-
- // The album is loaded first, so that the artist and the library named by the request are enforced before the track itself is read. This is
- // the same resource scoping the track read uses, so a play can never reference a track through another library, artist or album.
- Result getAlbumResult = await _unitOfWork.AlbumRepository
- .GetByIdAsync(albumId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
- if (getAlbumResult.IsFailure)
- return getAlbumResult.Errors;
- if (getAlbumResult.Value is null)
- return DomainErrors.Music.AlbumNotFound;
- AlbumEntity existingAlbum = getAlbumResult.Value;
- if (existingAlbum.LibraryId != libraryId || existingAlbum.ArtistId != artistId)
- return DomainErrors.Music.AlbumNotFound;
-
- Result getTrackResult = await _unitOfWork.TrackRepository
- .GetByIdAsync(trackId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
- if (getTrackResult.IsFailure)
- return getTrackResult.Errors;
- if (getTrackResult.Value is null)
- return DomainErrors.Music.TrackNotFound;
- TrackEntity existingTrack = getTrackResult.Value;
- if (existingTrack.AlbumId != albumId || existingTrack.LibraryId != libraryId)
- return DomainErrors.Music.TrackNotFound;
-
- // Create the play record, which also raises the domain event announcing the start of the play.
- MusicPlayRecord playRecord = MusicPlayRecord.Create(
- UserId.Create(userId),
- TrackId.Create(trackId),
- LibraryId.Create(libraryId),
- AlbumId.Create(albumId),
- ArtistId.Create(artistId));
-
- Result insertResult = await _unitOfWork.MusicPlayRecordRepository
- .InsertAsync(playRecord.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
- if (insertResult.IsFailure)
- return insertResult.Errors;
-
- Result saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
- if (saveChangesResult.IsFailure)
- return saveChangesResult.Errors;
-
- // Queue any domain events, to be published after the request has completed successfully.
- foreach (IDomainEvent domainEvent in playRecord.GetDomainEvents())
- _domainEventsQueue.Enqueue(domainEvent);
-
- // Reading does not need the aggregate: the persisted row is read directly and mapped to the response, so the response carries the
- // timestamps the auditing interceptor actually stored instead of the in-memory aggregate's values.
- Result getPersistedPlayRecordResult = await _unitOfWork.MusicPlayRecordRepository
- .GetByIdForUserAsync(playRecord.Id.Value, userId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
- if (getPersistedPlayRecordResult.IsFailure)
- return getPersistedPlayRecordResult.Errors;
- if (getPersistedPlayRecordResult.Value is null)
- return DomainErrors.MusicPlayHistory.MusicPlayRecordNotFound;
-
- return getPersistedPlayRecordResult.Value.ToResponse();
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommandValidator.cs
deleted file mode 100644
index 6eb8b406..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommandValidator.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.Infrastructure.Validation;
-using Lumina.Application.Common.Utilities;
-using Lumina.Domain.Common.Errors;
-using System;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StartPlay;
-
-///
-/// Validates the needed validation rules for .
-///
-public class StartPlayCommandValidator : AbstractValidator
-{
- ///
- /// Initializes a new instance of the class.
- ///
- public StartPlayCommandValidator()
- {
- // Validates the identifier of the media library that contains the track, taken from the route.
- RuleFor(command => command.LibraryId)
- .NotEmpty()
- .WithError(Errors.Library.LibraryIdCannotBeEmpty);
-
- RuleFor(command => command.LibraryId)
- .Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
- .When(command => command.LibraryId is not null && command.LibraryId.Length > 0)
- .WithError(Errors.Library.LibraryIdCannotBeEmpty);
-
- // Validates the identifier of the artist that produced the track, taken from the route.
- RuleFor(command => command.ArtistId)
- .NotEmpty()
- .WithError(Errors.Music.ArtistIdCannotBeEmpty);
-
- RuleFor(command => command.ArtistId)
- .Must(artistId => Guid.TryParse(artistId, out Guid parsedArtistId) && parsedArtistId != Guid.Empty)
- .When(command => command.ArtistId is not null && command.ArtistId.Length > 0)
- .WithError(Errors.Music.ArtistIdCannotBeEmpty);
-
- // Validates the identifier of the album that contains the track, taken from the route.
- RuleFor(command => command.AlbumId)
- .NotEmpty()
- .WithError(Errors.Music.AlbumIdCannotBeEmpty);
-
- RuleFor(command => command.AlbumId)
- .Must(albumId => Guid.TryParse(albumId, out Guid parsedAlbumId) && parsedAlbumId != Guid.Empty)
- .When(command => command.AlbumId is not null && command.AlbumId.Length > 0)
- .WithError(Errors.Music.AlbumIdCannotBeEmpty);
-
- // Validates the identifier of the track that started playing, taken from the route.
- RuleFor(command => command.TrackId)
- .NotEmpty()
- .WithError(Errors.Music.TrackIdCannotBeEmpty);
-
- RuleFor(command => command.TrackId)
- .Must(trackId => Guid.TryParse(trackId, out Guid parsedTrackId) && parsedTrackId != Guid.Empty)
- .When(command => command.TrackId is not null && command.TrackId.Length > 0)
- .WithError(Errors.Music.TrackIdCannotBeEmpty);
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommand.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommand.cs
deleted file mode 100644
index 8beee312..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommand.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StopPlay;
-
-///
-/// Command for reporting that a play of a track by the current user stopped before the track completed.
-///
-/// The Id of the play record, taken from the route.
-/// The last position reported by the player, in seconds.
-/// The duration the user listened to, in seconds.
-[DebuggerDisplay("PlayRecordId: {PlayRecordId}; PositionInSeconds: {PositionInSeconds}")]
-public record StopPlayCommand(
- string? PlayRecordId,
- double? PositionInSeconds,
- double? ListenedDurationInSeconds
-) : ICommand;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommandHandler.cs
deleted file mode 100644
index c67b9c39..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommandHandler.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Lumina.Application.Common.DataAccess.UoW;
-using Lumina.Application.Common.DomainEvents;
-using Lumina.Application.Common.Infrastructure.Authentication;
-using Lumina.Application.Common.Infrastructure.Validation;
-using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Domain.Common.Events;
-using Lumina.Domain.Common.Primitives;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.ValueObjects;
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
-using DomainErrors = Lumina.Domain.Common.Errors.Errors;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StopPlay;
-
-///
-/// Handler for the command to report that a play of a track by the current user stopped before the track completed.
-///
-public class StopPlayCommandHandler : ICommandHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly ICurrentUserService _currentUserService;
- private readonly IDomainEventsQueue _domainEventsQueue;
- private readonly IValidator _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected service to retrieve the current user information.
- /// Injected service for the queue of domain events.
- /// Injected validator for application validation rules.
- public StopPlayCommandHandler(
- IUnitOfWork unitOfWork,
- ICurrentUserService currentUserService,
- IDomainEventsQueue domainEventsQueue,
- IValidator validator)
- {
- _unitOfWork = unitOfWork;
- _currentUserService = currentUserService;
- _domainEventsQueue = domainEventsQueue;
- _validator = validator;
- }
-
- ///
- /// Handles the command to report that a play of a track by the current user stopped before the track completed.
- ///
- /// The command to be handled.
- /// Cancellation token that can be used to stop the execution.
- /// An representing either a successful update, or an error message.
- public async Task> HandleAsync(StopPlayCommand command, CancellationToken cancellationToken)
- {
- List validationResult = _validator.Validate(command);
- if (validationResult.Count > 0)
- return validationResult;
-
- // An authenticated request must always carry a user identity.
- Guid? currentUserId = _currentUserService.UserId;
- if (currentUserId is null)
- return ApplicationErrors.Authorization.NotAuthorized;
- Guid userId = currentUserId.Value;
-
- // The validator guarantees that the route identifier and the reported times are valid before this point.
- Guid playRecordId = Guid.Parse(command.PlayRecordId!);
-
- // The record is loaded scoped to the current user, so a record of another user is indistinguishable from a missing one.
- Result getPlayRecordResult = await _unitOfWork.MusicPlayRecordRepository
- .GetByIdForUserAsync(playRecordId, userId, cancellationToken: cancellationToken).ConfigureAwait(false);
- if (getPlayRecordResult.IsFailure)
- return getPlayRecordResult.Errors;
- if (getPlayRecordResult.Value is null)
- return DomainErrors.MusicPlayHistory.MusicPlayRecordNotFound;
-
- Result toDomainEntityResult = getPlayRecordResult.Value.ToDomainEntity();
- if (toDomainEntityResult.IsFailure)
- return toDomainEntityResult.Errors;
- MusicPlayRecord playRecord = toDomainEntityResult.Value;
-
- Result stopResult = playRecord.Stop(
- MusicPlayPosition.Create(TimeSpan.FromSeconds(command.PositionInSeconds!.Value)),
- TimeSpan.FromSeconds(command.ListenedDurationInSeconds!.Value));
- if (stopResult.IsFailure)
- return stopResult.Errors;
-
- Result updateResult = await _unitOfWork.MusicPlayRecordRepository
- .UpdateForUserAsync(playRecord.ToRepositoryEntity(), userId, cancellationToken).ConfigureAwait(false);
- if (updateResult.IsFailure)
- return updateResult.Errors;
-
- Result saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
- if (saveChangesResult.IsFailure)
- return saveChangesResult.Errors;
-
- // Queue any domain events, to be published after the request has completed successfully.
- foreach (IDomainEvent domainEvent in playRecord.GetDomainEvents())
- _domainEventsQueue.Enqueue(domainEvent);
-
- return Result.Updated;
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommandValidator.cs
deleted file mode 100644
index efb89a31..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommandValidator.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.Infrastructure.Validation;
-using Lumina.Application.Common.Utilities;
-using Lumina.Domain.Common.Errors;
-using System;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StopPlay;
-
-///
-/// Validates the needed validation rules for .
-///
-public class StopPlayCommandValidator : AbstractValidator
-{
- ///
- /// Initializes a new instance of the class.
- ///
- public StopPlayCommandValidator()
- {
- RuleFor(command => command.PlayRecordId)
- .NotEmpty()
- .WithError(Errors.MusicPlayHistory.PlayRecordIdCannotBeEmpty);
-
- RuleFor(command => command.PlayRecordId)
- .Must(playRecordId => Guid.TryParse(playRecordId, out Guid parsedPlayRecordId) && parsedPlayRecordId != Guid.Empty)
- .When(command => command.PlayRecordId is not null && command.PlayRecordId.Length > 0)
- .WithError(Errors.MusicPlayHistory.PlayRecordIdCannotBeEmpty);
-
- RuleFor(command => command.PositionInSeconds)
- .NotNull()
- .WithError(Errors.MusicPlayHistory.PlaybackPositionCannotBeNull);
-
- RuleFor(command => command.PositionInSeconds)
- .Must(position => position is null || (double.IsFinite(position.Value) && position.Value >= 0))
- .WithError(Errors.MusicPlayHistory.PlaybackPositionMustBeNonNegative);
-
- RuleFor(command => command.PositionInSeconds)
- .Must(position => position is null || position.Value <= TimeSpan.MaxValue.TotalSeconds)
- .WithError(Errors.MusicPlayHistory.PlaybackPositionIsOutOfRange);
-
- RuleFor(command => command.ListenedDurationInSeconds)
- .NotNull()
- .WithError(Errors.MusicPlayHistory.ListenedDurationCannotBeNull);
-
- RuleFor(command => command.ListenedDurationInSeconds)
- .Must(listenedDuration => listenedDuration is null || (double.IsFinite(listenedDuration.Value) && listenedDuration.Value >= 0))
- .WithError(Errors.MusicPlayHistory.ListenedDurationMustBeNonNegative);
-
- RuleFor(command => command.ListenedDurationInSeconds)
- .Must(listenedDuration => listenedDuration is null || listenedDuration.Value <= TimeSpan.MaxValue.TotalSeconds)
- .WithError(Errors.MusicPlayHistory.ListenedDurationIsOutOfRange);
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMostPlayed/GetMostPlayedQuery.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMostPlayed/GetMostPlayedQuery.cs
deleted file mode 100644
index 75ce8a99..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMostPlayed/GetMostPlayedQuery.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using Lumina.Application.Common.DTO.Pagination;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetMostPlayed;
-
-///
-/// Query for getting the most played tracks of the current user, from the most played.
-///
-/// The object containing the requested pagination data, or to return every matching track.
-[DebuggerDisplay("PaginationData: {PaginationData}")]
-public record GetMostPlayedQuery(
- PaginationDataDto? PaginationData
-) : IQuery;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMostPlayed/GetMostPlayedQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMostPlayed/GetMostPlayedQueryHandler.cs
deleted file mode 100644
index 0ae316a6..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMostPlayed/GetMostPlayedQueryHandler.cs
+++ /dev/null
@@ -1,256 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Lumina.Application.Common.DataAccess.UoW;
-using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Application.Common.DTO.Pagination;
-using Lumina.Application.Common.Infrastructure.Authentication;
-using Lumina.Application.Common.Infrastructure.Authorization;
-using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
-using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Application.Common.Utilities;
-using Lumina.Contracts.Responses.Common;
-using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Domain.Common.Primitives;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate;
-using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
-using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
-using Lumina.Domain.SharedKernel.Common.Enums.Playback;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetMostPlayed;
-
-///
-/// Handler for the query to get the most played tracks of the current user.
-///
-public class GetMostPlayedQueryHandler : IQueryHandler>>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly ICurrentUserService _currentUserService;
- private readonly IAuthorizationService _authorizationService;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected service to retrieve the current user information.
- /// Injected service for authorization related functionality.
- public GetMostPlayedQueryHandler(IUnitOfWork unitOfWork, ICurrentUserService currentUserService, IAuthorizationService authorizationService)
- {
- _unitOfWork = unitOfWork;
- _currentUserService = currentUserService;
- _authorizationService = authorizationService;
- }
-
- ///
- /// Handles the query to get the most played tracks of the current user.
- ///
- /// The query to be handled.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An containing either the requested page of most played tracks, or an error message.
- ///
- public async Task>> HandleAsync(GetMostPlayedQuery query, CancellationToken cancellationToken)
- {
- // An authenticated request must always carry a user identity.
- Guid? currentUserId = _currentUserService.UserId;
- if (currentUserId is null)
- return ApplicationErrors.Authorization.NotAuthorized;
- Guid userId = currentUserId.Value;
-
- Result> getRecordsResult = await _unitOfWork.MusicPlayRecordRepository.GetForUserAsync(userId, cancellationToken).ConfigureAwait(false);
- if (getRecordsResult.IsFailure)
- return getRecordsResult.Errors;
-
- // Only the plays that count as plays are aggregated. The last activity of a track is the end of its most recent play, or the last
- // progress update while that play is still in progress.
- List aggregates = [.. getRecordsResult.Value
- .Where(record => MusicPlayRecord.DoesCountAsPlay(record.Status, record.ListenedDurationMilliseconds.ToClampedTimeSpan()))
- .GroupBy(record => new { record.TrackId, record.LibraryId, record.AlbumId, record.ArtistId })
- .Select(group => new PlayedTrackAggregate(
- group.Key.TrackId,
- group.Key.LibraryId,
- group.Key.AlbumId,
- group.Key.ArtistId,
- group.Max(record => record.EndedOnUtc ?? record.UpdatedOnUtc ?? record.CreatedOnUtc),
- group.Count(),
- group.Count(record => record.Status == PlaybackRecordStatus.Completed),
- group.Sum(record => record.ListenedDurationMilliseconds)))
- .OrderByDescending(aggregate => aggregate.PlayCount)
- .ThenByDescending(aggregate => aggregate.ListenedDurationMilliseconds)
- .ThenByDescending(aggregate => aggregate.LastActivityOnUtc)
- .ThenBy(aggregate => aggregate.TrackId)];
-
- return await ToResponsePageAsync(aggregates, query.PaginationData, userId, cancellationToken).ConfigureAwait(false);
- }
-
- ///
- /// Pages the aggregated tracks, resolves their display data, and converts them to the response of the query.
- ///
- /// The aggregated tracks, already ordered for this query.
- /// The requested pagination data, or for every matching track.
- /// The Id of the user whose tracks are retrieved.
- /// Cancellation token that can be used to stop the execution.
- /// An containing either the requested page of played tracks, or an error.
- private async Task>> ToResponsePageAsync(
- List aggregates, PaginationDataDto? paginationData, Guid userId, CancellationToken cancellationToken)
- {
- PaginatedResultDto page = Paginate(aggregates, paginationData);
- Result> getDtosResult = await ToPlayedTrackDtosAsync(page.Data, userId, cancellationToken).ConfigureAwait(false);
- if (getDtosResult.IsFailure)
- return getDtosResult.Errors;
-
- return Result.From(new PaginatedResultDto
- {
- Data = getDtosResult.Value,
- CurrentPage = page.CurrentPage,
- PerPage = page.PerPage,
- Count = page.Count,
- NumberOfPages = page.NumberOfPages
- }.ToResponses());
- }
-
- ///
- /// Applies the requested pagination to the ordered aggregated tracks.
- ///
- /// The ordered aggregated tracks.
- /// The requested pagination data, or for every matching track.
- /// The requested page of aggregated tracks.
- private static PaginatedResultDto Paginate(List aggregates, PaginationDataDto? paginationData)
- {
- if (paginationData is null)
- return new PaginatedResultDto
- {
- Data = aggregates,
- CurrentPage = 1,
- PerPage = aggregates.Count,
- Count = aggregates.Count,
- NumberOfPages = 1
- };
-
- int count = aggregates.Count;
- int numberOfPages = (int)Math.Ceiling((double)count / paginationData.PerPage);
- int currentPage = Math.Min(paginationData.CurrentPage, Math.Max(1, numberOfPages));
- List page = [.. aggregates
- .Skip((currentPage - 1) * paginationData.PerPage)
- .Take(paginationData.PerPage)];
- return new PaginatedResultDto
- {
- Data = page,
- CurrentPage = currentPage,
- PerPage = paginationData.PerPage,
- Count = count,
- NumberOfPages = numberOfPages
- };
- }
-
- ///
- /// Resolves the display data of the tracks of for the libraries the user can access, and builds their DTOs.
- ///
- /// The aggregated tracks of the requested page.
- /// The Id of the user whose tracks are retrieved.
- /// Cancellation token that can be used to stop the execution.
- /// An containing either the played tracks, with blank display data for missing or inaccessible tracks, or an error.
- private async Task>> ToPlayedTrackDtosAsync(IReadOnlyList aggregates, Guid userId, CancellationToken cancellationToken)
- {
- if (aggregates.Count == 0)
- return new List();
-
- // The access decision only needs the library Id that the play record already carries, so it is made once per distinct library before any
- // track or artwork is loaded. Display data from a library the user cannot access is never read.
- Dictionary libraryAccess = [];
- foreach (Guid libraryId in aggregates.Select(aggregate => aggregate.LibraryId).Distinct())
- libraryAccess[libraryId] = await _authorizationService.EvaluatePolicyAsync(
- userId, new LibraryOwnershipPolicyContext(libraryId), cancellationToken).ConfigureAwait(false);
-
- List accessibleTrackIds = [.. aggregates
- .Where(aggregate => libraryAccess[aggregate.LibraryId])
- .Select(aggregate => aggregate.TrackId)
- .Distinct()];
- Dictionary tracks = [];
- if (accessibleTrackIds.Count > 0)
- {
- Result> getTracksResult = await _unitOfWork.TrackRepository.GetByIdsAsync(accessibleTrackIds, shouldIncludeNavigationProperties: true, cancellationToken).ConfigureAwait(false);
- if (getTracksResult.IsFailure)
- return getTracksResult.Errors;
- tracks = getTracksResult.Value.ToDictionary(track => track.Id);
- }
-
- List albumIds = [.. tracks.Values.Select(track => track.AlbumId).Distinct()];
- Dictionary albumCovers = [];
- if (albumIds.Count > 0)
- {
- Result> getArtworkResult = await _unitOfWork.MusicArtworkRepository.GetByOwnersAsync(MusicArtworkOwnerType.Album, albumIds, cancellationToken).ConfigureAwait(false);
- if (getArtworkResult.IsFailure)
- return getArtworkResult.Errors;
- albumCovers = getArtworkResult.Value
- .Where(artwork => artwork.ArtworkType == ArtworkType.Cover)
- .GroupBy(artwork => artwork.OwnerId)
- .ToDictionary(
- group => group.Key,
- group => group.OrderBy(artwork => artwork.Ordinal).Select(artwork => artwork.FileName).FirstOrDefault());
- }
-
- List playedTracks = [];
- foreach (PlayedTrackAggregate aggregate in aggregates)
- {
- if (libraryAccess[aggregate.LibraryId] && tracks.TryGetValue(aggregate.TrackId, out TrackEntity? foundTrack) && foundTrack.LibraryId == aggregate.LibraryId)
- playedTracks.Add(new PlayedTrackDto(
- aggregate.TrackId,
- aggregate.LibraryId,
- aggregate.AlbumId,
- aggregate.ArtistId,
- foundTrack.Title,
- foundTrack.Album?.Title,
- foundTrack.Album?.Artist?.Name,
- albumCovers.TryGetValue(foundTrack.AlbumId, out string? coverFileName) ? coverFileName : null,
- aggregate.LastActivityOnUtc,
- aggregate.PlayCount,
- aggregate.CompletedPlayCount,
- aggregate.ListenedDurationMilliseconds));
- else // Keep the row so the play counts stay accurate, but blank the display data of a missing or inaccessible track.
- playedTracks.Add(new PlayedTrackDto(
- aggregate.TrackId,
- aggregate.LibraryId,
- aggregate.AlbumId,
- aggregate.ArtistId,
- null,
- null,
- null,
- null,
- aggregate.LastActivityOnUtc,
- aggregate.PlayCount,
- aggregate.CompletedPlayCount,
- aggregate.ListenedDurationMilliseconds));
- }
- return playedTracks;
- }
-
- ///
- /// The aggregated counted plays of one track in one library.
- ///
- /// The Id of the track.
- /// The Id of the media library that contains the track.
- /// The Id of the album that contains the track.
- /// The Id of the artist that produced the track.
- /// The date and time of the last recorded activity of the track's most recent play.
- /// The number of plays of the track that count as plays.
- /// The number of plays of the track that completed.
- /// The duration the user listened to the track, over all of its counted plays, in milliseconds.
- private sealed record PlayedTrackAggregate(
- Guid TrackId,
- Guid LibraryId,
- Guid AlbumId,
- Guid ArtistId,
- DateTime LastActivityOnUtc,
- int PlayCount,
- int CompletedPlayCount,
- long ListenedDurationMilliseconds
- );
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMusicPlayStatistics/GetMusicPlayStatisticsQuery.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMusicPlayStatistics/GetMusicPlayStatisticsQuery.cs
deleted file mode 100644
index d5e6f1b5..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMusicPlayStatistics/GetMusicPlayStatisticsQuery.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetMusicPlayStatistics;
-
-///
-/// Query for getting the listening statistics of the current user.
-///
-[DebuggerDisplay("Music play statistics")]
-public record GetMusicPlayStatisticsQuery() : IQuery;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMusicPlayStatistics/GetMusicPlayStatisticsQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMusicPlayStatistics/GetMusicPlayStatisticsQueryHandler.cs
deleted file mode 100644
index dc27a4e9..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMusicPlayStatistics/GetMusicPlayStatisticsQueryHandler.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Lumina.Application.Common.DataAccess.UoW;
-using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Application.Common.Infrastructure.Authentication;
-using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Application.Common.Utilities;
-using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Domain.Common.Primitives;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate;
-using Lumina.Domain.SharedKernel.Common.Enums.Playback;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetMusicPlayStatistics;
-
-///
-/// Handler for the query to get the listening statistics of the current user.
-///
-public class GetMusicPlayStatisticsQueryHandler : IQueryHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly ICurrentUserService _currentUserService;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected service to retrieve the current user information.
- public GetMusicPlayStatisticsQueryHandler(IUnitOfWork unitOfWork, ICurrentUserService currentUserService)
- {
- _unitOfWork = unitOfWork;
- _currentUserService = currentUserService;
- }
-
- ///
- /// Handles the query to get the listening statistics of the current user.
- ///
- /// The query to be handled.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An containing either the listening statistics of the current user, or an error message.
- ///
- public async Task> HandleAsync(GetMusicPlayStatisticsQuery query, CancellationToken cancellationToken)
- {
- // An authenticated request must always carry a user identity.
- Guid? currentUserId = _currentUserService.UserId;
- if (currentUserId is null)
- return ApplicationErrors.Authorization.NotAuthorized;
- Guid userId = currentUserId.Value;
-
- Result> getRecordsResult = await _unitOfWork.MusicPlayRecordRepository.GetForUserAsync(userId, cancellationToken).ConfigureAwait(false);
- if (getRecordsResult.IsFailure)
- return getRecordsResult.Errors;
-
- IReadOnlyList records = getRecordsResult.Value;
- // The total listening time includes the listened duration of every recorded play, including the plays that do not count.
- long totalListeningDurationMilliseconds = records.Sum(record => record.ListenedDurationMilliseconds);
- // A play counts when it completed or when it reached the threshold. An in-progress play that already reached the threshold is counted,
- // so the counted total need not equal the completed and stopped plays together.
- int totalPlayCount = records.Count(record => MusicPlayRecord.DoesCountAsPlay(record.Status, record.ListenedDurationMilliseconds.ToClampedTimeSpan()));
- int completedPlayCount = records.Count(record => record.Status == PlaybackRecordStatus.Completed);
- int stoppedPlayCount = records.Count(record => record.Status == PlaybackRecordStatus.Stopped && MusicPlayRecord.DoesCountAsPlay(record.Status, record.ListenedDurationMilliseconds.ToClampedTimeSpan()));
- double completionRate = totalPlayCount == 0 ? 0 : (double)completedPlayCount / totalPlayCount;
-
- return new MusicPlayStatisticsDto(
- totalListeningDurationMilliseconds,
- totalPlayCount,
- completedPlayCount,
- stoppedPlayCount,
- completionRate).ToResponse();
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQuery.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQuery.cs
deleted file mode 100644
index 45ad17f4..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQuery.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetPlayRecord;
-
-///
-/// Query for getting a recorded play of a track by the current user.
-///
-/// The Id of the play record, taken from the route.
-[DebuggerDisplay("PlayRecordId: {PlayRecordId}")]
-public record GetPlayRecordQuery(
- string? PlayRecordId
-) : IQuery;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQueryHandler.cs
deleted file mode 100644
index 3ca8ce9a..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQueryHandler.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Lumina.Application.Common.DataAccess.UoW;
-using Lumina.Application.Common.Infrastructure.Authentication;
-using Lumina.Application.Common.Infrastructure.Validation;
-using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Domain.Common.Primitives;
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
-using DomainErrors = Lumina.Domain.Common.Errors.Errors;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetPlayRecord;
-
-///
-/// Handler for the query to get a recorded play of a track by the current user.
-///
-public class GetPlayRecordQueryHandler : IQueryHandler>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly ICurrentUserService _currentUserService;
- private readonly IValidator _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected service to retrieve the current user information.
- /// Injected validator for application validation rules.
- public GetPlayRecordQueryHandler(
- IUnitOfWork unitOfWork,
- ICurrentUserService currentUserService,
- IValidator validator)
- {
- _unitOfWork = unitOfWork;
- _currentUserService = currentUserService;
- _validator = validator;
- }
-
- ///
- /// Handles the query to get a recorded play of a track by the current user.
- ///
- /// The query to be handled.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An containing either the requested , or an error message.
- ///
- public async Task> HandleAsync(GetPlayRecordQuery query, CancellationToken cancellationToken)
- {
- List validationResult = _validator.Validate(query);
- if (validationResult.Count > 0)
- return validationResult;
-
- // An authenticated request must always carry a user identity.
- Guid? currentUserId = _currentUserService.UserId;
- if (currentUserId is null)
- return ApplicationErrors.Authorization.NotAuthorized;
- Guid userId = currentUserId.Value;
-
- // The validator guarantees that the route identifier is a non-empty Guid before this point.
- Guid playRecordId = Guid.Parse(query.PlayRecordId!);
-
- // The record is read without tracking and scoped to the current user, so a record of another user is indistinguishable from a missing one.
- Result getPlayRecordResult = await _unitOfWork.MusicPlayRecordRepository
- .GetByIdForUserAsync(playRecordId, userId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
- if (getPlayRecordResult.IsFailure)
- return getPlayRecordResult.Errors;
- if (getPlayRecordResult.Value is null)
- return DomainErrors.MusicPlayHistory.MusicPlayRecordNotFound;
-
- return getPlayRecordResult.Value.ToResponse();
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQueryValidator.cs
deleted file mode 100644
index 1c927f0b..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQueryValidator.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.Infrastructure.Validation;
-using Lumina.Application.Common.Utilities;
-using Lumina.Domain.Common.Errors;
-using System;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetPlayRecord;
-
-///
-/// Validates the needed validation rules for .
-///
-public class GetPlayRecordQueryValidator : AbstractValidator
-{
- ///
- /// Initializes a new instance of the class.
- ///
- public GetPlayRecordQueryValidator()
- {
- RuleFor(query => query.PlayRecordId)
- .NotEmpty()
- .WithError(Errors.MusicPlayHistory.PlayRecordIdCannotBeEmpty);
-
- RuleFor(query => query.PlayRecordId)
- .Must(playRecordId => Guid.TryParse(playRecordId, out Guid parsedPlayRecordId) && parsedPlayRecordId != Guid.Empty)
- .When(query => query.PlayRecordId is not null && query.PlayRecordId.Length > 0)
- .WithError(Errors.MusicPlayHistory.PlayRecordIdCannotBeEmpty);
- }
-}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetRecentlyPlayed/GetRecentlyPlayedQuery.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetRecentlyPlayed/GetRecentlyPlayedQuery.cs
deleted file mode 100644
index 79ce53ae..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetRecentlyPlayed/GetRecentlyPlayedQuery.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using Lumina.Application.Common.DTO.Pagination;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetRecentlyPlayed;
-
-///
-/// Query for getting the recently played tracks of the current user, from the most recently played.
-///
-/// The object containing the requested pagination data, or to return every matching track.
-[DebuggerDisplay("PaginationData: {PaginationData}")]
-public record GetRecentlyPlayedQuery(
- PaginationDataDto? PaginationData
-) : IQuery;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetRecentlyPlayed/GetRecentlyPlayedQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetRecentlyPlayed/GetRecentlyPlayedQueryHandler.cs
deleted file mode 100644
index c71a3a2b..00000000
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetRecentlyPlayed/GetRecentlyPlayedQueryHandler.cs
+++ /dev/null
@@ -1,254 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.CQRS;
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Lumina.Application.Common.DataAccess.UoW;
-using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Application.Common.DTO.Pagination;
-using Lumina.Application.Common.Infrastructure.Authentication;
-using Lumina.Application.Common.Infrastructure.Authorization;
-using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
-using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Application.Common.Utilities;
-using Lumina.Contracts.Responses.Common;
-using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-using Lumina.Domain.Common.Primitives;
-using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate;
-using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
-using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
-using Lumina.Domain.SharedKernel.Common.Enums.Playback;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
-#endregion
-
-namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetRecentlyPlayed;
-
-///
-/// Handler for the query to get the recently played tracks of the current user.
-///
-public class GetRecentlyPlayedQueryHandler : IQueryHandler>>
-{
- private readonly IUnitOfWork _unitOfWork;
- private readonly ICurrentUserService _currentUserService;
- private readonly IAuthorizationService _authorizationService;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Injected unit of work for interacting with the data access layer repositories.
- /// Injected service to retrieve the current user information.
- /// Injected service for authorization related functionality.
- public GetRecentlyPlayedQueryHandler(IUnitOfWork unitOfWork, ICurrentUserService currentUserService, IAuthorizationService authorizationService)
- {
- _unitOfWork = unitOfWork;
- _currentUserService = currentUserService;
- _authorizationService = authorizationService;
- }
-
- ///
- /// Handles the query to get the recently played tracks of the current user.
- ///
- /// The query to be handled.
- /// Cancellation token that can be used to stop the execution.
- ///
- /// An containing either the requested page of recently played tracks, or an error message.
- ///
- public async Task>> HandleAsync(GetRecentlyPlayedQuery query, CancellationToken cancellationToken)
- {
- // An authenticated request must always carry a user identity.
- Guid? currentUserId = _currentUserService.UserId;
- if (currentUserId is null)
- return ApplicationErrors.Authorization.NotAuthorized;
- Guid userId = currentUserId.Value;
-
- Result> getRecordsResult = await _unitOfWork.MusicPlayRecordRepository.GetForUserAsync(userId, cancellationToken).ConfigureAwait(false);
- if (getRecordsResult.IsFailure)
- return getRecordsResult.Errors;
-
- // Only the plays that count as plays are aggregated. The last activity of a track is the end of its most recent play, or the last
- // progress update while that play is still in progress.
- List aggregates = [.. getRecordsResult.Value
- .Where(record => MusicPlayRecord.DoesCountAsPlay(record.Status, record.ListenedDurationMilliseconds.ToClampedTimeSpan()))
- .GroupBy(record => new { record.TrackId, record.LibraryId, record.AlbumId, record.ArtistId })
- .Select(group => new PlayedTrackAggregate(
- group.Key.TrackId,
- group.Key.LibraryId,
- group.Key.AlbumId,
- group.Key.ArtistId,
- group.Max(record => record.EndedOnUtc ?? record.UpdatedOnUtc ?? record.CreatedOnUtc),
- group.Count(),
- group.Count(record => record.Status == PlaybackRecordStatus.Completed),
- group.Sum(record => record.ListenedDurationMilliseconds)))
- .OrderByDescending(aggregate => aggregate.LastActivityOnUtc)
- .ThenBy(aggregate => aggregate.TrackId)];
-
- return await ToResponsePageAsync(aggregates, query.PaginationData, userId, cancellationToken).ConfigureAwait(false);
- }
-
- ///
- /// Pages the aggregated tracks, resolves their display data, and converts them to the response of the query.
- ///
- /// The aggregated tracks, already ordered for this query.
- /// The requested pagination data, or for every matching track.
- /// The Id of the user whose tracks are retrieved.
- /// Cancellation token that can be used to stop the execution.
- /// An containing either the requested page of played tracks, or an error.
- private async Task>> ToResponsePageAsync(
- List aggregates, PaginationDataDto? paginationData, Guid userId, CancellationToken cancellationToken)
- {
- PaginatedResultDto page = Paginate(aggregates, paginationData);
- Result> getDtosResult = await ToPlayedTrackDtosAsync(page.Data, userId, cancellationToken).ConfigureAwait(false);
- if (getDtosResult.IsFailure)
- return getDtosResult.Errors;
-
- return Result.From(new PaginatedResultDto
- {
- Data = getDtosResult.Value,
- CurrentPage = page.CurrentPage,
- PerPage = page.PerPage,
- Count = page.Count,
- NumberOfPages = page.NumberOfPages
- }.ToResponses());
- }
-
- ///
- /// Applies the requested pagination to the ordered aggregated tracks.
- ///
- /// The ordered aggregated tracks.
- /// The requested pagination data, or for every matching track.
- /// The requested page of aggregated tracks.
- private static PaginatedResultDto Paginate(List aggregates, PaginationDataDto? paginationData)
- {
- if (paginationData is null)
- return new PaginatedResultDto
- {
- Data = aggregates,
- CurrentPage = 1,
- PerPage = aggregates.Count,
- Count = aggregates.Count,
- NumberOfPages = 1
- };
-
- int count = aggregates.Count;
- int numberOfPages = (int)Math.Ceiling((double)count / paginationData.PerPage);
- int currentPage = Math.Min(paginationData.CurrentPage, Math.Max(1, numberOfPages));
- List page = [.. aggregates
- .Skip((currentPage - 1) * paginationData.PerPage)
- .Take(paginationData.PerPage)];
- return new PaginatedResultDto
- {
- Data = page,
- CurrentPage = currentPage,
- PerPage = paginationData.PerPage,
- Count = count,
- NumberOfPages = numberOfPages
- };
- }
-
- ///
- /// Resolves the display data of the tracks of for the libraries the user can access, and builds their DTOs.
- ///
- /// The aggregated tracks of the requested page.
- /// The Id of the user whose tracks are retrieved.
- /// Cancellation token that can be used to stop the execution.
- /// An containing either the played tracks, with blank display data for missing or inaccessible tracks, or an error.
- private async Task>> ToPlayedTrackDtosAsync(IReadOnlyList aggregates, Guid userId, CancellationToken cancellationToken)
- {
- if (aggregates.Count == 0)
- return new List();
-
- // The access decision only needs the library Id that the play record already carries, so it is made once per distinct library before any
- // track or artwork is loaded. Display data from a library the user cannot access is never read.
- Dictionary libraryAccess = [];
- foreach (Guid libraryId in aggregates.Select(aggregate => aggregate.LibraryId).Distinct())
- libraryAccess[libraryId] = await _authorizationService.EvaluatePolicyAsync(
- userId, new LibraryOwnershipPolicyContext(libraryId), cancellationToken).ConfigureAwait(false);
-
- List accessibleTrackIds = [.. aggregates
- .Where(aggregate => libraryAccess[aggregate.LibraryId])
- .Select(aggregate => aggregate.TrackId)
- .Distinct()];
- Dictionary tracks = [];
- if (accessibleTrackIds.Count > 0)
- {
- Result> getTracksResult = await _unitOfWork.TrackRepository.GetByIdsAsync(accessibleTrackIds, shouldIncludeNavigationProperties: true, cancellationToken).ConfigureAwait(false);
- if (getTracksResult.IsFailure)
- return getTracksResult.Errors;
- tracks = getTracksResult.Value.ToDictionary(track => track.Id);
- }
-
- List albumIds = [.. tracks.Values.Select(track => track.AlbumId).Distinct()];
- Dictionary albumCovers = [];
- if (albumIds.Count > 0)
- {
- Result> getArtworkResult = await _unitOfWork.MusicArtworkRepository.GetByOwnersAsync(MusicArtworkOwnerType.Album, albumIds, cancellationToken).ConfigureAwait(false);
- if (getArtworkResult.IsFailure)
- return getArtworkResult.Errors;
- albumCovers = getArtworkResult.Value
- .Where(artwork => artwork.ArtworkType == ArtworkType.Cover)
- .GroupBy(artwork => artwork.OwnerId)
- .ToDictionary(
- group => group.Key,
- group => group.OrderBy(artwork => artwork.Ordinal).Select(artwork => artwork.FileName).FirstOrDefault());
- }
-
- List playedTracks = [];
- foreach (PlayedTrackAggregate aggregate in aggregates)
- {
- if (libraryAccess[aggregate.LibraryId] && tracks.TryGetValue(aggregate.TrackId, out TrackEntity? foundTrack) && foundTrack.LibraryId == aggregate.LibraryId)
- playedTracks.Add(new PlayedTrackDto(
- aggregate.TrackId,
- aggregate.LibraryId,
- aggregate.AlbumId,
- aggregate.ArtistId,
- foundTrack.Title,
- foundTrack.Album?.Title,
- foundTrack.Album?.Artist?.Name,
- albumCovers.TryGetValue(foundTrack.AlbumId, out string? coverFileName) ? coverFileName : null,
- aggregate.LastActivityOnUtc,
- aggregate.PlayCount,
- aggregate.CompletedPlayCount,
- aggregate.ListenedDurationMilliseconds));
- else // Keep the row so the play counts stay accurate, but blank the display data of a missing or inaccessible track.
- playedTracks.Add(new PlayedTrackDto(
- aggregate.TrackId,
- aggregate.LibraryId,
- aggregate.AlbumId,
- aggregate.ArtistId,
- null,
- null,
- null,
- null,
- aggregate.LastActivityOnUtc,
- aggregate.PlayCount,
- aggregate.CompletedPlayCount,
- aggregate.ListenedDurationMilliseconds));
- }
- return playedTracks;
- }
-
- ///
- /// The aggregated counted plays of one track in one library.
- ///
- /// The Id of the track.
- /// The Id of the media library that contains the track.
- /// The Id of the album that contains the track.
- /// The Id of the artist that produced the track.
- /// The date and time of the last recorded activity of the track's most recent play.
- /// The number of plays of the track that count as plays.
- /// The number of plays of the track that completed.
- /// The duration the user listened to the track, over all of its counted plays, in milliseconds.
- private sealed record PlayedTrackAggregate(
- Guid TrackId,
- Guid LibraryId,
- Guid AlbumId,
- Guid ArtistId,
- DateTime LastActivityOnUtc,
- int PlayCount,
- int CompletedPlayCount,
- long ListenedDurationMilliseconds
- );
-}
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/CompletePlayRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/CompletePlayRequest.cs
deleted file mode 100644
index 1913d14e..00000000
--- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/CompletePlayRequest.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Represents a request to report that a play of a track by the current user reached its end.
-///
-/// The last position reported by the player, in seconds. Required.
-/// The duration the user listened to, in seconds. Required.
-[DebuggerDisplay("PositionInSeconds: {PositionInSeconds}; ListenedDurationInSeconds: {ListenedDurationInSeconds}")]
-public sealed record CompletePlayRequest(
- double? PositionInSeconds,
- double? ListenedDurationInSeconds
-);
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayedRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayedRequest.cs
deleted file mode 100644
index 7c8effb6..00000000
--- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayedRequest.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Represents a request for getting a window of the most played tracks of the current user.
-///
-/// The one based page of tracks to return. Optional; defaults to 1 when a page size is provided.
-/// The number of tracks per page. Optional; defaults to 50 when a page is provided. When both pagination parameters are omitted, every matching track is returned.
-[DebuggerDisplay("CurrentPage: {CurrentPage}; PerPage: {PerPage}")]
-public record GetMostPlayedRequest(
- int? CurrentPage,
- int? PerPage
-);
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayedRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayedRequest.cs
deleted file mode 100644
index c1945e47..00000000
--- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayedRequest.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Represents a request for getting a window of the recently played tracks of the current user.
-///
-/// The one based page of tracks to return. Optional; defaults to 1 when a page size is provided.
-/// The number of tracks per page. Optional; defaults to 50 when a page is provided. When both pagination parameters are omitted, every matching track is returned.
-[DebuggerDisplay("CurrentPage: {CurrentPage}; PerPage: {PerPage}")]
-public record GetRecentlyPlayedRequest(
- int? CurrentPage,
- int? PerPage
-);
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgressRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgressRequest.cs
deleted file mode 100644
index 3bd8dba5..00000000
--- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgressRequest.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Represents a request to report the progress of a play of a track by the current user.
-///
-/// The last position reported by the player, in seconds. Required.
-/// The duration the user has listened to, in seconds. Required.
-[DebuggerDisplay("PositionInSeconds: {PositionInSeconds}; ListenedDurationInSeconds: {ListenedDurationInSeconds}")]
-public sealed record ReportPlayProgressRequest(
- double? PositionInSeconds,
- double? ListenedDurationInSeconds
-);
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/StopPlayRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/StopPlayRequest.cs
deleted file mode 100644
index 3a210238..00000000
--- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/StopPlayRequest.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Represents a request to report that a play of a track by the current user stopped before the track completed.
-///
-/// The last position reported by the player, in seconds. Required.
-/// The duration the user listened to, in seconds. Required.
-[DebuggerDisplay("PositionInSeconds: {PositionInSeconds}; ListenedDurationInSeconds: {ListenedDurationInSeconds}")]
-public sealed record StopPlayRequest(
- double? PositionInSeconds,
- double? ListenedDurationInSeconds
-);
diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsResponse.cs
deleted file mode 100644
index 3b11212e..00000000
--- a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsResponse.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Represents the listening statistics of the current user.
-///
-/// The total duration the user listened to, over every recorded play, in seconds.
-/// The number of recorded plays that count as plays. An in-progress play counts once it reaches the threshold, so this total can exceed the completed and stopped plays together.
-/// The number of recorded plays that completed.
-/// The number of recorded plays that stopped before the track completed and count as plays.
-/// The fraction of the plays that count as plays that completed, between 0 and 1, or 0 when there is no counted play.
-[DebuggerDisplay("TotalPlayCount: {TotalPlayCount}; CompletedPlayCount: {CompletedPlayCount}")]
-public sealed record MusicPlayStatisticsResponse(
- double TotalListeningDurationInSeconds,
- int TotalPlayCount,
- int CompletedPlayCount,
- int StoppedPlayCount,
- double CompletionRate
-);
diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayRecordResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayRecordResponse.cs
deleted file mode 100644
index 888972ad..00000000
--- a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayRecordResponse.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Domain.SharedKernel.Common.Enums.Playback;
-using System;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Represents a recorded play of a track by the current user.
-///
-/// The Id of the play record.
-/// The Id of the track that was played.
-/// The Id of the media library that contains the track.
-/// The Id of the album that contains the track.
-/// The Id of the artist that produced the track.
-/// The state of the recorded play.
-/// The last position reported by the player, in seconds.
-/// The duration the user has listened to, in seconds.
-/// The date and time when the play started.
-/// The date and time when the play completed or stopped, if it has ended.
-/// The date and time when the play record was last updated, if applicable.
-[DebuggerDisplay("Id: {Id}; TrackId: {TrackId}; Status: {Status}")]
-public sealed record PlayRecordResponse(
- Guid Id,
- Guid TrackId,
- Guid LibraryId,
- Guid AlbumId,
- Guid ArtistId,
- PlaybackRecordStatus Status,
- double LastPositionInSeconds,
- double ListenedDurationInSeconds,
- DateTime StartedOnUtc,
- DateTime? EndedOnUtc,
- DateTime? UpdatedOnUtc
-);
diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackResponse.cs
deleted file mode 100644
index 6de92848..00000000
--- a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackResponse.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using System;
-using System.Diagnostics;
-#endregion
-
-namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
-
-///
-/// Represents a track of the listening statistics of the current user, together with its aggregated play counts.
-///
-/// The Id of the track.
-/// The Id of the media library that contains the track.
-/// The Id of the album that contains the track.
-/// The Id of the artist that produced the track.
-/// The title of the track, if it still exists and the user can access its library.
-/// The title of the album that contains the track, if it still exists and the user can access its library.
-/// The name of the artist that produced the track, if it still exists and the user can access its library.
-/// The path of the cover art of the album, if available.
-/// The date and time of the last recorded activity of the track's most recent play.
-/// The number of plays of the track that count as plays.
-/// The number of plays of the track that completed.
-/// The duration the user listened to the track, over all of its counted plays, in seconds.
-[DebuggerDisplay("TrackId: {TrackId}; PlayCount: {PlayCount}")]
-public sealed record PlayedTrackResponse(
- Guid TrackId,
- Guid LibraryId,
- Guid AlbumId,
- Guid ArtistId,
- string? Title,
- string? AlbumTitle,
- string? ArtistName,
- string? CoverPath,
- DateTime LastPlayedOnUtc,
- int PlayCount,
- int CompletedPlayCount,
- double ListenedDurationInSeconds
-);
diff --git a/src/Lumina.DataAccess/Common/Configuration/MusicPlayRecordConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/MusicPlayRecordConfiguration.cs
deleted file mode 100644
index 84b0f809..00000000
--- a/src/Lumina.DataAccess/Common/Configuration/MusicPlayRecordConfiguration.cs
+++ /dev/null
@@ -1,95 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Metadata.Builders;
-#endregion
-
-namespace Lumina.DataAccess.Common.Configuration;
-
-///
-/// Configures the entity mapping for the entity.
-///
-public class MusicPlayRecordConfiguration : IEntityTypeConfiguration
-{
- ///
- /// Configures the entity.
- ///
- /// The builder to be used to configure the entity.
- public void Configure(EntityTypeBuilder builder)
- {
- builder.ToTable("MusicPlayRecords");
- builder.HasKey(playRecord => playRecord.Id);
- builder.Property(playRecord => playRecord.Id)
- .ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
- .HasColumnOrder(0);
-
- builder.Property(playRecord => playRecord.UserId)
- .IsRequired()
- .HasColumnOrder(1);
-
- builder.Property(playRecord => playRecord.TrackId)
- .IsRequired()
- .HasColumnOrder(2);
-
- builder.Property(playRecord => playRecord.LibraryId)
- .IsRequired()
- .HasColumnOrder(3);
-
- builder.Property(playRecord => playRecord.AlbumId)
- .IsRequired()
- .HasColumnOrder(4);
-
- builder.Property(playRecord => playRecord.ArtistId)
- .IsRequired()
- .HasColumnOrder(5);
-
- builder.Property(playRecord => playRecord.Status)
- .IsRequired()
- .HasConversion()
- .HasMaxLength(20)
- .HasColumnOrder(6);
-
- builder.Property(playRecord => playRecord.LastPositionMilliseconds)
- .IsRequired()
- .HasColumnOrder(7);
-
- builder.Property(playRecord => playRecord.ListenedDurationMilliseconds)
- .IsRequired()
- .HasColumnOrder(8);
-
- builder.Property(playRecord => playRecord.EndedOnUtc)
- .HasColumnOrder(9);
-
- // The version is the optimistic concurrency token: every update increments it, and an update whose loaded version no longer matches
- // the stored one affects no row and fails, instead of reverting a play that another report already completed or stopped.
- builder.Property(playRecord => playRecord.Version)
- .IsRequired()
- .IsConcurrencyToken()
- .HasColumnOrder(10);
-
- // Audit.
- builder.Property(playRecord => playRecord.CreatedOnUtc)
- .IsRequired()
- .HasColumnOrder(11);
-
- builder.Property(playRecord => playRecord.CreatedBy)
- .IsRequired()
- .HasColumnOrder(12);
-
- builder.Property(playRecord => playRecord.UpdatedOnUtc)
- .HasDefaultValue(null)
- .HasColumnOrder(13);
-
- builder.Property(playRecord => playRecord.UpdatedBy)
- .HasDefaultValue(null)
- .HasColumnOrder(14);
-
- // The referenced entities are kept by Id only, without foreign keys, so a play survives the deletion of the track it references and the
- // statistics of the listening history still count it.
- // Enables the chronological reads of the plays of a user, which the statistics are built from.
- builder.HasIndex(playRecord => new { playRecord.UserId, playRecord.CreatedOnUtc });
-
- // Enables the reads of the plays of a track, which the per track statistics are built from.
- builder.HasIndex(playRecord => playRecord.TrackId);
- }
-}
diff --git a/src/Lumina.DataAccess/Common/Migrations/20261026153835_DropsMusicPlayRecords.Designer.cs b/src/Lumina.DataAccess/Common/Migrations/20261026153835_DropsMusicPlayRecords.Designer.cs
new file mode 100644
index 00000000..ef818694
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Migrations/20261026153835_DropsMusicPlayRecords.Designer.cs
@@ -0,0 +1,3896 @@
+//
+using System;
+using Lumina.DataAccess.Core.UoW;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace Lumina.DataAccess.Common.Migrations
+{
+ [DbContext(typeof(LuminaDbContext))]
+ [Migration("20261026153835_DropsMusicPlayRecords")]
+ partial class DropsMusicPlayRecords
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "10.0.11");
+
+ modelBuilder.Entity("AlbumGenres", b =>
+ {
+ b.Property("AlbumId")
+ .HasColumnType("TEXT");
+
+ b.Property("GenreId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("AlbumId", "GenreId");
+
+ b.HasIndex("GenreId");
+
+ b.ToTable("AlbumGenres", (string)null);
+ });
+
+ modelBuilder.Entity("AlbumTags", b =>
+ {
+ b.Property("AlbumId")
+ .HasColumnType("TEXT");
+
+ b.Property("TagId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("AlbumId", "TagId");
+
+ b.HasIndex("TagId");
+
+ b.ToTable("AlbumTags", (string)null);
+ });
+
+ modelBuilder.Entity("ArtistGenres", b =>
+ {
+ b.Property("ArtistId")
+ .HasColumnType("TEXT");
+
+ b.Property("GenreId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("ArtistId", "GenreId");
+
+ b.HasIndex("GenreId");
+
+ b.ToTable("ArtistGenres", (string)null);
+ });
+
+ modelBuilder.Entity("ArtistTags", b =>
+ {
+ b.Property("ArtistId")
+ .HasColumnType("TEXT");
+
+ b.Property("TagId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("ArtistId", "TagId");
+
+ b.HasIndex("TagId");
+
+ b.ToTable("ArtistTags", (string)null);
+ });
+
+ modelBuilder.Entity("BookGenres", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("GenreId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "GenreId");
+
+ b.HasIndex("GenreId");
+
+ b.ToTable("BookGenres", (string)null);
+ });
+
+ modelBuilder.Entity("BookTags", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("TagId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "TagId");
+
+ b.HasIndex("TagId");
+
+ b.ToTable("BookTags", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("PermissionName")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.HasKey("Id");
+
+ b.ToTable("Permissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("RoleName")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.HasKey("Id");
+
+ b.ToTable("Roles", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b =>
+ {
+ b.Property("RoleId")
+ .HasColumnType("TEXT");
+
+ b.Property("PermissionId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("RoleId", "PermissionId");
+
+ b.HasIndex("PermissionId");
+
+ b.HasIndex("RoleId", "PermissionId")
+ .IsUnique();
+
+ b.ToTable("RolePermissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b =>
+ {
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.Property("PermissionId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("UserId", "PermissionId");
+
+ b.HasIndex("PermissionId");
+
+ b.HasIndex("UserId", "PermissionId")
+ .IsUnique();
+
+ b.ToTable("UserPermissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b =>
+ {
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("RoleId")
+ .HasColumnType("TEXT");
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("UserId");
+
+ b.HasIndex("RoleId");
+
+ b.HasIndex("UserId", "RoleId")
+ .IsUnique();
+
+ b.ToTable("UserRoles", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Genres", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Tags", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Favorites.FavoriteEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("MediaItemId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("MediaKind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UserId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId", "CreatedOnUtc");
+
+ b.HasIndex("UserId", "MediaKind", "CreatedOnUtc");
+
+ b.HasIndex("UserId", "MediaKind", "MediaItemId")
+ .IsUnique();
+
+ b.ToTable("Favorites", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaConsumption.MediaConsumptionRecordEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("ConsecutivePagesRead")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(0)
+ .HasColumnOrder(14);
+
+ b.Property("ConsumedDurationMilliseconds")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(9);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(17);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(16);
+
+ b.Property("EndedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("LastActivityOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("LastPositionKind")
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("LastPositionLocation")
+ .HasMaxLength(4096)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("LastPositionTimeOffsetMilliseconds")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(11);
+
+ b.Property("LastProgressFraction")
+ .HasColumnType("REAL")
+ .HasColumnOrder(13);
+
+ b.Property("LibraryId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("MediaItemId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("MediaKind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("StartedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("Status")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(19);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(18);
+
+ b.Property("UserId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("Version")
+ .IsConcurrencyToken()
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(15);
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId", "MediaKind", "StartedOnUtc");
+
+ b.HasIndex("UserId", "MediaKind", "MediaItemId", "LastActivityOnUtc");
+
+ b.ToTable("MediaConsumptionRecords", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaConsumption.MediaResumePointEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.Property("LastConsumedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("LastPositionKind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("LastPositionLocation")
+ .HasMaxLength(4096)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("LastPositionTimeOffsetMilliseconds")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(6);
+
+ b.Property("LastProgressFraction")
+ .HasColumnType("REAL")
+ .HasColumnOrder(8);
+
+ b.Property("LibraryId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("MediaItemId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("MediaKind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(14);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(13);
+
+ b.Property("UserId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("Version")
+ .IsConcurrencyToken()
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(10);
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId", "MediaKind", "MediaItemId")
+ .IsUnique();
+
+ b.ToTable("MediaResumePoints", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaContributors.MediaContributorEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("Biography")
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("DateOfBirth")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("DateOfDeath")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("DisplayName")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1)
+ .UseCollation("NOCASE");
+
+ b.Property("LegalName")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.HasKey("Id");
+
+ b.HasIndex("DisplayName")
+ .IsUnique();
+
+ b.ToTable("MediaContributors", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumContributorEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("AlbumId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("MediaContributorId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("Role")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.HasKey("Id");
+
+ b.HasIndex("MediaContributorId");
+
+ b.HasIndex("AlbumId", "MediaContributorId", "Role")
+ .IsUnique();
+
+ b.ToTable("AlbumContributors", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("ASIN")
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(28);
+
+ b.Property("ArtistId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("Barcode")
+ .HasMaxLength(13)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(25);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(33);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(32);
+
+ b.Property("Description")
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("Disambiguation")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("Label")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(27);
+
+ b.Property("LanguageCode")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(13);
+
+ b.Property("LanguageName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(14);
+
+ b.Property("LanguageNativeName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(15);
+
+ b.Property("LastMetadataUpdateUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(37);
+
+ b.Property("LibraryId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("MediaFormat")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(23);
+
+ b.Property("MetadataProvider")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(38);
+
+ b.Property("MetadataStatus")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasDefaultValue("Pending")
+ .HasColumnOrder(36);
+
+ b.Property("MusicBrainzReleaseArtistId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(31);
+
+ b.Property("MusicBrainzReleaseGroupId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(30);
+
+ b.Property("MusicBrainzReleaseId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(29);
+
+ b.Property("OriginalLanguageCode")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(16);
+
+ b.Property("OriginalLanguageName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(17);
+
+ b.Property("OriginalLanguageNativeName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(18);
+
+ b.Property("OriginalReleaseDate")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("OriginalReleaseYear")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(8);
+
+ b.Property("OriginalTitle")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("Packaging")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(24);
+
+ b.Property