mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Removes the old music play history surface and drops its table
This commit is contained in:
1 parent
0b5b65391c
commit
bc619679e8
83 files changed
+3955
-4893
No files matched your search
-22
@@ -1,22 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the listening statistics of the current user.
|
||||
/// </summary>
|
||||
/// <param name="TotalListeningDurationMilliseconds">The total duration the user listened to, over every recorded play, in milliseconds.</param>
|
||||
/// <param name="TotalPlayCount">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.</param>
|
||||
/// <param name="CompletedPlayCount">The number of recorded plays that completed.</param>
|
||||
/// <param name="StoppedPlayCount">The number of recorded plays that stopped before the track completed and count as plays.</param>
|
||||
/// <param name="CompletionRate">The fraction of the plays that count as plays that completed, between 0 and 1, or 0 when there is no counted play.</param>
|
||||
[DebuggerDisplay("TotalPlayCount: {TotalPlayCount}; CompletedPlayCount: {CompletedPlayCount}")]
|
||||
public sealed record MusicPlayStatisticsDto(
|
||||
long TotalListeningDurationMilliseconds,
|
||||
int TotalPlayCount,
|
||||
int CompletedPlayCount,
|
||||
int StoppedPlayCount,
|
||||
double CompletionRate
|
||||
);
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a track of the listening statistics of the current user, together with its aggregated play counts.
|
||||
/// </summary>
|
||||
/// <param name="TrackId">The Id of the track.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the track.</param>
|
||||
/// <param name="AlbumId">The Id of the album that contains the track.</param>
|
||||
/// <param name="ArtistId">The Id of the artist that produced the track.</param>
|
||||
/// <param name="Title">The title of the track, if it still exists and the user can access its library.</param>
|
||||
/// <param name="AlbumTitle">The title of the album that contains the track, if it still exists and the user can access its library.</param>
|
||||
/// <param name="ArtistName">The name of the artist that produced the track, if it still exists and the user can access its library.</param>
|
||||
/// <param name="CoverPath">The path of the cover art of the album, if available.</param>
|
||||
/// <param name="LastPlayedOnUtc">The date and time of the last recorded activity of the track's most recent play.</param>
|
||||
/// <param name="PlayCount">The number of plays of the track that count as plays.</param>
|
||||
/// <param name="CompletedPlayCount">The number of plays of the track that completed.</param>
|
||||
/// <param name="ListenedDurationMilliseconds">The duration the user listened to the track, over all of its counted plays, in milliseconds.</param>
|
||||
[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
|
||||
);
|
||||
-93
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for a recorded play of a track.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Id: {Id}; TrackId: {TrackId}; Status: {Status}")]
|
||||
public class MusicPlayRecordEntity : IStorageEntity, IAuditableEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the play record.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that started the play.
|
||||
/// </summary>
|
||||
public required Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the track that was played.
|
||||
/// </summary>
|
||||
public required Guid TrackId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the media library that contains the track.
|
||||
/// </summary>
|
||||
public required Guid LibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the album that contains the track.
|
||||
/// </summary>
|
||||
public required Guid AlbumId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the artist that produced the track.
|
||||
/// </summary>
|
||||
public required Guid ArtistId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the state of the recorded play.
|
||||
/// </summary>
|
||||
public PlaybackRecordStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the last position reported by the player, in milliseconds. It is stored as a whole number of milliseconds so that the
|
||||
/// stored value is independent of the persistence medium's support for time values.
|
||||
/// </summary>
|
||||
public long LastPositionMilliseconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the duration the user has listened to, in milliseconds. It is stored as a whole number of milliseconds so that the
|
||||
/// stored value is independent of the persistence medium's support for time values.
|
||||
/// </summary>
|
||||
public long ListenedDurationMilliseconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the play completed or stopped, if it has ended.
|
||||
/// </summary>
|
||||
public DateTime? EndedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the version of the stored row. It is used as an optimistic concurrency token, so that a report that read the play
|
||||
/// before another report ended it can never overwrite the newer state.
|
||||
/// </summary>
|
||||
public long Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added. It is also the date and time when the play started.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
-50
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the repository for recorded music plays.
|
||||
/// </summary>
|
||||
public interface IMusicPlayRecordRepository : IRepository<MusicPlayRecordEntity>,
|
||||
IInsertRepositoryAction<MusicPlayRecordEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the play record identified by <paramref name="id"/> when it belongs to the user identified by <paramref name="userId"/>, if it exists.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the play record to get.</param>
|
||||
/// <param name="userId">The Id of the user the play record must belong to.</param>
|
||||
/// <param name="shouldTrackEntities">Whether the retrieved record should be tracked by the persistence medium, so that changes to it can be saved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the play record identified by <paramref name="id"/> and owned by <paramref name="userId"/>,
|
||||
/// <see langword="null"/> when no such record exists, or an error.
|
||||
/// </returns>
|
||||
Task<Result<MusicPlayRecordEntity?>> GetByIdForUserAsync(Guid id, Guid userId, bool shouldTrackEntities = true, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the play records of the user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user whose play records are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the play records of the user, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<MusicPlayRecordEntity>>> GetForUserAsync(Guid userId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the play record of the user identified by <paramref name="userId"/>, when the record belongs to that user and still holds the
|
||||
/// version it was read with.
|
||||
/// </summary>
|
||||
/// <param name="data">The play record whose editable values are applied to the stored record.</param>
|
||||
/// <param name="userId">The Id of the user the play record must belong to.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful update, or an error.</returns>
|
||||
Task<Result<Updated>> UpdateForUserAsync(MusicPlayRecordEntity data, Guid userId, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -153,11 +153,6 @@ public interface IUnitOfWork
|
||||
/// </summary>
|
||||
IUserSettingsRepository UserSettingsRepository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the music play record repository.
|
||||
/// </summary>
|
||||
IMusicPlayRecordRepository MusicPlayRecordRepository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the playlist repository.
|
||||
/// </summary>
|
||||
|
||||
-27
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="CompletePlayRequest"/>.
|
||||
/// </summary>
|
||||
public static class CompletePlayRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="CompletePlayCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="playRecordId">The Id of the play record, taken from the route.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static CompletePlayCommand ToCommand(this CompletePlayRequest request, string? playRecordId)
|
||||
{
|
||||
return new CompletePlayCommand(
|
||||
playRecordId,
|
||||
request.PositionInSeconds,
|
||||
request.ListenedDurationInSeconds
|
||||
);
|
||||
}
|
||||
}
|
||||
-31
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetMostPlayedRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetMostPlayedRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetMostPlayedQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
-31
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetRecentlyPlayedRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetRecentlyPlayedRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetRecentlyPlayedQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
-67
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicPlayRecordEntity"/>.
|
||||
/// </summary>
|
||||
public static class MusicPlayRecordEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="MusicPlayRecord"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="MusicPlayRecord"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicPlayRecord> 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<DateTime>.FromNullable(repositoryEntity.EndedOnUtc),
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
Optional<DateTime>.FromNullable(repositoryEntity.UpdatedOnUtc)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="PlayRecordResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
-43
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicPlayRecord"/>.
|
||||
/// </summary>
|
||||
public static class MusicPlayRecordMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="MusicPlayRecordEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
-29
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicPlayStatisticsDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicPlayStatisticsDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="MusicPlayStatisticsResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The listening statistics data to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static MusicPlayStatisticsResponse ToResponse(this MusicPlayStatisticsDto data)
|
||||
{
|
||||
return new MusicPlayStatisticsResponse(
|
||||
data.TotalListeningDurationMilliseconds.ToClampedTimeSpan().TotalSeconds,
|
||||
data.TotalPlayCount,
|
||||
data.CompletedPlayCount,
|
||||
data.StoppedPlayCount,
|
||||
data.CompletionRate
|
||||
);
|
||||
}
|
||||
}
|
||||
-59
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="PlayedTrackDto"/>.
|
||||
/// </summary>
|
||||
public static class PlayedTrackDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="PlayedTrackResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The played track data to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to a paginated collection of <see cref="PlayedTrackResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The paginated played track data to be converted.</param>
|
||||
/// <returns>The converted paginated responses.</returns>
|
||||
public static PaginatedResponse<PlayedTrackResponse> ToResponses(this PaginatedResultDto<PlayedTrackDto> data)
|
||||
{
|
||||
return new PaginatedResponse<PlayedTrackResponse>
|
||||
{
|
||||
Data = [.. data.Data.Select(track => track.ToResponse())],
|
||||
CurrentPage = data.CurrentPage,
|
||||
PerPage = data.PerPage,
|
||||
Count = data.Count,
|
||||
NumberOfPages = data.NumberOfPages
|
||||
};
|
||||
}
|
||||
}
|
||||
-27
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ReportPlayProgressRequest"/>.
|
||||
/// </summary>
|
||||
public static class ReportPlayProgressRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="ReportPlayProgressCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="playRecordId">The Id of the play record, taken from the route.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static ReportPlayProgressCommand ToCommand(this ReportPlayProgressRequest request, string? playRecordId)
|
||||
{
|
||||
return new ReportPlayProgressCommand(
|
||||
playRecordId,
|
||||
request.PositionInSeconds,
|
||||
request.ListenedDurationInSeconds
|
||||
);
|
||||
}
|
||||
}
|
||||
-27
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="StopPlayRequest"/>.
|
||||
/// </summary>
|
||||
public static class StopPlayRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="StopPlayCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="playRecordId">The Id of the play record, taken from the route.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static StopPlayCommand ToCommand(this StopPlayRequest request, string? playRecordId)
|
||||
{
|
||||
return new StopPlayCommand(
|
||||
playRecordId,
|
||||
request.PositionInSeconds,
|
||||
request.ListenedDurationInSeconds
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user