From bc619679e8af53437d1aa4c46bcda092740f1027 Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Mon, 26 Oct 2026 18:06:04 +0200 Subject: [PATCH] Removes the old music play history surface and drops its table --- .../PlayHistory/MusicPlayStatisticsDto.cs | 22 - .../PlayHistory/PlayedTrackDto.cs | 37 - .../MusicLibrary/MusicPlayRecordEntity.cs | 93 - .../IMusicPlayRecordRepository.cs | 50 - .../Common/DataAccess/UoW/IUnitOfWork.cs | 5 - .../PlayHistory/CompletePlayRequestMapping.cs | 27 - .../GetMostPlayedRequestMapping.cs | 31 - .../GetRecentlyPlayedRequestMapping.cs | 31 - .../MusicPlayRecordEntityMapping.cs | 67 - .../PlayHistory/MusicPlayRecordMapping.cs | 43 - .../MusicPlayStatisticsDtoMapping.cs | 29 - .../PlayHistory/PlayedTrackDtoMapping.cs | 59 - .../ReportPlayProgressRequestMapping.cs | 27 - .../PlayHistory/StopPlayRequestMapping.cs | 27 - .../CompletePlay/CompletePlayCommand.cs | 19 - .../CompletePlayCommandHandler.cs | 107 - .../CompletePlayCommandValidator.cs | 53 - .../ReportPlayProgressCommand.cs | 19 - .../ReportPlayProgressCommandHandler.cs | 107 - .../ReportPlayProgressCommandValidator.cs | 53 - .../Commands/StartPlay/StartPlayCommand.cs | 21 - .../StartPlay/StartPlayCommandHandler.cs | 148 - .../StartPlay/StartPlayCommandValidator.cs | 60 - .../Commands/StopPlay/StopPlayCommand.cs | 19 - .../StopPlay/StopPlayCommandHandler.cs | 107 - .../StopPlay/StopPlayCommandValidator.cs | 53 - .../GetMostPlayed/GetMostPlayedQuery.cs | 16 - .../GetMostPlayedQueryHandler.cs | 256 -- .../GetMusicPlayStatisticsQuery.cs | 12 - .../GetMusicPlayStatisticsQueryHandler.cs | 79 - .../GetPlayRecord/GetPlayRecordQuery.cs | 15 - .../GetPlayRecordQueryHandler.cs | 78 - .../GetPlayRecordQueryValidator.cs | 29 - .../GetRecentlyPlayedQuery.cs | 16 - .../GetRecentlyPlayedQueryHandler.cs | 254 -- .../PlayHistory/CompletePlayRequest.cs | 16 - .../PlayHistory/GetMostPlayedRequest.cs | 16 - .../PlayHistory/GetRecentlyPlayedRequest.cs | 16 - .../PlayHistory/ReportPlayProgressRequest.cs | 16 - .../PlayHistory/StopPlayRequest.cs | 16 - .../MusicPlayStatisticsResponse.cs | 22 - .../PlayHistory/PlayRecordResponse.cs | 36 - .../PlayHistory/PlayedTrackResponse.cs | 37 - .../MusicPlayRecordConfiguration.cs | 95 - ...26153835_DropsMusicPlayRecords.Designer.cs | 3896 +++++++++++++++++ .../20261026153835_DropsMusicPlayRecords.cs | 57 + .../LuminaDbContextModelSnapshot.cs | 74 - .../MusicLibrary/MusicPlayRecordRepository.cs | 135 - .../Core/UoW/LuminaDbContext.cs | 1 - src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs | 13 - .../Enums/Playback/PlaybackRecordStatus.cs | 22 - .../Common/Errors/Errors.MusicPlayHistory.cs | 28 - .../MusicLibraryAggregate/AlbumId.cs | 51 - .../MusicLibraryAggregate/ArtistId.cs | 51 - .../MusicLibraryAggregate/TrackId.cs | 51 - .../LibraryAggregate/LibraryId.cs | 51 - .../UserAggregate/UserId.cs | 51 - .../Events/MusicPlayCompletedDomainEvent.cs | 31 - .../Events/MusicPlayProgressedDomainEvent.cs | 31 - .../Events/MusicPlayStartedDomainEvent.cs | 34 - .../Events/MusicPlayStoppedDomainEvent.cs | 31 - .../MusicPlayRecord.cs | 319 -- .../ValueObjects/MusicPlayPosition.cs | 51 - .../ValueObjects/MusicPlayRecordId.cs | 51 - .../MusicLibrary/ApiRoutes.PlayHistory.cs | 19 - .../MusicLibrary/ApiRoutes.PlayStatistics.cs | 17 - .../CompletePlay/CompletePlayEndpoint.cs | 58 - .../CompletePlayEndpointSummary.cs | 129 - .../GetMostPlayed/GetMostPlayedEndpoint.cs | 63 - .../GetMostPlayedEndpointSummary.cs | 116 - .../GetMusicPlayStatisticsEndpoint.cs | 60 - .../GetMusicPlayStatisticsEndpointSummary.cs | 80 - .../GetPlayRecord/GetPlayRecordEndpoint.cs | 62 - .../GetPlayRecordEndpointSummary.cs | 117 - .../GetRecentlyPlayedEndpoint.cs | 63 - .../GetRecentlyPlayedEndpointSummary.cs | 116 - .../ReportPlayProgressEndpoint.cs | 58 - .../ReportPlayProgressEndpointSummary.cs | 129 - .../StartPlay/StartPlayEndpoint.cs | 58 - .../StartPlay/StartPlayEndpointSummary.cs | 144 - .../PlayHistory/StopPlay/StopPlayEndpoint.cs | 58 - .../StopPlay/StopPlayEndpointSummary.cs | 129 - .../Core/UoW/LuminaDbContextTests.cs | 4 +- 83 files changed, 3955 insertions(+), 4893 deletions(-) delete mode 100644 src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsDto.cs delete mode 100644 src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackDto.cs delete mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicPlayRecordEntity.cs delete mode 100644 src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IMusicPlayRecordRepository.cs delete mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/CompletePlayRequestMapping.cs delete mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayedRequestMapping.cs delete mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayedRequestMapping.cs delete mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayRecordEntityMapping.cs delete mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayRecordMapping.cs delete mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsDtoMapping.cs delete mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackDtoMapping.cs delete mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgressRequestMapping.cs delete mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/StopPlayRequestMapping.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommand.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommandHandler.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/CompletePlay/CompletePlayCommandValidator.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommand.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommandHandler.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/ReportPlayProgress/ReportPlayProgressCommandValidator.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommand.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommandHandler.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StartPlay/StartPlayCommandValidator.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommand.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommandHandler.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Commands/StopPlay/StopPlayCommandValidator.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMostPlayed/GetMostPlayedQuery.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMostPlayed/GetMostPlayedQueryHandler.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMusicPlayStatistics/GetMusicPlayStatisticsQuery.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetMusicPlayStatistics/GetMusicPlayStatisticsQueryHandler.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQuery.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQueryHandler.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetPlayRecord/GetPlayRecordQueryValidator.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetRecentlyPlayed/GetRecentlyPlayedQuery.cs delete mode 100644 src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/Queries/GetRecentlyPlayed/GetRecentlyPlayedQueryHandler.cs delete mode 100644 src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/CompletePlayRequest.cs delete mode 100644 src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayedRequest.cs delete mode 100644 src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayedRequest.cs delete mode 100644 src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgressRequest.cs delete mode 100644 src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/StopPlayRequest.cs delete mode 100644 src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/MusicPlayStatisticsResponse.cs delete mode 100644 src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayRecordResponse.cs delete mode 100644 src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/PlayHistory/PlayedTrackResponse.cs delete mode 100644 src/Lumina.DataAccess/Common/Configuration/MusicPlayRecordConfiguration.cs create mode 100644 src/Lumina.DataAccess/Common/Migrations/20261026153835_DropsMusicPlayRecords.Designer.cs create mode 100644 src/Lumina.DataAccess/Common/Migrations/20261026153835_DropsMusicPlayRecords.cs delete mode 100644 src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicPlayRecordRepository.cs delete mode 100644 src/Lumina.Domain.SharedKernel/Common/Enums/Playback/PlaybackRecordStatus.cs delete mode 100644 src/Lumina.Domain/Common/Errors/Errors.MusicPlayHistory.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/AlbumId.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/ArtistId.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/TrackId.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayCompletedDomainEvent.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayProgressedDomainEvent.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayStartedDomainEvent.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayStoppedDomainEvent.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/MusicPlayRecord.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/ValueObjects/MusicPlayPosition.cs delete mode 100644 src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/ValueObjects/MusicPlayRecordId.cs delete mode 100644 src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.PlayHistory.cs delete mode 100644 src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.PlayStatistics.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/CompletePlay/CompletePlayEndpoint.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/CompletePlay/CompletePlayEndpointSummary.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayed/GetMostPlayedEndpoint.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayed/GetMostPlayedEndpointSummary.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMusicPlayStatistics/GetMusicPlayStatisticsEndpoint.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMusicPlayStatistics/GetMusicPlayStatisticsEndpointSummary.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetPlayRecord/GetPlayRecordEndpoint.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetPlayRecord/GetPlayRecordEndpointSummary.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayed/GetRecentlyPlayedEndpoint.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayed/GetRecentlyPlayedEndpointSummary.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgress/ReportPlayProgressEndpoint.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgress/ReportPlayProgressEndpointSummary.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StartPlay/StartPlayEndpoint.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StartPlay/StartPlayEndpointSummary.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StopPlay/StopPlayEndpoint.cs delete mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StopPlay/StopPlayEndpointSummary.cs 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("ReReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("ReReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("ReleaseCountry") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("ReleaseStatus") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(20); + + b.Property("ReleaseTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(26); + + b.Property("ReleaseVersion") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("Script") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("TotalDiscs") + .HasColumnType("INTEGER") + .HasColumnOrder(21); + + b.Property("TotalTracks") + .HasColumnType("INTEGER") + .HasColumnOrder(22); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(35); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(34); + + b.HasKey("Id"); + + b.HasIndex("ArtistId", "Title"); + + b.HasIndex("LibraryId", "Title"); + + b.ToTable("Albums", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtistId") + .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("ArtistId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("ArtistContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Country") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("Disambiguation") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("Gender") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("IsEnded") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("LifeSpanBegin") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("LifeSpanEnd") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(17); + + b.Property("MusicBrainzArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("SortName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Type") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("Website") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "Name") + .IsUnique(); + + b.ToTable("Artists", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicArtworkEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("FileName") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("LastUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Ordinal") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("OwnerId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("OwnerType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Provider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.HasIndex("OwnerType", "OwnerId", "ArtworkType", "Ordinal") + .IsUnique(); + + b.ToTable("MusicArtwork", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicLibraryScanItemMetadataEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("AcoustId") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(25); + + b.Property("ArtistName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("AudioCodec") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("BitDepth") + .HasColumnType("INTEGER") + .HasColumnOrder(14); + + b.Property("Bitrate") + .HasColumnType("INTEGER") + .HasColumnOrder(16); + + b.Property("Channels") + .HasColumnType("INTEGER") + .HasColumnOrder(13); + + b.Property("Container") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(31); + + b.Property("DiscNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("DurationInSeconds") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("LibraryScanId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.PrimitiveCollection("Moods") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(30); + + b.Property("MusicBrainzArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(17); + + b.Property("MusicBrainzRecordingId") + .HasColumnType("TEXT") + .HasColumnOrder(21); + + b.Property("MusicBrainzReleaseArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("MusicBrainzReleaseGroupId") + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("MusicBrainzReleaseId") + .HasColumnType("TEXT") + .HasColumnOrder(20); + + b.Property("MusicBrainzTrackId") + .HasColumnType("TEXT") + .HasColumnOrder(22); + + b.Property("MusicBrainzWorkId") + .HasColumnType("TEXT") + .HasColumnOrder(23); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ReleaseName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("ReleaseType") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("ReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("ReplayGainAlbumGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(28); + + b.Property("ReplayGainAlbumPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(29); + + b.Property("ReplayGainTrackGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(26); + + b.Property("ReplayGainTrackPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(27); + + b.Property("SampleRate") + .HasColumnType("INTEGER") + .HasColumnOrder(12); + + b.Property("TrackNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("TrackTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("WorkTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.HasKey("Id"); + + b.HasIndex("LibraryScanId", "Path") + .IsUnique(); + + b.ToTable("MusicLibraryScanItemMetadata", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + 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("TrackId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("MediaContributorId"); + + b.HasIndex("TrackId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("TrackContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("AcoustId") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(44); + + b.Property("AlbumId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("AudioCodec") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.Property("BitDepth") + .HasColumnType("INTEGER") + .HasColumnOrder(23); + + b.Property("Bitrate") + .HasColumnType("INTEGER") + .HasColumnOrder(25); + + b.Property("Bpm") + .HasColumnType("INTEGER") + .HasColumnOrder(30); + + b.Property("Channels") + .HasColumnType("INTEGER") + .HasColumnOrder(22); + + b.Property("Container") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(49); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(38); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(37); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("Disambiguation") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("DiscNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(27); + + b.Property("DurationInSeconds") + .HasColumnType("INTEGER") + .HasColumnOrder(20); + + b.Property("IsVideo") + .HasColumnType("INTEGER") + .HasColumnOrder(31); + + b.Property("Key") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(29); + + b.Property("LanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("LanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("LanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(42); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(43); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(41); + + b.Property("MusicBrainzRecordingId") + .HasColumnType("TEXT") + .HasColumnOrder(34); + + b.Property("MusicBrainzTrackId") + .HasColumnType("TEXT") + .HasColumnOrder(35); + + b.Property("MusicBrainzWorkId") + .HasColumnType("TEXT") + .HasColumnOrder(36); + + b.Property("OriginalLanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(17); + + b.Property("OriginalLanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("OriginalLanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("OriginalReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("OriginalReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("OriginalTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ReReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("ReReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("ReleaseCountry") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("ReleaseVersion") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("ReplayGainAlbumGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(47); + + b.Property("ReplayGainAlbumPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(48); + + b.Property("ReplayGainTrackGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(45); + + b.Property("ReplayGainTrackPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(46); + + b.Property("SampleRate") + .HasColumnType("INTEGER") + .HasColumnOrder(21); + + b.Property("Script") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(28); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("TrackNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(26); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(40); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(39); + + b.Property("WorkTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(32); + + b.Property("WorkType") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(33); + + b.HasKey("Id"); + + b.HasIndex("AlbumId", "TrackNumber"); + + b.HasIndex("LibraryId", "Path") + .IsUnique(); + + b.ToTable("Tracks", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.DirectoryScanFingerprintEntity", b => + { + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("LastWriteTimeUtc") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.HasKey("LibraryId", "Path"); + + b.HasIndex("LibraryId"); + + b.ToTable("DirectoryScanFingerprints", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkProvidersConfigurationFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("CanDownloadMetadataFromWeb") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(true) + .HasColumnOrder(6); + + b.Property("CompletionThresholdPercentage") + .HasColumnType("INTEGER") + .HasColumnOrder(17); + + b.Property("CoverImage") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("IsEnabled") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(true) + .HasColumnOrder(4); + + b.Property("IsLocked") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("LibraryType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("MetadataProvidersConfigurationFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("PathTemplateFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("ShouldSaveMetadataInMediaDirectories") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("ShouldSkipUnchangedDirectoriesDuringScan") + .HasColumnType("INTEGER") + .HasColumnOrder(8); + + b.Property("ShouldTrackConsumptionProgress") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(false) + .HasColumnOrder(16); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Libraries", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Status") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.HasIndex("LibraryId", "Status", "CreatedOnUtc") + .IsDescending(true, false, true); + + b.ToTable("LibraryScans", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanResultEntity", b => + { + b.Property("LibraryScanId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasMaxLength(24) + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("FileSize") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Status") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.HasKey("LibraryScanId", "Path"); + + b.HasIndex("Path"); + + b.HasIndex("ContentHash", "FileSize", "Path"); + + b.ToTable("LibraryScanResults", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanSnapshotEntity", b => + { + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("FileSize") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("LibraryId", "Path"); + + b.HasIndex("LibraryId"); + + b.ToTable("LibraryScanSnapshots", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanStagingResultsEntity", b => + { + b.Property("LibraryScanId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("IsNew") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("NeedsRehash") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("PreviousContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("Size") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.HasKey("LibraryScanId", "Path"); + + b.HasIndex("LibraryScanId", "NeedsRehash"); + + b.ToTable("LibraryScanStagingResults", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookArtworkEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("BookId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("FileName") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("LastUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Ordinal") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Provider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.HasIndex("BookId", "ArtworkType", "Ordinal") + .IsUnique(); + + b.ToTable("BookArtwork", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("BookId") + .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("BookId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("BookContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ASIN") + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(21); + + b.Property("AppleBooksId") + .HasColumnType("TEXT") + .HasColumnOrder(29); + + b.Property("BarnesAndNobleId") + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(28); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(33); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(32); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Edition") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("Format") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("GoodreadsId") + .HasColumnType("TEXT") + .HasColumnOrder(22); + + b.Property("GoogleBooksId") + .HasMaxLength(12) + .HasColumnType("TEXT") + .HasColumnOrder(27); + + b.Property("LCCN") + .HasColumnType("TEXT") + .HasColumnOrder(23); + + b.Property("LanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("LanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("LanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(39); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(36); + + b.Property("LibraryThingId") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(26); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(40); + + b.Property("MetadataStatus") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(38); + + b.Property("OCLCNumber") + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.Property("OpenLibraryId") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(25); + + b.Property("OriginalLanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("OriginalLanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("OriginalLanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("OriginalReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("OriginalReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("OriginalTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("PageCount") + .HasColumnType("INTEGER") + .HasColumnOrder(17); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(37); + + b.Property("Publisher") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("ReReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("ReReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("ReleaseCountry") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("ReleaseVersion") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(35); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(34); + + b.Property("VolumeNumber") + .HasColumnType("REAL") + .HasColumnOrder(20); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "MetadataStatus"); + + b.HasIndex("LibraryId", "Path") + .IsUnique(); + + b.ToTable("Books", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Playlists.PlaylistEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("EntryCount") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(0) + .HasColumnOrder(10); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Type") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(0L) + .HasColumnOrder(9); + + b.HasKey("Id"); + + b.HasIndex("UserId", "UpdatedOnUtc"); + + b.ToTable("Playlists", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Playlists.PlaylistEntryEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("MediaItemId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("MediaItemType") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("PlaylistId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Position") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("Id"); + + b.HasIndex("MediaItemId"); + + b.HasIndex("PlaylistId", "Position") + .IsUnique(); + + b.ToTable("PlaylistEntries", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryArtworkProviderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Rank") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId"); + + b.ToTable("LibraryArtworkProviderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryBookReaderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId") + .IsUnique(); + + b.ToTable("LibraryBookReaderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryMetadataProviderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Rank") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId"); + + b.ToTable("LibraryMetadataProviderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.PluginEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Author") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Description") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("LoadError") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("LoadStatus") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("SettingsJson") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("Version") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("Id"); + + b.ToTable("Plugins", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.ScheduledJobEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("Hour") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("IntervalMinutes") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("LastCompletedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("LastStartedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Minute") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("OwnerUserId") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("ScheduleType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Status") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("TaskType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.ToTable("ScheduledJobs", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.ScheduledJobExecutionEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CompletedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("IsCycleRun") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("ScheduledJobId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("StartedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("TaskType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("WasCycleActive") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("ScheduledJobId"); + + b.HasIndex("StartedOnUtc", "ScheduledJobId"); + + b.ToTable("ScheduledJobExecutions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.SchedulerDisplayPreferencesEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("DisplayTimeSpan") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("DisplayTimeUnit") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("JobTypeFilter") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("SchedulerDisplayPreferences", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Themes.ThemeEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Author") + .IsRequired() + .HasMaxLength(80) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("Description") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("InstallSource") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("InstalledAtUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("IsCurrent") + .HasColumnType("INTEGER") + .HasColumnOrder(8); + + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(false) + .HasColumnOrder(9); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("PreviewPath") + .HasMaxLength(240) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("ThemeId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("Version") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.HasKey("Id"); + + b.HasIndex("IsCurrent") + .IsUnique() + .HasFilter("IsCurrent = 1"); + + b.HasIndex("ThemeId") + .IsUnique(); + + b.ToTable("Themes", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("TempPassword") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("TempPasswordCreated") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("TotpSecret") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Username") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("Username") + .IsUnique(); + + b.ToTable("Users", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsGaplessPlaybackEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(16); + + b.Property("IsMuted") + .HasColumnType("INTEGER") + .HasColumnOrder(29); + + b.Property("IsPaginationEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("IsThemeCachingEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("ItemsPerPage") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("ReplayGainMode") + .HasColumnType("INTEGER") + .HasColumnOrder(17); + + b.Property("ShouldAggregateArtworkWhenMissing") + .HasColumnType("INTEGER") + .HasColumnOrder(13); + + b.Property("ShouldAggregateMetadataWhenMissing") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("ShouldAutoplay") + .HasColumnType("INTEGER") + .HasColumnOrder(15); + + b.Property("ShouldIgnoreThePrefixForAlphaPicker") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("ShouldKeepDownloadingWhilePaused") + .HasColumnType("INTEGER") + .HasColumnOrder(14); + + b.Property("ShouldPreserveBookStyles") + .HasColumnType("INTEGER") + .HasColumnOrder(12); + + b.Property("ShouldRenderPdfAsImages") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("StreamingQuality") + .HasColumnType("INTEGER") + .HasColumnOrder(18); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Volume") + .HasColumnType("REAL") + .HasColumnOrder(28); + + b.Property("VuMeterHighThreshold") + .HasColumnType("REAL") + .HasColumnOrder(23); + + b.Property("VuMeterMediumThreshold") + .HasColumnType("REAL") + .HasColumnOrder(22); + + b.Property("VuMeterOrientation") + .HasColumnType("INTEGER") + .HasColumnOrder(19); + + b.Property("VuMeterPeakHoldDurationInMilliseconds") + .HasColumnType("INTEGER") + .HasColumnOrder(25); + + b.Property("VuMeterPeakReleasePerSecond") + .HasColumnType("REAL") + .HasColumnOrder(27); + + b.Property("VuMeterReleasePerSecond") + .HasColumnType("REAL") + .HasColumnOrder(26); + + b.Property("VuMeterSegmentCount") + .HasColumnType("INTEGER") + .HasColumnOrder(20); + + b.Property("VuMeterSegmentGap") + .HasColumnType("INTEGER") + .HasColumnOrder(21); + + b.Property("VuMeterShowPeak") + .HasColumnType("INTEGER") + .HasColumnOrder(24); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("UserSettings", (string)null); + }); + + modelBuilder.Entity("TrackGenres", b => + { + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("TrackId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("TrackGenres", (string)null); + }); + + modelBuilder.Entity("TrackTags", b => + { + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("TrackId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("TrackTags", (string)null); + }); + + modelBuilder.Entity("AlbumGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", null) + .WithMany() + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("AlbumTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", null) + .WithMany() + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ArtistGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany() + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ArtistTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany() + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BookGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany() + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BookTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany() + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission") + .WithMany("RolePermissions") + .HasForeignKey("PermissionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role") + .WithMany("RolePermissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Permission"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission") + .WithMany("UserPermissions") + .HasForeignKey("PermissionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("UserPermissions") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Permission"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithOne("UserRole") + .HasForeignKey("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Favorites.FavoriteEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaConsumption.MediaConsumptionRecordEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaConsumption.MediaResumePointEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", null) + .WithMany("Contributors") + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", "Artist") + .WithMany("Albums") + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumCatalogNumberEntity", "CatalogNumbers", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("CatalogNumber") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumCatalogNumbers", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumReleaseTypeEntity", "ReleaseTypes", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("ReleaseType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumReleaseTypes", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + + b.Navigation("Artist"); + + b.Navigation("CatalogNumbers"); + + b.Navigation("Ratings"); + + b.Navigation("ReleaseTypes"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany("Contributors") + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", b => + { + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "Area", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("Area") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "BeginArea", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("BeginArea") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "EndArea", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("EndArea") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistAliasEntity", "Aliases", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("BeginDate") + .HasColumnType("TEXT"); + + b1.Property("EndDate") + .HasColumnType("TEXT"); + + b1.Property("IsEnded") + .HasColumnType("INTEGER"); + + b1.Property("IsPrimary") + .HasColumnType("INTEGER"); + + b1.Property("Locale") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b1.Property("SortName") + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b1.Property("Type") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistAliases", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistIpiEntity", "Ipis", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistIpis", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistIsniEntity", "Isnis", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistIsnis", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.Navigation("Aliases"); + + b.Navigation("Area"); + + b.Navigation("BeginArea"); + + b.Navigation("EndArea"); + + b.Navigation("Ipis"); + + b.Navigation("Isnis"); + + b.Navigation("Ratings"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", null) + .WithMany("Contributors") + .HasForeignKey("TrackId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", "Album") + .WithMany("Tracks") + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackIsrcEntity", "Isrcs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(12) + .HasColumnType("TEXT") + .HasColumnName("ISRC"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackIsrcs", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackMoodEntity", "Moods", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackMoods", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackWorkIswcEntity", "WorkIswcs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackWorkIswcs", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackWorkLanguageEntity", "WorkLanguages", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("LanguageCode") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("TEXT"); + + b1.Property("LanguageName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b1.Property("NativeName") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackWorkLanguages", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.Navigation("Album"); + + b.Navigation("Isrcs"); + + b.Navigation("Moods"); + + b.Navigation("Ratings"); + + b.Navigation("WorkIswcs"); + + b.Navigation("WorkLanguages"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.DirectoryScanFingerprintEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", null) + .WithMany() + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("Libraries") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryContentLocationEntity", "ContentLocations", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("LibraryId") + .HasColumnType("TEXT"); + + b1.Property("Path") + .IsRequired() + .HasMaxLength(260) + .HasColumnType("TEXT") + .HasColumnName("Path"); + + b1.HasKey("Id"); + + b1.HasIndex("LibraryId"); + + b1.ToTable("LibraryContentLocations", (string)null); + + b1.WithOwner() + .HasForeignKey("LibraryId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryPathTemplatePartEntity", "PathTemplateParts", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("IsOptional") + .HasColumnType("INTEGER"); + + b1.Property("Kind") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b1.Property("LibraryId") + .HasColumnType("TEXT"); + + b1.Property("Position") + .HasColumnType("INTEGER") + .HasColumnName("Position"); + + b1.Property("Representation") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("LibraryId", "Position") + .IsUnique(); + + b1.ToTable("LibraryPathTemplateParts", (string)null); + + b1.WithOwner() + .HasForeignKey("LibraryId"); + }); + + b.Navigation("ContentLocations"); + + b.Navigation("PathTemplateParts"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", "Library") + .WithMany("LibraryScans") + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("LibraryScans") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Library"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanResultEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", "LibraryScan") + .WithMany("LibraryScanResults") + .HasForeignKey("LibraryScanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LibraryScan"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanSnapshotEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", "Library") + .WithMany() + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Library"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanStagingResultsEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", null) + .WithMany() + .HasForeignKey("LibraryScanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookArtworkEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany("Artwork") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany("Contributors") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("BookId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("BookId"); + + b1.ToTable("BookRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("BookId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.IsbnEntity", "ISBNs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("BookId") + .HasColumnType("TEXT"); + + b1.Property("Format") + .IsRequired() + .HasMaxLength(6) + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(13) + .HasColumnType("TEXT") + .HasColumnName("ISBN"); + + b1.HasKey("Id"); + + b1.HasIndex("BookId"); + + b1.ToTable("BookISBNs", (string)null); + + b1.WithOwner() + .HasForeignKey("BookId"); + }); + + b.Navigation("ISBNs"); + + b.Navigation("Ratings"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Playlists.PlaylistEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Playlists.PlaylistEntryEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Playlists.PlaylistEntity", null) + .WithMany("Entries") + .HasForeignKey("PlaylistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", null) + .WithOne() + .HasForeignKey("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("TrackGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", null) + .WithMany() + .HasForeignKey("TrackId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("TrackTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", null) + .WithMany() + .HasForeignKey("TrackId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b => + { + b.Navigation("RolePermissions"); + + b.Navigation("UserPermissions"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b => + { + b.Navigation("RolePermissions"); + + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", b => + { + b.Navigation("Contributors"); + + b.Navigation("Tracks"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", b => + { + b.Navigation("Albums"); + + b.Navigation("Contributors"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", b => + { + b.Navigation("Contributors"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.Navigation("LibraryScans"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.Navigation("LibraryScanResults"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.Navigation("Artwork"); + + b.Navigation("Contributors"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Playlists.PlaylistEntity", b => + { + b.Navigation("Entries"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b => + { + b.Navigation("Libraries"); + + b.Navigation("LibraryScans"); + + b.Navigation("UserPermissions"); + + b.Navigation("UserRole"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Lumina.DataAccess/Common/Migrations/20261026153835_DropsMusicPlayRecords.cs b/src/Lumina.DataAccess/Common/Migrations/20261026153835_DropsMusicPlayRecords.cs new file mode 100644 index 00000000..b888304e --- /dev/null +++ b/src/Lumina.DataAccess/Common/Migrations/20261026153835_DropsMusicPlayRecords.cs @@ -0,0 +1,57 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Lumina.DataAccess.Common.Migrations +{ + /// + public partial class DropsMusicPlayRecords : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "MusicPlayRecords"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "MusicPlayRecords", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + UserId = table.Column(type: "TEXT", nullable: false), + TrackId = table.Column(type: "TEXT", nullable: false), + LibraryId = table.Column(type: "TEXT", nullable: false), + AlbumId = table.Column(type: "TEXT", nullable: false), + ArtistId = table.Column(type: "TEXT", nullable: false), + Status = table.Column(type: "TEXT", maxLength: 20, nullable: false), + LastPositionMilliseconds = table.Column(type: "INTEGER", nullable: false), + ListenedDurationMilliseconds = table.Column(type: "INTEGER", nullable: false), + EndedOnUtc = table.Column(type: "TEXT", nullable: true), + Version = table.Column(type: "INTEGER", nullable: false), + CreatedOnUtc = table.Column(type: "TEXT", nullable: false), + CreatedBy = table.Column(type: "TEXT", nullable: false), + UpdatedOnUtc = table.Column(type: "TEXT", nullable: true), + UpdatedBy = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_MusicPlayRecords", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_MusicPlayRecords_TrackId", + table: "MusicPlayRecords", + column: "TrackId"); + + migrationBuilder.CreateIndex( + name: "IX_MusicPlayRecords_UserId_CreatedOnUtc", + table: "MusicPlayRecords", + columns: new[] { "UserId", "CreatedOnUtc" }); + } + } +} diff --git a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs index b1674c65..f6d75310 100644 --- a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs +++ b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs @@ -1184,80 +1184,6 @@ namespace Lumina.DataAccess.Common.Migrations b.ToTable("MusicLibraryScanItemMetadata", (string)null); }); - modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicPlayRecordEntity", b => - { - b.Property("Id") - .HasColumnType("TEXT") - .HasColumnOrder(0); - - b.Property("AlbumId") - .HasColumnType("TEXT") - .HasColumnOrder(4); - - b.Property("ArtistId") - .HasColumnType("TEXT") - .HasColumnOrder(5); - - b.Property("CreatedBy") - .HasColumnType("TEXT") - .HasColumnOrder(12); - - b.Property("CreatedOnUtc") - .HasColumnType("TEXT") - .HasColumnOrder(11); - - b.Property("EndedOnUtc") - .HasColumnType("TEXT") - .HasColumnOrder(9); - - b.Property("LastPositionMilliseconds") - .HasColumnType("INTEGER") - .HasColumnOrder(7); - - b.Property("LibraryId") - .HasColumnType("TEXT") - .HasColumnOrder(3); - - b.Property("ListenedDurationMilliseconds") - .HasColumnType("INTEGER") - .HasColumnOrder(8); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("TEXT") - .HasColumnOrder(6); - - b.Property("TrackId") - .HasColumnType("TEXT") - .HasColumnOrder(2); - - 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("TrackId"); - - b.HasIndex("UserId", "CreatedOnUtc"); - - b.ToTable("MusicPlayRecords", (string)null); - }); - modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackContributorEntity", b => { b.Property("Id") diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicPlayRecordRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicPlayRecordRepository.cs deleted file mode 100644 index 7b98192e..00000000 --- a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicPlayRecordRepository.cs +++ /dev/null @@ -1,135 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; -using Lumina.Application.Common.DataAccess.Repositories.MusicLibrary; -using Lumina.DataAccess.Common.Persistence; -using Lumina.DataAccess.Core.UoW; -using Lumina.Domain.Common.Primitives; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using DomainErrors = Lumina.Domain.Common.Errors.Errors; -#endregion - -namespace Lumina.DataAccess.Core.Repositories.MusicLibrary; - -/// -/// Repository for recorded music plays. -/// -internal sealed class MusicPlayRecordRepository : IMusicPlayRecordRepository -{ - private readonly LuminaDbContext _luminaDbContext; - - /// - /// Initializes a new instance of the class. - /// - /// Injected Entity Framework DbContext. - public MusicPlayRecordRepository(LuminaDbContext luminaDbContext) - { - _luminaDbContext = luminaDbContext; - } - - /// - /// 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. - /// - public async Task> GetByIdForUserAsync(Guid id, Guid userId, bool shouldTrackEntities = true, CancellationToken cancellationToken = default) - { - // The user is part of the filter rather than a check performed after the read, so the storage medium never returns a record that - // belongs to another user in the first place. - IQueryable query = _luminaDbContext.MusicPlayRecords - .Where(playRecord => playRecord.Id == id && playRecord.UserId == userId); - if (!shouldTrackEntities) - query = query.AsNoTracking(); - return await query.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); - } - - /// - /// 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. - public async Task>> GetForUserAsync(Guid userId, CancellationToken cancellationToken) - { - // The user is part of the query, so the storage medium never returns the plays of another user. - List playRecords = await _luminaDbContext.MusicPlayRecords - .AsNoTracking() - .Where(playRecord => playRecord.UserId == userId) - .ToListAsync(cancellationToken).ConfigureAwait(false); - return Result.From>(playRecords); - } - - /// - /// Adds a new play record. - /// - /// The play record to add. - /// Cancellation token that can be used to stop the execution. - /// An representing either a successful operation, or an error. - public async Task> InsertAsync(MusicPlayRecordEntity data, CancellationToken cancellationToken) - { - bool doesPlayRecordExist = await _luminaDbContext.MusicPlayRecords - .AnyAsync(playRecord => playRecord.Id == data.Id, cancellationToken).ConfigureAwait(false); - if (doesPlayRecordExist) - return DomainErrors.MusicPlayHistory.MusicPlayRecordAlreadyExists; - - _luminaDbContext.MusicPlayRecords.Add(data); - return Result.Created; - } - - /// - /// 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. - public async Task> UpdateForUserAsync(MusicPlayRecordEntity data, Guid userId, CancellationToken cancellationToken) - { - // The user is part of both the tracked and the stored lookup, so a future caller can never update a record that belongs to another - // user merely by knowing its Id. - MusicPlayRecordEntity? foundPlayRecord = _luminaDbContext.MusicPlayRecords.Local - .FirstOrDefault(playRecord => playRecord.Id == data.Id && playRecord.UserId == userId) - ?? await _luminaDbContext.MusicPlayRecords - .FirstOrDefaultAsync(playRecord => playRecord.Id == data.Id && playRecord.UserId == userId, cancellationToken).ConfigureAwait(false); - if (foundPlayRecord is null) - return DomainErrors.MusicPlayHistory.MusicPlayRecordNotFound; - - // A report that carries the values that are already stored is a no-op: writing it would bump the version for nothing, and a - // concurrent stop or complete that read the same version could then fail for a report that changed no data. - bool hasEditableChanges = foundPlayRecord.Status != data.Status || - foundPlayRecord.LastPositionMilliseconds != data.LastPositionMilliseconds || - foundPlayRecord.ListenedDurationMilliseconds != data.ListenedDurationMilliseconds || - foundPlayRecord.EndedOnUtc != data.EndedOnUtc; - if (!hasEditableChanges) - return Result.Updated; - - // The stored identity is never overwritten by an edit, and the audit columns are only ever written by the auditing interceptor. - // The version is captured before the copy and incremented after it, so the update is only applied when the row still holds the - // version the report read; a later progress report can therefore never overwrite a completed or stopped play. - Guid storedUserId = foundPlayRecord.UserId; - Guid trackId = foundPlayRecord.TrackId; - Guid libraryId = foundPlayRecord.LibraryId; - Guid albumId = foundPlayRecord.AlbumId; - Guid artistId = foundPlayRecord.ArtistId; - long version = foundPlayRecord.Version; - EditableValuesCopier.CopyEditableValues(_luminaDbContext, foundPlayRecord, data); - foundPlayRecord.UserId = storedUserId; - foundPlayRecord.TrackId = trackId; - foundPlayRecord.LibraryId = libraryId; - foundPlayRecord.AlbumId = albumId; - foundPlayRecord.ArtistId = artistId; - foundPlayRecord.Version = version + 1; - return Result.Updated; - } -} diff --git a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs index e30b5ecf..16f46317 100644 --- a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs +++ b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs @@ -53,7 +53,6 @@ public class LuminaDbContext : DbContext public virtual DbSet ScheduledJobs { get; set; } = null!; public virtual DbSet ScheduledJobExecutions { get; set; } = null!; public virtual DbSet SchedulerDisplayPreferences { get; set; } = null!; - public virtual DbSet MusicPlayRecords { get; set; } = null!; public virtual DbSet Playlists { get; set; } = null!; public virtual DbSet PlaylistEntries { get; set; } = null!; public virtual DbSet Favorites { get; set; } = null!; diff --git a/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs b/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs index 81e86b7e..f6a29ab7 100644 --- a/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs +++ b/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs @@ -70,7 +70,6 @@ public class UnitOfWork : IUnitOfWork, IDisposable private IThemeRepository? _themeRepository; private IUserRepository? _userRepository; private IUserSettingsRepository? _userSettingsRepository; - private IMusicPlayRecordRepository? _musicPlayRecordRepository; private IPlaylistRepository? _playlistRepository; private IFavoriteRepository? _favoriteRepository; private IMediaConsumptionRecordRepository? _mediaConsumptionRecordRepository; @@ -386,18 +385,6 @@ public class UnitOfWork : IUnitOfWork, IDisposable } } - /// - /// Gets the music play record repository. - /// - public IMusicPlayRecordRepository MusicPlayRecordRepository - { - get - { - _musicPlayRecordRepository ??= new MusicPlayRecordRepository(_luminaDbContext); - return _musicPlayRecordRepository; - } - } - /// /// Gets the playlist repository. /// diff --git a/src/Lumina.Domain.SharedKernel/Common/Enums/Playback/PlaybackRecordStatus.cs b/src/Lumina.Domain.SharedKernel/Common/Enums/Playback/PlaybackRecordStatus.cs deleted file mode 100644 index 4eb75fa6..00000000 --- a/src/Lumina.Domain.SharedKernel/Common/Enums/Playback/PlaybackRecordStatus.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Lumina.Domain.SharedKernel.Common.Enums.Playback; - -/// -/// Enumeration for the states of a recorded playback. -/// -public enum PlaybackRecordStatus -{ - /// - /// The playback was recorded as started and has not ended yet. - /// - InProgress, - - /// - /// The playback reached the end of the media item. - /// - Completed, - - /// - /// The playback ended before the media item completed. - /// - Stopped, -} diff --git a/src/Lumina.Domain/Common/Errors/Errors.MusicPlayHistory.cs b/src/Lumina.Domain/Common/Errors/Errors.MusicPlayHistory.cs deleted file mode 100644 index cefddfa4..00000000 --- a/src/Lumina.Domain/Common/Errors/Errors.MusicPlayHistory.cs +++ /dev/null @@ -1,28 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Primitives; -#endregion - -namespace Lumina.Domain.Common.Errors; - -/// -/// Music play history error types. -/// -public static partial class Errors -{ - public static class MusicPlayHistory - { - public static Error MusicPlayRecordNotFound => Error.NotFound(description: nameof(MusicPlayRecordNotFound)); - public static Error MusicPlayRecordAlreadyExists => Error.Conflict(description: nameof(MusicPlayRecordAlreadyExists)); - public static Error PlayRecordIdCannotBeEmpty => Error.Validation(description: nameof(PlayRecordIdCannotBeEmpty)); - public static Error PlaybackPositionCannotBeNull => Error.Validation(description: nameof(PlaybackPositionCannotBeNull)); - public static Error PlaybackPositionMustBeNonNegative => Error.Validation(description: nameof(PlaybackPositionMustBeNonNegative)); - public static Error PlaybackPositionIsOutOfRange => Error.Validation(description: nameof(PlaybackPositionIsOutOfRange)); - public static Error ListenedDurationCannotBeNull => Error.Validation(description: nameof(ListenedDurationCannotBeNull)); - public static Error ListenedDurationMustBeNonNegative => Error.Validation(description: nameof(ListenedDurationMustBeNonNegative)); - public static Error ListenedDurationIsOutOfRange => Error.Validation(description: nameof(ListenedDurationIsOutOfRange)); - public static Error PlayIsNotInProgress => Error.Conflict(description: nameof(PlayIsNotInProgress)); - public static Error ListenedDurationCannotDecrease => Error.Validation(description: nameof(ListenedDurationCannotDecrease)); - public static Error InProgressPlayCannotHaveEndTime => Error.Validation(description: nameof(InProgressPlayCannotHaveEndTime)); - public static Error EndedPlayMustHaveEndTime => Error.Validation(description: nameof(EndedPlayMustHaveEndTime)); - } -} diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/AlbumId.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/AlbumId.cs deleted file mode 100644 index e1955782..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/AlbumId.cs +++ /dev/null @@ -1,51 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Models.Core; -using System; -using System.Collections.Generic; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.AudioLibraryBoundedContext.MusicLibraryAggregate; - -/// -/// Value Object for the Id of an album, duplicated from the AudioLibrary bounded context to keep the cross bounded context references decoupled. -/// -[DebuggerDisplay("{Value}")] -public sealed class AlbumId : EntityId -{ - /// - /// Initializes a new instance of the class. - /// - /// The value representing this object. - private AlbumId(Guid value) : base(value) - { - } - - /// - /// Creates a new instance of the class. - /// - /// The created instance. - public static AlbumId CreateUnique() - { - return new AlbumId(Guid.NewGuid()); - } - - /// - /// Creates a new instance of the class, from a pre-existing . - /// - /// The value used to create the instance. - /// The created instance. - public static AlbumId Create(Guid value) - { - return new AlbumId(value); - } - - /// - /// Gets the list of items that define equality of the object. - /// - /// A list of items defining the equality. - public override IEnumerable GetEqualityComponents() - { - yield return Value; - } -} diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/ArtistId.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/ArtistId.cs deleted file mode 100644 index 3b00f250..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/ArtistId.cs +++ /dev/null @@ -1,51 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Models.Core; -using System; -using System.Collections.Generic; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.AudioLibraryBoundedContext.MusicLibraryAggregate; - -/// -/// Value Object for the Id of an artist, duplicated from the AudioLibrary bounded context to keep the cross bounded context references decoupled. -/// -[DebuggerDisplay("{Value}")] -public sealed class ArtistId : EntityId -{ - /// - /// Initializes a new instance of the class. - /// - /// The value representing this object. - private ArtistId(Guid value) : base(value) - { - } - - /// - /// Creates a new instance of the class. - /// - /// The created instance. - public static ArtistId CreateUnique() - { - return new ArtistId(Guid.NewGuid()); - } - - /// - /// Creates a new instance of the class, from a pre-existing . - /// - /// The value used to create the instance. - /// The created instance. - public static ArtistId Create(Guid value) - { - return new ArtistId(value); - } - - /// - /// Gets the list of items that define equality of the object. - /// - /// A list of items defining the equality. - public override IEnumerable GetEqualityComponents() - { - yield return Value; - } -} diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/TrackId.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/TrackId.cs deleted file mode 100644 index ee9a4f1e..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/AudioLibraryBoundedContext/MusicLibraryAggregate/TrackId.cs +++ /dev/null @@ -1,51 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Models.Core; -using System; -using System.Collections.Generic; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.AudioLibraryBoundedContext.MusicLibraryAggregate; - -/// -/// Value Object for the Id of a track, duplicated from the AudioLibrary bounded context to keep the cross bounded context references decoupled. -/// -[DebuggerDisplay("{Value}")] -public sealed class TrackId : EntityId -{ - /// - /// Initializes a new instance of the class. - /// - /// The value representing this object. - private TrackId(Guid value) : base(value) - { - } - - /// - /// Creates a new instance of the class. - /// - /// The created instance. - public static TrackId CreateUnique() - { - return new TrackId(Guid.NewGuid()); - } - - /// - /// Creates a new instance of the class, from a pre-existing . - /// - /// The value used to create the instance. - /// The created instance. - public static TrackId Create(Guid value) - { - return new TrackId(value); - } - - /// - /// Gets the list of items that define equality of the object. - /// - /// A list of items defining the equality. - public override IEnumerable GetEqualityComponents() - { - yield return Value; - } -} diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs deleted file mode 100644 index 435a3fc4..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs +++ /dev/null @@ -1,51 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Models.Core; -using System; -using System.Collections.Generic; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate; - -/// -/// Value Object for the Id of a media library, duplicated from the LibraryManagement bounded context to keep the cross bounded context references decoupled. -/// -[DebuggerDisplay("{Value}")] -public sealed class LibraryId : EntityId -{ - /// - /// Initializes a new instance of the class. - /// - /// The value representing this object. - private LibraryId(Guid value) : base(value) - { - } - - /// - /// Creates a new instance of the class. - /// - /// The created instance. - public static LibraryId CreateUnique() - { - return new LibraryId(Guid.NewGuid()); - } - - /// - /// Creates a new instance of the class, from a pre-existing . - /// - /// The value used to create the instance. - /// The created instance. - public static LibraryId Create(Guid value) - { - return new LibraryId(value); - } - - /// - /// Gets the list of items that define equality of the object. - /// - /// A list of items defining the equality. - public override IEnumerable GetEqualityComponents() - { - yield return Value; - } -} diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs deleted file mode 100644 index 4339b0f4..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs +++ /dev/null @@ -1,51 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Models.Core; -using System; -using System.Collections.Generic; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate; - -/// -/// Value Object for the Id of a user, duplicated from the UserManagement bounded context to keep the cross bounded context references decoupled. -/// -[DebuggerDisplay("{Value}")] -public sealed class UserId : EntityId -{ - /// - /// Initializes a new instance of the class. - /// - /// The value representing this object. - private UserId(Guid value) : base(value) - { - } - - /// - /// Creates a new instance of the class. - /// - /// The created instance. - public static UserId CreateUnique() - { - return new UserId(Guid.NewGuid()); - } - - /// - /// Creates a new instance of the class, from a pre-existing . - /// - /// The value used to create the instance. - /// The created instance. - public static UserId Create(Guid value) - { - return new UserId(value); - } - - /// - /// Gets the list of items that define equality of the object. - /// - /// A list of items defining the equality. - public override IEnumerable GetEqualityComponents() - { - yield return Value; - } -} diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayCompletedDomainEvent.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayCompletedDomainEvent.cs deleted file mode 100644 index 8fa32ceb..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayCompletedDomainEvent.cs +++ /dev/null @@ -1,31 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Events; -using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.AudioLibraryBoundedContext.MusicLibraryAggregate; -using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate; -using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.ValueObjects; -using System; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.Events; - -/// -/// Domain event raised when a music play completes. -/// -/// The unique identifier of the domain event. -/// The unique identifier of the play record. -/// The unique identifier of the user that owns the play record. -/// The unique identifier of the track that completed. -/// The last position reported by the player. -/// The duration that the user listened to. -/// The date and time when the domain event occurred. -[DebuggerDisplay("MusicPlayRecordId: {MusicPlayRecordId.Value}; TrackId: {TrackId.Value}")] -public record MusicPlayCompletedDomainEvent( - Guid Id, - MusicPlayRecordId MusicPlayRecordId, - UserId UserId, - TrackId TrackId, - MusicPlayPosition Position, - TimeSpan ListenedDuration, - DateTime OccurredOnUtc -) : IDomainEvent; diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayProgressedDomainEvent.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayProgressedDomainEvent.cs deleted file mode 100644 index 070ffb2c..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayProgressedDomainEvent.cs +++ /dev/null @@ -1,31 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Events; -using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.AudioLibraryBoundedContext.MusicLibraryAggregate; -using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate; -using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.ValueObjects; -using System; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.Events; - -/// -/// Domain event raised when a player reports the progress of a music play. -/// -/// The unique identifier of the domain event. -/// The unique identifier of the play record. -/// The unique identifier of the user that owns the play record. -/// The unique identifier of the track that is being played. -/// The last position reported by the player. -/// The duration that the user has listened to so far. -/// The date and time when the domain event occurred. -[DebuggerDisplay("MusicPlayRecordId: {MusicPlayRecordId.Value}; Position: {Position.Offset}")] -public record MusicPlayProgressedDomainEvent( - Guid Id, - MusicPlayRecordId MusicPlayRecordId, - UserId UserId, - TrackId TrackId, - MusicPlayPosition Position, - TimeSpan ListenedDuration, - DateTime OccurredOnUtc -) : IDomainEvent; diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayStartedDomainEvent.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayStartedDomainEvent.cs deleted file mode 100644 index a7768e58..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayStartedDomainEvent.cs +++ /dev/null @@ -1,34 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Events; -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.ValueObjects; -using System; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.Events; - -/// -/// Domain event raised when a music play starts. -/// -/// The unique identifier of the domain event. -/// The unique identifier of the play record. -/// The unique identifier of the user that started the play. -/// The unique identifier of the track that was played. -/// The unique identifier of the media library that contains the track. -/// The unique identifier of the album that contains the track. -/// The unique identifier of the artist that produced the track. -/// The date and time when the domain event occurred. -[DebuggerDisplay("MusicPlayRecordId: {MusicPlayRecordId.Value}; TrackId: {TrackId.Value}")] -public record MusicPlayStartedDomainEvent( - Guid Id, - MusicPlayRecordId MusicPlayRecordId, - UserId UserId, - TrackId TrackId, - LibraryId LibraryId, - AlbumId AlbumId, - ArtistId ArtistId, - DateTime OccurredOnUtc -) : IDomainEvent; diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayStoppedDomainEvent.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayStoppedDomainEvent.cs deleted file mode 100644 index 0cb26b6f..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/Events/MusicPlayStoppedDomainEvent.cs +++ /dev/null @@ -1,31 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Events; -using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.AudioLibraryBoundedContext.MusicLibraryAggregate; -using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate; -using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.ValueObjects; -using System; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.Events; - -/// -/// Domain event raised when a music play stops before the track completes. -/// -/// The unique identifier of the domain event. -/// The unique identifier of the play record. -/// The unique identifier of the user that owns the play record. -/// The unique identifier of the track that was stopped. -/// The last position reported by the player. -/// The duration that the user listened to. -/// The date and time when the domain event occurred. -[DebuggerDisplay("MusicPlayRecordId: {MusicPlayRecordId.Value}; TrackId: {TrackId.Value}")] -public record MusicPlayStoppedDomainEvent( - Guid Id, - MusicPlayRecordId MusicPlayRecordId, - UserId UserId, - TrackId TrackId, - MusicPlayPosition Position, - TimeSpan ListenedDuration, - DateTime OccurredOnUtc -) : IDomainEvent; diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/MusicPlayRecord.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/MusicPlayRecord.cs deleted file mode 100644 index 145f83de..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/MusicPlayRecord.cs +++ /dev/null @@ -1,319 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Errors; -using Lumina.Domain.Common.Models.Core; -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.Events; -using Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.ValueObjects; -using Lumina.Domain.SharedKernel.Common.Enums.Playback; -using System; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate; - -/// -/// Aggregate root for a recorded music play. -/// -/// -/// A record is created when a player starts a track and is updated by the progress, completion and stop reports of that player. It logs what was -/// played, how far it reached and how long the user listened, so statistics and recommendations can be built from it. The record is created when the -/// play starts, so is the start time. -/// -[DebuggerDisplay("Id: {Id.Value}; TrackId: {TrackId.Value}; Status: {Status}")] -public sealed class MusicPlayRecord : AggregateRoot -{ - /// - /// The minimum number of seconds a user must listen to a track for the play to count, unless the play completed first. - /// - private const int MINIMUM_COUNTED_LISTENED_DURATION_SECONDS = 30; - - /// - /// Gets the object representing the unique identifier of the user that started the play. - /// - public UserId UserId { get; private set; } - - /// - /// Gets the Id of the track that was played. - /// - public TrackId TrackId { get; private set; } - - /// - /// Gets the Id of the media library that contains the track. - /// - public LibraryId LibraryId { get; private set; } - - /// - /// Gets the Id of the album that contains the track. - /// - public AlbumId AlbumId { get; private set; } - - /// - /// Gets the Id of the artist that produced the track. - /// - public ArtistId ArtistId { get; private set; } - - /// - /// Gets the state of the recorded play. - /// - public PlaybackRecordStatus Status { get; private set; } - - /// - /// Gets the last position reported by the player. - /// - public MusicPlayPosition LastPosition { get; private set; } - - /// - /// Gets the duration that the user has listened to. - /// - public TimeSpan ListenedDuration { get; private set; } - - /// - /// Gets the date and time when the play completed or stopped, if it has ended. - /// - public Optional EndedOnUtc { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// The object representing the unique identifier of the play record. - /// The object representing the unique identifier of the user that started the play. - /// 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. - /// The duration that the user has listened to. - /// The date and time when the play completed or stopped, if it has ended. - /// The date and time when the play started. - /// The date and time when the play record was last updated. - private MusicPlayRecord( - MusicPlayRecordId id, - UserId userId, - TrackId trackId, - LibraryId libraryId, - AlbumId albumId, - ArtistId artistId, - PlaybackRecordStatus status, - MusicPlayPosition lastPosition, - TimeSpan listenedDuration, - Optional endedOnUtc, - DateTime createdOnUtc, - Optional updatedOnUtc) : base(id) - { - Id = id; - UserId = userId; - TrackId = trackId; - LibraryId = libraryId; - AlbumId = albumId; - ArtistId = artistId; - Status = status; - LastPosition = lastPosition; - ListenedDuration = listenedDuration; - EndedOnUtc = endedOnUtc; - CreatedOnUtc = createdOnUtc; - UpdatedOnUtc = updatedOnUtc; - } - - /// - /// Creates a new play record for a track that started playing. - /// - /// The object representing the unique identifier of the user that started the play. - /// 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 created instance. - public static MusicPlayRecord Create( - UserId userId, - TrackId trackId, - LibraryId libraryId, - AlbumId albumId, - ArtistId artistId) - { - DateTime occurredOnUtc = DateTime.UtcNow; - MusicPlayRecord playRecord = new( - MusicPlayRecordId.CreateUnique(), - userId, - trackId, - libraryId, - albumId, - artistId, - PlaybackRecordStatus.InProgress, - MusicPlayPosition.Zero, - TimeSpan.Zero, - Optional.None(), - occurredOnUtc, - Optional.None()); - - playRecord._domainEvents.Add(new MusicPlayStartedDomainEvent( - Guid.NewGuid(), - playRecord.Id, - userId, - trackId, - libraryId, - albumId, - artistId, - occurredOnUtc)); - return playRecord; - } - - /// - /// Creates a new instance of the class, with pre-existing data. - /// - /// The object representing the unique identifier of the play record. - /// The object representing the unique identifier of the user that started the play. - /// 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. - /// The duration that the user has listened to. - /// The date and time when the play completed or stopped, if it has ended. - /// The date and time when the play started. - /// The date and time when the play record was last updated. - /// - /// An containing either a successfully created , or an error message. - /// - public static Result Create( - MusicPlayRecordId id, - UserId userId, - TrackId trackId, - LibraryId libraryId, - AlbumId albumId, - ArtistId artistId, - PlaybackRecordStatus status, - MusicPlayPosition lastPosition, - TimeSpan listenedDuration, - Optional endedOnUtc, - DateTime createdOnUtc, - Optional updatedOnUtc) - { - if (status == PlaybackRecordStatus.InProgress && endedOnUtc.HasValue) - return Errors.MusicPlayHistory.InProgressPlayCannotHaveEndTime; - if (status != PlaybackRecordStatus.InProgress && !endedOnUtc.HasValue) - return Errors.MusicPlayHistory.EndedPlayMustHaveEndTime; - - return new MusicPlayRecord( - id, - userId, - trackId, - libraryId, - albumId, - artistId, - status, - lastPosition, - listenedDuration, - endedOnUtc, - createdOnUtc, - updatedOnUtc); - } - - /// - /// Determines whether a play with the provided and counts as a play for the listening statistics. - /// - /// The state of the recorded play. - /// The duration that the user has listened to. - /// when the play counts, otherwise. - public static bool DoesCountAsPlay(PlaybackRecordStatus status, TimeSpan listenedDuration) - { - return status == PlaybackRecordStatus.Completed || listenedDuration.TotalSeconds >= MINIMUM_COUNTED_LISTENED_DURATION_SECONDS; - } - - /// - /// Updates the last reported position and the listened duration of an in-progress play. - /// - /// The last position reported by the player. - /// The duration that the user has listened to. - /// An representing either a successful update, or an error. - public Result ReportProgress(MusicPlayPosition position, TimeSpan listenedDuration) - { - if (Status != PlaybackRecordStatus.InProgress) - return Errors.MusicPlayHistory.PlayIsNotInProgress; - if (listenedDuration < ListenedDuration) - return Errors.MusicPlayHistory.ListenedDurationCannotDecrease; - if (LastPosition.Offset == position.Offset && ListenedDuration == listenedDuration) - return Result.Updated; - - LastPosition = position; - ListenedDuration = listenedDuration; - - DateTime occurredOnUtc = DateTime.UtcNow; - UpdatedOnUtc = Optional.Some(occurredOnUtc); - _domainEvents.Add(new MusicPlayProgressedDomainEvent( - Guid.NewGuid(), - Id, - UserId, - TrackId, - position, - listenedDuration, - occurredOnUtc)); - return Result.Updated; - } - - /// - /// Marks an in-progress play as completed. - /// - /// The last position reported by the player. - /// The duration that the user listened to. - /// An representing either a successful update, or an error. - public Result Complete(MusicPlayPosition position, TimeSpan listenedDuration) - { - if (Status != PlaybackRecordStatus.InProgress) - return Errors.MusicPlayHistory.PlayIsNotInProgress; - if (listenedDuration < ListenedDuration) - return Errors.MusicPlayHistory.ListenedDurationCannotDecrease; - - LastPosition = position; - ListenedDuration = listenedDuration; - Status = PlaybackRecordStatus.Completed; - - DateTime occurredOnUtc = DateTime.UtcNow; - EndedOnUtc = Optional.Some(occurredOnUtc); - UpdatedOnUtc = Optional.Some(occurredOnUtc); - _domainEvents.Add(new MusicPlayCompletedDomainEvent( - Guid.NewGuid(), - Id, - UserId, - TrackId, - position, - listenedDuration, - occurredOnUtc)); - return Result.Updated; - } - - /// - /// Marks an in-progress play as stopped before the track completed. - /// - /// The last position reported by the player. - /// The duration that the user listened to. - /// An representing either a successful update, or an error. - public Result Stop(MusicPlayPosition position, TimeSpan listenedDuration) - { - if (Status != PlaybackRecordStatus.InProgress) - return Errors.MusicPlayHistory.PlayIsNotInProgress; - if (listenedDuration < ListenedDuration) - return Errors.MusicPlayHistory.ListenedDurationCannotDecrease; - - LastPosition = position; - ListenedDuration = listenedDuration; - Status = PlaybackRecordStatus.Stopped; - - DateTime occurredOnUtc = DateTime.UtcNow; - EndedOnUtc = Optional.Some(occurredOnUtc); - UpdatedOnUtc = Optional.Some(occurredOnUtc); - _domainEvents.Add(new MusicPlayStoppedDomainEvent( - Guid.NewGuid(), - Id, - UserId, - TrackId, - position, - listenedDuration, - occurredOnUtc)); - return Result.Updated; - } -} diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/ValueObjects/MusicPlayPosition.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/ValueObjects/MusicPlayPosition.cs deleted file mode 100644 index abaa70ab..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/ValueObjects/MusicPlayPosition.cs +++ /dev/null @@ -1,51 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Models.Core; -using System; -using System.Collections.Generic; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.ValueObjects; - -/// -/// Value Object for the last position reported by a player for a music play record. -/// -public sealed class MusicPlayPosition : ValueObject -{ - /// - /// Gets the position reported by the player. - /// - public TimeSpan Offset { get; } - - /// - /// Gets the position at the very start of a track. - /// - public static MusicPlayPosition Zero { get; } = new(TimeSpan.Zero); - - /// - /// Initializes a new instance of the class. - /// - /// The position reported by the player. - private MusicPlayPosition(TimeSpan offset) - { - Offset = offset; - } - - /// - /// Creates a new instance of the class. - /// - /// The position reported by the player. - /// The created instance. - public static MusicPlayPosition Create(TimeSpan offset) - { - return new MusicPlayPosition(offset); - } - - /// - /// Gets the list of items that define equality of the object. - /// - /// A list of items defining the equality. - public override IEnumerable GetEqualityComponents() - { - yield return Offset; - } -} diff --git a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/ValueObjects/MusicPlayRecordId.cs b/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/ValueObjects/MusicPlayRecordId.cs deleted file mode 100644 index a8679528..00000000 --- a/src/Lumina.Domain/Core/BoundedContexts/MusicPlayHistoryBoundedContext/MusicPlayRecordAggregate/ValueObjects/MusicPlayRecordId.cs +++ /dev/null @@ -1,51 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Models.Core; -using System; -using System.Collections.Generic; -using System.Diagnostics; -#endregion - -namespace Lumina.Domain.Core.BoundedContexts.MusicPlayHistoryBoundedContext.MusicPlayRecordAggregate.ValueObjects; - -/// -/// Value Object for the Id of a music play record. -/// -[DebuggerDisplay("{Value}")] -public sealed class MusicPlayRecordId : EntityId -{ - /// - /// Initializes a new instance of the class. - /// - /// The value representing this object. - private MusicPlayRecordId(Guid value) : base(value) - { - } - - /// - /// Creates a new instance of the class. - /// - /// The created instance. - public static MusicPlayRecordId CreateUnique() - { - return new MusicPlayRecordId(Guid.NewGuid()); - } - - /// - /// Creates a new instance of the class, from a pre-existing . - /// - /// The value used to create the instance. - /// The created instance. - public static MusicPlayRecordId Create(Guid value) - { - return new MusicPlayRecordId(value); - } - - /// - /// Gets the list of items that define equality of the object. - /// - /// A list of items defining the equality. - public override IEnumerable GetEqualityComponents() - { - yield return Value; - } -} diff --git a/src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.PlayHistory.cs b/src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.PlayHistory.cs deleted file mode 100644 index b74dda95..00000000 --- a/src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.PlayHistory.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; - -/// -/// Class for the collection of the music play history routes of the API. -/// -public static partial class ApiRoutes -{ - /// - /// Routes for the music play history of the current user. - /// - public static class PlayHistory - { - public const string START_PLAY = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/plays"; - public const string GET_PLAY = "/users/me/music-play-history/plays/{playRecordId}"; - public const string REPORT_PLAY_PROGRESS = "/users/me/music-play-history/plays/{playRecordId}/progress"; - public const string COMPLETE_PLAY = "/users/me/music-play-history/plays/{playRecordId}/complete"; - public const string STOP_PLAY = "/users/me/music-play-history/plays/{playRecordId}/stop"; - } -} diff --git a/src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.PlayStatistics.cs b/src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.PlayStatistics.cs deleted file mode 100644 index 5c398ae8..00000000 --- a/src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.PlayStatistics.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; - -/// -/// Class for the collection of the music play statistics routes of the API. -/// -public static partial class ApiRoutes -{ - /// - /// Routes for the music play statistics of the current user. - /// - public static class PlayStatistics - { - public const string GET_RECENTLY_PLAYED = "/users/me/music-play-history/recently-played"; - public const string GET_MOST_PLAYED = "/users/me/music-play-history/most-played"; - public const string GET_MUSIC_PLAY_STATISTICS = "/users/me/music-play-history/statistics"; - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/CompletePlay/CompletePlayEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/CompletePlay/CompletePlayEndpoint.cs deleted file mode 100644 index b4f684c9..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/CompletePlay/CompletePlayEndpoint.cs +++ /dev/null @@ -1,58 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.CQRS; -using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.CompletePlay; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Domain.Common.Primitives; -using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; -using Lumina.Presentation.Api.Core.Endpoints.Common; -using Microsoft.AspNetCore.Http; -using System.Threading; -using System.Threading.Tasks; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.CompletePlay; - -/// -/// API endpoint for the /users/me/music-play-history/plays/{playRecordId}/complete route. -/// -/// -/// Uses "me" because it is always for the currently authenticated user. -/// -public class CompletePlayEndpoint : BaseEndpoint -{ - private readonly ICommandHandler> _completePlayCommandHandler; - - /// - /// Initializes a new instance of the class. - /// - /// Injected service for handling complete play commands. - public CompletePlayEndpoint(ICommandHandler> completePlayCommandHandler) - { - _completePlayCommandHandler = completePlayCommandHandler; - } - - /// - /// Configures the API endpoint. - /// - public override void Configure() - { - Verbs(FastEndpoints.Http.PUT); - Routes(ApiRoutes.PlayHistory.COMPLETE_PLAY); - Version(1); - DontCatchExceptions(); - } - - /// - /// Reports that a play of a track by the current user reached its end. - /// - /// The request containing the last position and the listened duration. - /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(CompletePlayRequest request, CancellationToken cancellationToken) - { - // Take the unique identifier from the route. - string? playRecordId = HttpContext.Request.RouteValues["playRecordId"]?.ToString(); - Result result = await _completePlayCommandHandler.HandleAsync(request.ToCommand(playRecordId), cancellationToken).ConfigureAwait(false); - return result.Match(success => TypedResults.Ok(success), Problem); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/CompletePlay/CompletePlayEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/CompletePlay/CompletePlayEndpointSummary.cs deleted file mode 100644 index 11e0b9e1..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/CompletePlay/CompletePlayEndpointSummary.cs +++ /dev/null @@ -1,129 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.CompletePlay; - -/// -/// Class used for providing a textual description for the API endpoint, for OpenAPI. -/// -[ExcludeFromCodeCoverage] -public class CompletePlayEndpointSummary : Summary -{ - /// - /// Initializes a new instance of the class. - /// - public CompletePlayEndpointSummary() - { - Summary = "Reports that a play of a track by the current user reached its end."; - Description = "Reports that a play of a track by the current user reached its end, together with the last position and the listened duration. Only an in-progress play of the current user can be completed, and the listened duration can never decrease. The reports are stored so that the play history, statistics and recommendations can be built from them."; - - ExampleRequest = new CompletePlayRequest( - PositionInSeconds: 354, - ListenedDurationInSeconds: 354 - ); - - RequestParam(request => request.PositionInSeconds, "The last position reported by the player, in seconds. Required."); - RequestParam(request => request.ListenedDurationInSeconds, "The duration the user listened to, in seconds. Required."); - - Response(200, "The completion of the play was reported.", example: new { }); - - Response(401, "Authentication required.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "Authentication failed", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/complete" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token has expired", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/complete" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token is invalid", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/complete" - } - } - ); - - Response(404, "The request failed because the play record does not exist, or it does not belong to the current user.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.5", - title = "General.NotFound", - status = 404, - detail = "MusicPlayRecordNotFound", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/complete", - traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00" - } - ); - - Response(409, "The request failed because the play is not in progress anymore, or because another report changed it after this request read it.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.10", - title = "General.Conflict", - status = 409, - detail = "PlayIsNotInProgress", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/complete", - traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" - }, - new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.10", - title = "General.Conflict", - status = 409, - detail = "ConcurrencyConflict", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/complete", - traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" - } - } - ); - - Response(422, "The request did not pass validation checks.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc4918#section-11.2", - title = "General.Validation", - status = 422, - detail = "OneOrMoreValidationErrorsOccurred", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/complete", - errors = new Dictionary - { - { - "General.Validation", new[] - { - "PlayRecordIdCannotBeEmpty", - "PlaybackPositionCannotBeNull", - "PlaybackPositionMustBeNonNegative", - "PlaybackPositionIsOutOfRange", - "ListenedDurationCannotBeNull", - "ListenedDurationMustBeNonNegative", - "ListenedDurationIsOutOfRange", - "ListenedDurationCannotDecrease" - } - } - }, - traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00" - } - ); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayed/GetMostPlayedEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayed/GetMostPlayedEndpoint.cs deleted file mode 100644 index a85c56e3..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayed/GetMostPlayedEndpoint.cs +++ /dev/null @@ -1,63 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Application.Common.CQRS; -using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetMostPlayed; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Contracts.Responses.Common; -using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Domain.Common.Primitives; -using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; -using Lumina.Presentation.Api.Core.Endpoints.Common; -using Microsoft.AspNetCore.Http; -using System.Threading; -using System.Threading.Tasks; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetMostPlayed; - -/// -/// API endpoint for the /users/me/music-play-history/most-played route. -/// -/// -/// Uses "me" because it is always for the currently authenticated user. -/// -public class GetMostPlayedEndpoint : BaseEndpoint -{ - private readonly IQueryHandler>> _getMostPlayedQueryHandler; - - /// - /// Initializes a new instance of the class. - /// - /// Injected service for handling get most played queries. - public GetMostPlayedEndpoint(IQueryHandler>> getMostPlayedQueryHandler) - { - _getMostPlayedQueryHandler = getMostPlayedQueryHandler; - } - - /// - /// Configures the API endpoint. - /// - public override void Configure() - { - Verbs(Http.GET); - Routes(ApiRoutes.PlayStatistics.GET_MOST_PLAYED); - Version(1); - DontCatchExceptions(); - } - - /// - /// Gets the most played tracks of the current user. - /// - /// The request containing the optional page bounds. - /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(GetMostPlayedRequest request, CancellationToken cancellationToken) - { - // The statistics belong to the authenticated user, so no intermediary may store any response of this route, including its problem - // responses, and every response varies by the bearer token that authorized it. - HttpContext.Response.Headers["Cache-Control"] = "private, no-store"; - HttpContext.Response.Headers["Vary"] = "Authorization"; - Result> result = await _getMostPlayedQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false); - return result.Match(success => TypedResults.Ok(success), Problem); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayed/GetMostPlayedEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayed/GetMostPlayedEndpointSummary.cs deleted file mode 100644 index 2e44e5c6..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMostPlayed/GetMostPlayedEndpointSummary.cs +++ /dev/null @@ -1,116 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Contracts.Responses.Common; -using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using System; -using System.Diagnostics.CodeAnalysis; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetMostPlayed; - -/// -/// Class used for providing a textual description for the API endpoint, for OpenAPI. -/// -[ExcludeFromCodeCoverage] -public class GetMostPlayedEndpointSummary : Summary -{ - /// - /// Initializes a new instance of the class. - /// - public GetMostPlayedEndpointSummary() - { - Summary = "Gets the most played tracks of the current user."; - Description = "Gets the tracks the current user played the most, from the most played. Only the plays that count as plays are included: a play counts when it completed or when the listened duration reached 30 seconds. Each track is returned once, with its counted plays, its completed plays, the duration the user listened to it and its last activity time. A track deleted from its library keeps its row, without display data. The response is private to the authenticated user."; - - ExampleRequest = new GetMostPlayedRequest(CurrentPage: 1, PerPage: 50); - RequestParam(request => request.CurrentPage, "The one based page of tracks to return. Optional. Defaults to 1."); - RequestParam(request => request.PerPage, "The number of tracks per page. Optional. Defaults to 50. When both pagination parameters are omitted, every matching track is returned."); - - ResponseParam>(response => response.Data, "The most played tracks of the requested page, ordered by counted plays, listened duration, last activity, and track Id."); - ResponseParam>(response => response.CurrentPage, "The current page number."); - ResponseParam>(response => response.PerPage, "The number of tracks retrieved per page."); - ResponseParam>(response => response.Count, "The total number of tracks that match the filters."); - ResponseParam>(response => response.NumberOfPages, "The total number of pages."); - ResponseParam(response => response.TrackId, "The Id of the track."); - ResponseParam(response => response.LibraryId, "The Id of the media library that contains the track."); - ResponseParam(response => response.AlbumId, "The Id of the album that contains the track."); - ResponseParam(response => response.ArtistId, "The Id of the artist that produced the track."); - ResponseParam(response => response.Title, "The title of the track, if it still exists and the user can access its library."); - ResponseParam(response => response.AlbumTitle, "The title of the album that contains the track, if available."); - ResponseParam(response => response.ArtistName, "The name of the artist that produced the track, if available."); - ResponseParam(response => response.CoverPath, "The path of the cover art of the album, if available."); - ResponseParam(response => response.LastPlayedOnUtc, "The date and time of the last recorded activity of the track's most recent play."); - ResponseParam(response => response.PlayCount, "The number of plays of the track that count as plays."); - ResponseParam(response => response.CompletedPlayCount, "The number of plays of the track that completed."); - ResponseParam(response => response.ListenedDurationInSeconds, "The duration the user listened to the track, over all of its counted plays, in seconds."); - - Response(200, "The requested page of most played tracks is returned.", - example: new PaginatedResponse - { - Data = - [ - new PlayedTrackResponse( - TrackId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"), - LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"), - AlbumId: Guid.Parse("e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f"), - ArtistId: Guid.Parse("d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a"), - Title: "Time", - AlbumTitle: "The Dark Side of the Moon", - ArtistName: "Pink Floyd", - CoverPath: "covers/dark-side-of-the-moon.jpg", - LastPlayedOnUtc: new DateTime(2026, 10, 20, 18, 30, 0, DateTimeKind.Utc), - PlayCount: 12, - CompletedPlayCount: 9, - ListenedDurationInSeconds: 4230.5) - ], - CurrentPage = 1, - PerPage = 50, - Count = 1, - NumberOfPages = 1 - } - ); - - Response(401, "Authentication required.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "Authentication failed", - instance = "/api/v1/users/me/music-play-history/most-played" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token has expired", - instance = "/api/v1/users/me/music-play-history/most-played" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token is invalid", - instance = "/api/v1/users/me/music-play-history/most-played" - } - } - ); - - Response(403, "The request failed because the authenticated request does not carry the identity of a user.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.4", - title = "General.Unauthorized", - status = 403, - detail = "NotAuthorized", - instance = "/api/v1/users/me/music-play-history/most-played", - traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" - } - ); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMusicPlayStatistics/GetMusicPlayStatisticsEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMusicPlayStatistics/GetMusicPlayStatisticsEndpoint.cs deleted file mode 100644 index c0b1a37f..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMusicPlayStatistics/GetMusicPlayStatisticsEndpoint.cs +++ /dev/null @@ -1,60 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Application.Common.CQRS; -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetMusicPlayStatistics; -using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Domain.Common.Primitives; -using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; -using Lumina.Presentation.Api.Core.Endpoints.Common; -using Microsoft.AspNetCore.Http; -using System.Threading; -using System.Threading.Tasks; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetMusicPlayStatistics; - -/// -/// API endpoint for the /users/me/music-play-history/statistics route. -/// -/// -/// Uses "me" because it is always for the currently authenticated user. -/// -public class GetMusicPlayStatisticsEndpoint : BaseEndpoint -{ - private readonly IQueryHandler> _getMusicPlayStatisticsQueryHandler; - - /// - /// Initializes a new instance of the class. - /// - /// Injected service for handling get music play statistics queries. - public GetMusicPlayStatisticsEndpoint(IQueryHandler> getMusicPlayStatisticsQueryHandler) - { - _getMusicPlayStatisticsQueryHandler = getMusicPlayStatisticsQueryHandler; - } - - /// - /// Configures the API endpoint. - /// - public override void Configure() - { - Verbs(Http.GET); - Routes(ApiRoutes.PlayStatistics.GET_MUSIC_PLAY_STATISTICS); - Version(1); - DontCatchExceptions(); - } - - /// - /// Gets the listening statistics of the current user. - /// - /// The request object. - /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken) - { - // The statistics belong to the authenticated user, so no intermediary may store any response of this route, including its problem - // responses, and every response varies by the bearer token that authorized it. - HttpContext.Response.Headers["Cache-Control"] = "private, no-store"; - HttpContext.Response.Headers["Vary"] = "Authorization"; - Result result = await _getMusicPlayStatisticsQueryHandler.HandleAsync(new GetMusicPlayStatisticsQuery(), cancellationToken).ConfigureAwait(false); - return result.Match(success => TypedResults.Ok(success), Problem); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMusicPlayStatistics/GetMusicPlayStatisticsEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMusicPlayStatistics/GetMusicPlayStatisticsEndpointSummary.cs deleted file mode 100644 index be947cdb..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetMusicPlayStatistics/GetMusicPlayStatisticsEndpointSummary.cs +++ /dev/null @@ -1,80 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using System.Diagnostics.CodeAnalysis; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetMusicPlayStatistics; - -/// -/// Class used for providing a textual description for the API endpoint, for OpenAPI. -/// -[ExcludeFromCodeCoverage] -public class GetMusicPlayStatisticsEndpointSummary : Summary -{ - /// - /// Initializes a new instance of the class. - /// - public GetMusicPlayStatisticsEndpointSummary() - { - Summary = "Gets the listening statistics of the current user."; - Description = "Gets the total listening time, the number of plays that count as plays, the number of completed plays, the number of stopped plays that count and the completion rate of the current user. A play counts when it completed or when the listened duration reached 30 seconds, and the total listening time includes the listened duration of every recorded play. A play that is still in progress counts once it reaches the threshold, so the counted total can exceed the completed and stopped plays together. The statistics are aggregated over the plays of the authenticated user, so the response is private to that user."; - - ResponseParam(response => response.TotalListeningDurationInSeconds, "The total duration the user listened to, over every recorded play, in seconds."); - ResponseParam(response => response.TotalPlayCount, "The number of recorded plays that count as plays. It includes an in-progress play that has already reached the threshold, so it need not equal the completed and stopped plays together."); - ResponseParam(response => response.CompletedPlayCount, "The number of recorded plays that completed."); - ResponseParam(response => response.StoppedPlayCount, "The number of recorded plays that stopped before the track completed and count as plays."); - ResponseParam(response => response.CompletionRate, "The fraction of the counted plays that completed, between 0 and 1, or 0 when there is no counted play."); - - Response(200, "The listening statistics of the current user are returned.", - example: new MusicPlayStatisticsResponse( - TotalListeningDurationInSeconds: 93840.5, - TotalPlayCount: 512, - CompletedPlayCount: 388, - StoppedPlayCount: 124, - CompletionRate: 0.7578125) - ); - - Response(401, "Authentication required.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "Authentication failed", - instance = "/api/v1/users/me/music-play-history/statistics" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token has expired", - instance = "/api/v1/users/me/music-play-history/statistics" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token is invalid", - instance = "/api/v1/users/me/music-play-history/statistics" - } - } - ); - - Response(403, "The request failed because the authenticated request does not carry the identity of a user.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.4", - title = "General.Unauthorized", - status = 403, - detail = "NotAuthorized", - instance = "/api/v1/users/me/music-play-history/statistics", - traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" - } - ); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetPlayRecord/GetPlayRecordEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetPlayRecord/GetPlayRecordEndpoint.cs deleted file mode 100644 index 54f77709..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetPlayRecord/GetPlayRecordEndpoint.cs +++ /dev/null @@ -1,62 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Application.Common.CQRS; -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetPlayRecord; -using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Domain.Common.Primitives; -using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; -using Lumina.Presentation.Api.Core.Endpoints.Common; -using Microsoft.AspNetCore.Http; -using System.Threading; -using System.Threading.Tasks; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetPlayRecord; - -/// -/// API endpoint for the /users/me/music-play-history/plays/{playRecordId} route. -/// -/// -/// Uses "me" because it is always for the currently authenticated user. -/// -public class GetPlayRecordEndpoint : BaseEndpoint -{ - private readonly IQueryHandler> _getPlayRecordQueryHandler; - - /// - /// Initializes a new instance of the class. - /// - /// Injected service for handling get play record queries. - public GetPlayRecordEndpoint(IQueryHandler> getPlayRecordQueryHandler) - { - _getPlayRecordQueryHandler = getPlayRecordQueryHandler; - } - - /// - /// Configures the API endpoint. - /// - public override void Configure() - { - Verbs(Http.GET); - Routes(ApiRoutes.PlayHistory.GET_PLAY); - Version(1); - DontCatchExceptions(); - } - - /// - /// Gets a recorded play of a track by the current user. - /// - /// The request object. - /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken) - { - // The play record belongs to the authenticated user, so no intermediary may store any response of this route, including its problem - // responses, and every response varies by the bearer token that authorized it. - HttpContext.Response.Headers["Cache-Control"] = "private, no-store"; - HttpContext.Response.Headers["Vary"] = "Authorization"; - // Take the unique identifier from the route. - string? playRecordId = HttpContext.Request.RouteValues["playRecordId"]?.ToString(); - Result result = await _getPlayRecordQueryHandler.HandleAsync(new GetPlayRecordQuery(playRecordId), cancellationToken).ConfigureAwait(false); - return result.Match(success => TypedResults.Ok(success), Problem); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetPlayRecord/GetPlayRecordEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetPlayRecord/GetPlayRecordEndpointSummary.cs deleted file mode 100644 index 7d8c142f..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetPlayRecord/GetPlayRecordEndpointSummary.cs +++ /dev/null @@ -1,117 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Domain.SharedKernel.Common.Enums.Playback; -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetPlayRecord; - -/// -/// Class used for providing a textual description for the API endpoint, for OpenAPI. -/// -[ExcludeFromCodeCoverage] -public class GetPlayRecordEndpointSummary : Summary -{ - /// - /// Initializes a new instance of the class. - /// - public GetPlayRecordEndpointSummary() - { - Summary = "Retrieves a recorded play of a track by the current user."; - Description = "Retrieves the play record identified by the route, when it belongs to the current user. The record carries the last reported position, the listened duration and whether the play is in progress, completed or stopped. It never carries a queue, a current index, a repeat or shuffle state, or a playback session."; - - ResponseParam(r => r.Id, "The Id of the play record."); - ResponseParam(r => r.TrackId, "The Id of the track that was played."); - ResponseParam(r => r.LibraryId, "The Id of the media library that contains the track."); - ResponseParam(r => r.AlbumId, "The Id of the album that contains the track."); - ResponseParam(r => r.ArtistId, "The Id of the artist that produced the track."); - ResponseParam(r => r.Status, "The state of the recorded play."); - ResponseParam(r => r.LastPositionInSeconds, "The last position reported by the player, in seconds."); - ResponseParam(r => r.ListenedDurationInSeconds, "The duration the user has listened to, in seconds."); - ResponseParam(r => r.StartedOnUtc, "The date and time when the play started."); - ResponseParam(r => r.EndedOnUtc, "The date and time when the play completed or stopped, if it has ended."); - ResponseParam(r => r.UpdatedOnUtc, "The date and time when the play record was last updated, if applicable."); - - Response(200, "The play record is returned.", - example: new PlayRecordResponse( - Id: Guid.Parse("2c1b0a9f-8e7d-4c6b-5a4f-3e2d1c0b9a8f"), - TrackId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"), - LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"), - AlbumId: Guid.Parse("e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f"), - ArtistId: Guid.Parse("d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a"), - Status: PlaybackRecordStatus.Stopped, - LastPositionInSeconds: 92.5, - ListenedDurationInSeconds: 92.5, - StartedOnUtc: new DateTime(2026, 10, 19, 12, 0, 0, DateTimeKind.Utc), - EndedOnUtc: new DateTime(2026, 10, 19, 12, 1, 32, 500, DateTimeKind.Utc), - UpdatedOnUtc: new DateTime(2026, 10, 19, 12, 1, 32, 500, DateTimeKind.Utc) - ) - ); - - Response(401, "Authentication required.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "Authentication failed", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token has expired", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token is invalid", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}" - } - } - ); - - Response(404, "The request failed because the play record does not exist, or it does not belong to the current user.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.5", - title = "General.NotFound", - status = 404, - detail = "MusicPlayRecordNotFound", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}", - traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00" - } - ); - - Response(422, "The request did not pass validation checks.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc4918#section-11.2", - title = "General.Validation", - status = 422, - detail = "OneOrMoreValidationErrorsOccurred", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}", - errors = new Dictionary - { - { - "General.Validation", new[] - { - "PlayRecordIdCannotBeEmpty" - } - } - }, - traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00" - } - ); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayed/GetRecentlyPlayedEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayed/GetRecentlyPlayedEndpoint.cs deleted file mode 100644 index d4494435..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayed/GetRecentlyPlayedEndpoint.cs +++ /dev/null @@ -1,63 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Application.Common.CQRS; -using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetRecentlyPlayed; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Contracts.Responses.Common; -using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Domain.Common.Primitives; -using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; -using Lumina.Presentation.Api.Core.Endpoints.Common; -using Microsoft.AspNetCore.Http; -using System.Threading; -using System.Threading.Tasks; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetRecentlyPlayed; - -/// -/// API endpoint for the /users/me/music-play-history/recently-played route. -/// -/// -/// Uses "me" because it is always for the currently authenticated user. -/// -public class GetRecentlyPlayedEndpoint : BaseEndpoint -{ - private readonly IQueryHandler>> _getRecentlyPlayedQueryHandler; - - /// - /// Initializes a new instance of the class. - /// - /// Injected service for handling get recently played queries. - public GetRecentlyPlayedEndpoint(IQueryHandler>> getRecentlyPlayedQueryHandler) - { - _getRecentlyPlayedQueryHandler = getRecentlyPlayedQueryHandler; - } - - /// - /// Configures the API endpoint. - /// - public override void Configure() - { - Verbs(Http.GET); - Routes(ApiRoutes.PlayStatistics.GET_RECENTLY_PLAYED); - Version(1); - DontCatchExceptions(); - } - - /// - /// Gets the recently played tracks of the current user. - /// - /// The request containing the optional page bounds. - /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(GetRecentlyPlayedRequest request, CancellationToken cancellationToken) - { - // The statistics belong to the authenticated user, so no intermediary may store any response of this route, including its problem - // responses, and every response varies by the bearer token that authorized it. - HttpContext.Response.Headers["Cache-Control"] = "private, no-store"; - HttpContext.Response.Headers["Vary"] = "Authorization"; - Result> result = await _getRecentlyPlayedQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false); - return result.Match(success => TypedResults.Ok(success), Problem); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayed/GetRecentlyPlayedEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayed/GetRecentlyPlayedEndpointSummary.cs deleted file mode 100644 index c335be2e..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/GetRecentlyPlayed/GetRecentlyPlayedEndpointSummary.cs +++ /dev/null @@ -1,116 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Contracts.Responses.Common; -using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using System; -using System.Diagnostics.CodeAnalysis; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetRecentlyPlayed; - -/// -/// Class used for providing a textual description for the API endpoint, for OpenAPI. -/// -[ExcludeFromCodeCoverage] -public class GetRecentlyPlayedEndpointSummary : Summary -{ - /// - /// Initializes a new instance of the class. - /// - public GetRecentlyPlayedEndpointSummary() - { - Summary = "Gets the recently played tracks of the current user."; - Description = "Gets the tracks the current user played recently, from the most recently played. Only the plays that count as plays are included: a play counts when it completed or when the listened duration reached 30 seconds. Each track is returned once, with its last activity time, its counted plays, its completed plays and the duration the user listened to it. A track deleted from its library keeps its row, without display data. The response is private to the authenticated user."; - - ExampleRequest = new GetRecentlyPlayedRequest(CurrentPage: 1, PerPage: 50); - RequestParam(request => request.CurrentPage, "The one based page of tracks to return. Optional. Defaults to 1."); - RequestParam(request => request.PerPage, "The number of tracks per page. Optional. Defaults to 50. When both pagination parameters are omitted, every matching track is returned."); - - ResponseParam>(response => response.Data, "The recently played tracks of the requested page, from the most recently played."); - ResponseParam>(response => response.CurrentPage, "The current page number."); - ResponseParam>(response => response.PerPage, "The number of tracks retrieved per page."); - ResponseParam>(response => response.Count, "The total number of tracks that match the filters."); - ResponseParam>(response => response.NumberOfPages, "The total number of pages."); - ResponseParam(response => response.TrackId, "The Id of the track."); - ResponseParam(response => response.LibraryId, "The Id of the media library that contains the track."); - ResponseParam(response => response.AlbumId, "The Id of the album that contains the track."); - ResponseParam(response => response.ArtistId, "The Id of the artist that produced the track."); - ResponseParam(response => response.Title, "The title of the track, if it still exists and the user can access its library."); - ResponseParam(response => response.AlbumTitle, "The title of the album that contains the track, if available."); - ResponseParam(response => response.ArtistName, "The name of the artist that produced the track, if available."); - ResponseParam(response => response.CoverPath, "The path of the cover art of the album, if available."); - ResponseParam(response => response.LastPlayedOnUtc, "The date and time of the last recorded activity of the track's most recent play."); - ResponseParam(response => response.PlayCount, "The number of plays of the track that count as plays."); - ResponseParam(response => response.CompletedPlayCount, "The number of plays of the track that completed."); - ResponseParam(response => response.ListenedDurationInSeconds, "The duration the user listened to the track, over all of its counted plays, in seconds."); - - Response(200, "The requested page of recently played tracks is returned.", - example: new PaginatedResponse - { - Data = - [ - new PlayedTrackResponse( - TrackId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"), - LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"), - AlbumId: Guid.Parse("e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f"), - ArtistId: Guid.Parse("d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a"), - Title: "Time", - AlbumTitle: "The Dark Side of the Moon", - ArtistName: "Pink Floyd", - CoverPath: "covers/dark-side-of-the-moon.jpg", - LastPlayedOnUtc: new DateTime(2026, 10, 20, 18, 30, 0, DateTimeKind.Utc), - PlayCount: 12, - CompletedPlayCount: 9, - ListenedDurationInSeconds: 4230.5) - ], - CurrentPage = 1, - PerPage = 50, - Count = 1, - NumberOfPages = 1 - } - ); - - Response(401, "Authentication required.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "Authentication failed", - instance = "/api/v1/users/me/music-play-history/recently-played" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token has expired", - instance = "/api/v1/users/me/music-play-history/recently-played" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token is invalid", - instance = "/api/v1/users/me/music-play-history/recently-played" - } - } - ); - - Response(403, "The request failed because the authenticated request does not carry the identity of a user.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.4", - title = "General.Unauthorized", - status = 403, - detail = "NotAuthorized", - instance = "/api/v1/users/me/music-play-history/recently-played", - traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" - } - ); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgress/ReportPlayProgressEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgress/ReportPlayProgressEndpoint.cs deleted file mode 100644 index 68c0efb1..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgress/ReportPlayProgressEndpoint.cs +++ /dev/null @@ -1,58 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.CQRS; -using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.ReportPlayProgress; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Domain.Common.Primitives; -using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; -using Lumina.Presentation.Api.Core.Endpoints.Common; -using Microsoft.AspNetCore.Http; -using System.Threading; -using System.Threading.Tasks; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.ReportPlayProgress; - -/// -/// API endpoint for the /users/me/music-play-history/plays/{playRecordId}/progress route. -/// -/// -/// Uses "me" because it is always for the currently authenticated user. -/// -public class ReportPlayProgressEndpoint : BaseEndpoint -{ - private readonly ICommandHandler> _reportPlayProgressCommandHandler; - - /// - /// Initializes a new instance of the class. - /// - /// Injected service for handling report play progress commands. - public ReportPlayProgressEndpoint(ICommandHandler> reportPlayProgressCommandHandler) - { - _reportPlayProgressCommandHandler = reportPlayProgressCommandHandler; - } - - /// - /// Configures the API endpoint. - /// - public override void Configure() - { - Verbs(FastEndpoints.Http.PUT); - Routes(ApiRoutes.PlayHistory.REPORT_PLAY_PROGRESS); - Version(1); - DontCatchExceptions(); - } - - /// - /// Reports the progress of a play of a track by the current user. - /// - /// The request containing the last position and the listened duration. - /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(ReportPlayProgressRequest request, CancellationToken cancellationToken) - { - // Take the unique identifier from the route. - string? playRecordId = HttpContext.Request.RouteValues["playRecordId"]?.ToString(); - Result result = await _reportPlayProgressCommandHandler.HandleAsync(request.ToCommand(playRecordId), cancellationToken).ConfigureAwait(false); - return result.Match(success => TypedResults.Ok(success), Problem); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgress/ReportPlayProgressEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgress/ReportPlayProgressEndpointSummary.cs deleted file mode 100644 index 9e474de6..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/ReportPlayProgress/ReportPlayProgressEndpointSummary.cs +++ /dev/null @@ -1,129 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.ReportPlayProgress; - -/// -/// Class used for providing a textual description for the API endpoint, for OpenAPI. -/// -[ExcludeFromCodeCoverage] -public class ReportPlayProgressEndpointSummary : Summary -{ - /// - /// Initializes a new instance of the class. - /// - public ReportPlayProgressEndpointSummary() - { - Summary = "Reports the progress of a play of a track by the current user."; - Description = "Reports the last position and the listened duration of a play of a track by the current user. Only an in-progress play of the current user can be progressed, and the listened duration can never decrease. The reports are stored so that the play history, statistics and recommendations can be built from them."; - - ExampleRequest = new ReportPlayProgressRequest( - PositionInSeconds: 92.5, - ListenedDurationInSeconds: 92.5 - ); - - RequestParam(request => request.PositionInSeconds, "The last position reported by the player, in seconds. Required."); - RequestParam(request => request.ListenedDurationInSeconds, "The duration the user has listened to, in seconds. Required."); - - Response(200, "The progress of the play was reported.", example: new { }); - - Response(401, "Authentication required.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "Authentication failed", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/progress" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token has expired", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/progress" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token is invalid", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/progress" - } - } - ); - - Response(404, "The request failed because the play record does not exist, or it does not belong to the current user.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.5", - title = "General.NotFound", - status = 404, - detail = "MusicPlayRecordNotFound", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/progress", - traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00" - } - ); - - Response(409, "The request failed because the play is not in progress anymore, or because another report changed it after this request read it.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.10", - title = "General.Conflict", - status = 409, - detail = "PlayIsNotInProgress", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/progress", - traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" - }, - new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.10", - title = "General.Conflict", - status = 409, - detail = "ConcurrencyConflict", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/progress", - traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" - } - } - ); - - Response(422, "The request did not pass validation checks.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc4918#section-11.2", - title = "General.Validation", - status = 422, - detail = "OneOrMoreValidationErrorsOccurred", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/progress", - errors = new Dictionary - { - { - "General.Validation", new[] - { - "PlayRecordIdCannotBeEmpty", - "PlaybackPositionCannotBeNull", - "PlaybackPositionMustBeNonNegative", - "PlaybackPositionIsOutOfRange", - "ListenedDurationCannotBeNull", - "ListenedDurationMustBeNonNegative", - "ListenedDurationIsOutOfRange", - "ListenedDurationCannotDecrease" - } - } - }, - traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00" - } - ); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StartPlay/StartPlayEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StartPlay/StartPlayEndpoint.cs deleted file mode 100644 index 98c81567..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StartPlay/StartPlayEndpoint.cs +++ /dev/null @@ -1,58 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.CQRS; -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StartPlay; -using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Domain.Common.Primitives; -using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; -using Lumina.Presentation.Api.Core.Endpoints.Common; -using Microsoft.AspNetCore.Http; -using System.Threading; -using System.Threading.Tasks; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.StartPlay; - -/// -/// API endpoint for the /libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/plays route. -/// -public class StartPlayEndpoint : BaseEndpoint -{ - private readonly ICommandHandler> _startPlayCommandHandler; - - /// - /// Initializes a new instance of the class. - /// - /// Injected service for handling start play commands. - public StartPlayEndpoint(ICommandHandler> startPlayCommandHandler) - { - _startPlayCommandHandler = startPlayCommandHandler; - } - - /// - /// Configures the API endpoint. - /// - public override void Configure() - { - Verbs(FastEndpoints.Http.POST); - Routes(ApiRoutes.PlayHistory.START_PLAY); - Version(1); - DontCatchExceptions(); - } - - /// - /// Records the start of a play of a track by the current user. - /// - /// The request object. - /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken) - { - // Take the unique identifiers from the route, so that they cannot be replaced by values posted in a body. - string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString(); - string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString(); - string? albumId = HttpContext.Request.RouteValues["albumId"]?.ToString(); - string? trackId = HttpContext.Request.RouteValues["trackId"]?.ToString(); - Result result = await _startPlayCommandHandler - .HandleAsync(new StartPlayCommand(libraryId, artistId, albumId, trackId), cancellationToken).ConfigureAwait(false); - return result.Match(success => TypedResults.Ok(success), Problem); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StartPlay/StartPlayEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StartPlay/StartPlayEndpointSummary.cs deleted file mode 100644 index 228bbd60..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StartPlay/StartPlayEndpointSummary.cs +++ /dev/null @@ -1,144 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Domain.SharedKernel.Common.Enums.Playback; -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.StartPlay; - -/// -/// Class used for providing a textual description for the API endpoint, for OpenAPI. -/// -[ExcludeFromCodeCoverage] -public class StartPlayEndpointSummary : Summary -{ - /// - /// Initializes a new instance of the class. - /// - public StartPlayEndpointSummary() - { - Summary = "Records the start of a play of a track by the current user."; - Description = "Records the start of a play of a track by the current user, so that the play history, statistics and recommendations can be built from it. The track must belong to the named library, album and artist. The play record is returned with its identifier, which the player uses to report its progress, completion or stop. The play record belongs to the current user, and it never stores a queue, a current index, a repeat or shuffle state, or a playback session."; - - ResponseParam(r => r.Id, "The Id of the play record."); - ResponseParam(r => r.TrackId, "The Id of the track that was played."); - ResponseParam(r => r.LibraryId, "The Id of the media library that contains the track."); - ResponseParam(r => r.AlbumId, "The Id of the album that contains the track."); - ResponseParam(r => r.ArtistId, "The Id of the artist that produced the track."); - ResponseParam(r => r.Status, "The state of the recorded play."); - ResponseParam(r => r.LastPositionInSeconds, "The last position reported by the player, in seconds."); - ResponseParam(r => r.ListenedDurationInSeconds, "The duration the user has listened to, in seconds."); - ResponseParam(r => r.StartedOnUtc, "The date and time when the play started."); - ResponseParam(r => r.EndedOnUtc, "The date and time when the play completed or stopped, if it has ended."); - ResponseParam(r => r.UpdatedOnUtc, "The date and time when the play record was last updated, if applicable."); - - Response(200, "The play was recorded and its play record is returned.", - example: new PlayRecordResponse( - Id: Guid.Parse("2c1b0a9f-8e7d-4c6b-5a4f-3e2d1c0b9a8f"), - TrackId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"), - LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"), - AlbumId: Guid.Parse("e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f"), - ArtistId: Guid.Parse("d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a"), - Status: PlaybackRecordStatus.InProgress, - LastPositionInSeconds: 0, - ListenedDurationInSeconds: 0, - StartedOnUtc: new DateTime(2026, 10, 19, 12, 0, 0, DateTimeKind.Utc), - EndedOnUtc: null, - UpdatedOnUtc: null - ) - ); - - Response(401, "Authentication required.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "Authentication failed", - instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token has expired", - instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token is invalid", - instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays" - } - } - ); - - Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.4", - title = "General.Unauthorized", - status = 403, - detail = "NotAuthorized", - instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays", - traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" - } - ); - - Response(404, "The request failed because the album or the track does not exist, or they do not belong to the library, artist and album named by the request.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.5", - title = "General.NotFound", - status = 404, - detail = "AlbumNotFound", - instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays", - traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00" - }, - new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.5", - title = "General.NotFound", - status = 404, - detail = "TrackNotFound", - instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays", - traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00" - } - } - ); - - Response(422, "The request did not pass validation checks.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc4918#section-11.2", - title = "General.Validation", - status = 422, - detail = "OneOrMoreValidationErrorsOccurred", - instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays", - errors = new Dictionary - { - { - "General.Validation", new[] - { - "LibraryIdCannotBeEmpty", - "ArtistIdCannotBeEmpty", - "AlbumIdCannotBeEmpty", - "TrackIdCannotBeEmpty" - } - } - }, - traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00" - } - ); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StopPlay/StopPlayEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StopPlay/StopPlayEndpoint.cs deleted file mode 100644 index 755f3cb5..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StopPlay/StopPlayEndpoint.cs +++ /dev/null @@ -1,58 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.CQRS; -using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StopPlay; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using Lumina.Domain.Common.Primitives; -using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; -using Lumina.Presentation.Api.Core.Endpoints.Common; -using Microsoft.AspNetCore.Http; -using System.Threading; -using System.Threading.Tasks; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.StopPlay; - -/// -/// API endpoint for the /users/me/music-play-history/plays/{playRecordId}/stop route. -/// -/// -/// Uses "me" because it is always for the currently authenticated user. -/// -public class StopPlayEndpoint : BaseEndpoint -{ - private readonly ICommandHandler> _stopPlayCommandHandler; - - /// - /// Initializes a new instance of the class. - /// - /// Injected service for handling stop play commands. - public StopPlayEndpoint(ICommandHandler> stopPlayCommandHandler) - { - _stopPlayCommandHandler = stopPlayCommandHandler; - } - - /// - /// Configures the API endpoint. - /// - public override void Configure() - { - Verbs(FastEndpoints.Http.PUT); - Routes(ApiRoutes.PlayHistory.STOP_PLAY); - Version(1); - DontCatchExceptions(); - } - - /// - /// Reports that a play of a track by the current user stopped before the track completed. - /// - /// The request containing the last position and the listened duration. - /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(StopPlayRequest request, CancellationToken cancellationToken) - { - // Take the unique identifier from the route. - string? playRecordId = HttpContext.Request.RouteValues["playRecordId"]?.ToString(); - Result result = await _stopPlayCommandHandler.HandleAsync(request.ToCommand(playRecordId), cancellationToken).ConfigureAwait(false); - return result.Match(success => TypedResults.Ok(success), Problem); - } -} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StopPlay/StopPlayEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StopPlay/StopPlayEndpointSummary.cs deleted file mode 100644 index 06d252d8..00000000 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/PlayHistory/StopPlay/StopPlayEndpointSummary.cs +++ /dev/null @@ -1,129 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using FastEndpoints; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory; -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -#endregion - -namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.StopPlay; - -/// -/// Class used for providing a textual description for the API endpoint, for OpenAPI. -/// -[ExcludeFromCodeCoverage] -public class StopPlayEndpointSummary : Summary -{ - /// - /// Initializes a new instance of the class. - /// - public StopPlayEndpointSummary() - { - Summary = "Reports that a play of a track by the current user stopped before the track completed."; - Description = "Reports that a play of a track by the current user stopped before the track completed, together with the last position and the listened duration. Only an in-progress play of the current user can be stopped, and the listened duration can never decrease. The reports are stored so that the play history, statistics and recommendations can be built from them."; - - ExampleRequest = new StopPlayRequest( - PositionInSeconds: 92.5, - ListenedDurationInSeconds: 92.5 - ); - - RequestParam(request => request.PositionInSeconds, "The last position reported by the player, in seconds. Required."); - RequestParam(request => request.ListenedDurationInSeconds, "The duration the user listened to, in seconds. Required."); - - Response(200, "The stop of the play was reported.", example: new { }); - - Response(401, "Authentication required.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "Authentication failed", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/stop" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token has expired", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/stop" - }, - new - { - type = "https://tools.ietf.org/html/rfc7235#section-3.1", - status = 401, - title = "Unauthorized", - detail = "The token is invalid", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/stop" - } - } - ); - - Response(404, "The request failed because the play record does not exist, or it does not belong to the current user.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.5", - title = "General.NotFound", - status = 404, - detail = "MusicPlayRecordNotFound", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/stop", - traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00" - } - ); - - Response(409, "The request failed because the play is not in progress anymore, or because another report changed it after this request read it.", "application/problem+json", - example: new[] - { - new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.10", - title = "General.Conflict", - status = 409, - detail = "PlayIsNotInProgress", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/stop", - traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" - }, - new - { - type = "https://tools.ietf.org/html/rfc9110#section-15.5.10", - title = "General.Conflict", - status = 409, - detail = "ConcurrencyConflict", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/stop", - traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00" - } - } - ); - - Response(422, "The request did not pass validation checks.", "application/problem+json", - example: new - { - type = "https://tools.ietf.org/html/rfc4918#section-11.2", - title = "General.Validation", - status = 422, - detail = "OneOrMoreValidationErrorsOccurred", - instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/stop", - errors = new Dictionary - { - { - "General.Validation", new[] - { - "PlayRecordIdCannotBeEmpty", - "PlaybackPositionCannotBeNull", - "PlaybackPositionMustBeNonNegative", - "PlaybackPositionIsOutOfRange", - "ListenedDurationCannotBeNull", - "ListenedDurationMustBeNonNegative", - "ListenedDurationIsOutOfRange", - "ListenedDurationCannotDecrease" - } - } - }, - traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00" - } - ); - } -} diff --git a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs index e635d03c..7c48b83c 100644 --- a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs +++ b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs @@ -48,7 +48,7 @@ public class LuminaDbContextTests : IDisposable // Assert // The count assertion fails when a table is added or removed, reminding to update the assertions below. - Assert.Equal(67, tableNames.Length); + Assert.Equal(66, tableNames.Length); Assert.Contains("Books", tableNames); Assert.Contains("Users", tableNames); Assert.Contains("UserSettings", tableNames); @@ -108,7 +108,7 @@ public class LuminaDbContextTests : IDisposable Assert.Contains("AlbumContributors", tableNames); Assert.Contains("MusicArtwork", tableNames); Assert.Contains("MusicLibraryScanItemMetadata", tableNames); - Assert.Contains("MusicPlayRecords", tableNames); + Assert.DoesNotContain("MusicPlayRecords", tableNames); Assert.Contains("MediaConsumptionRecords", tableNames); Assert.Contains("MediaResumePoints", tableNames); Assert.Contains("Playlists", tableNames);