mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Adds playlist management and playback
This commit is contained in:
1 parent
009a0c8156
commit
9889c86c76
296 files changed
+18830
-367
No files matched your search
+14
-32
@@ -9,35 +9,17 @@ namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.A
|
||||
/// <summary>
|
||||
/// Lightweight read model of an album, containing only the fields needed to display the album in a card-based grid or a list.
|
||||
/// </summary>
|
||||
public sealed record AlbumLiteRow
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the album.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the album.
|
||||
/// </summary>
|
||||
public required string Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of tracks of the release.
|
||||
/// </summary>
|
||||
public int TotalTracks { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path of the image representing the album, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the release year of the album (the re-release year, if available, or the original release year), if known.
|
||||
/// </summary>
|
||||
public int? ReleaseYear { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set of types of the release.
|
||||
/// </summary>
|
||||
public List<MusicReleaseType>? ReleaseTypes { get; init; }
|
||||
}
|
||||
/// <param name="Id">The Id of the album.</param>
|
||||
/// <param name="Title">The title of the album.</param>
|
||||
/// <param name="TotalTracks">The number of tracks of the release.</param>
|
||||
/// <param name="CoverPath">The path of the image representing the album, if available.</param>
|
||||
/// <param name="ReleaseYear">The release year of the album (the re-release year, if available, or the original release year), if known.</param>
|
||||
/// <param name="ReleaseTypes">The set of types of the release.</param>
|
||||
public sealed record AlbumLiteRow(
|
||||
Guid Id,
|
||||
string Title,
|
||||
int TotalTracks,
|
||||
string? CoverPath,
|
||||
int? ReleaseYear,
|
||||
List<MusicReleaseType>? ReleaseTypes
|
||||
);
|
||||
+8
-17
@@ -7,20 +7,11 @@ namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.A
|
||||
/// <summary>
|
||||
/// Lightweight read model of an artist, containing only the fields needed to display the artist in a card-based grid or a list.
|
||||
/// </summary>
|
||||
public sealed record ArtistLiteRow
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the artist.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the artist.
|
||||
/// </summary>
|
||||
public required string Name { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path of the image representing the artist, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; init; }
|
||||
}
|
||||
/// <param name="Id">The Id of the artist.</param>
|
||||
/// <param name="Name">The name of the artist.</param>
|
||||
/// <param name="CoverPath">The path of the image representing the artist, if available.</param>
|
||||
public sealed record ArtistLiteRow(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string? CoverPath
|
||||
);
|
||||
+16
-37
@@ -7,40 +7,19 @@ namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.T
|
||||
/// <summary>
|
||||
/// Read model of a track returned by a randomized shuffle query, carrying everything the client needs to queue and play it.
|
||||
/// </summary>
|
||||
public sealed record ShuffleTrackRowDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the track.
|
||||
/// </summary>
|
||||
public required Guid TrackId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the track.
|
||||
/// </summary>
|
||||
public required string Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the duration of the track in seconds.
|
||||
/// </summary>
|
||||
public int DurationInSeconds { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the album the track belongs to.
|
||||
/// </summary>
|
||||
public required Guid AlbumId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the album the track belongs to.
|
||||
/// </summary>
|
||||
public required string AlbumTitle { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the artist the album belongs to.
|
||||
/// </summary>
|
||||
public required Guid ArtistId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path of the cover of the album, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; init; }
|
||||
}
|
||||
/// <param name="TrackId">The Id of the track.</param>
|
||||
/// <param name="Title">The title of the track.</param>
|
||||
/// <param name="DurationInSeconds">The duration of the track in seconds.</param>
|
||||
/// <param name="AlbumId">The Id of the album the track belongs to.</param>
|
||||
/// <param name="AlbumTitle">The title of the album the track belongs to.</param>
|
||||
/// <param name="ArtistId">The Id of the artist the album belongs to.</param>
|
||||
/// <param name="CoverPath">The path of the cover of the album, if available.</param>
|
||||
public sealed record ShuffleTrackRowDto(
|
||||
Guid TrackId,
|
||||
string Title,
|
||||
int DurationInSeconds,
|
||||
Guid AlbumId,
|
||||
string AlbumTitle,
|
||||
Guid ArtistId,
|
||||
string? CoverPath
|
||||
);
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the access information of a set of existing tracks.
|
||||
/// </summary>
|
||||
/// <param name="TrackCount">The number of distinct requested tracks that exist.</param>
|
||||
/// <param name="LibraryIds">The distinct Ids of the media libraries that contain those tracks.</param>
|
||||
[DebuggerDisplay("TrackCount: {TrackCount}; Libraries: {LibraryIds.Count}")]
|
||||
public sealed record TrackAccessSummaryDto(
|
||||
int TrackCount,
|
||||
IReadOnlyList<Guid> LibraryIds
|
||||
);
|
||||
+12
-27
@@ -7,30 +7,15 @@ namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.T
|
||||
/// <summary>
|
||||
/// Lightweight read model of a track, containing only the fields needed to display the track in a list.
|
||||
/// </summary>
|
||||
public sealed record TrackLiteRow
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the track.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the track.
|
||||
/// </summary>
|
||||
public required string Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of the track on its disc.
|
||||
/// </summary>
|
||||
public int TrackNumber { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of the disc the track belongs to, if applicable.
|
||||
/// </summary>
|
||||
public int? DiscNumber { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the duration of the track in seconds.
|
||||
/// </summary>
|
||||
public int DurationInSeconds { get; init; }
|
||||
}
|
||||
/// <param name="Id">The Id of the track.</param>
|
||||
/// <param name="Title">The title of the track.</param>
|
||||
/// <param name="TrackNumber">The number of the track on its disc.</param>
|
||||
/// <param name="DiscNumber">The number of the disc the track belongs to, if applicable.</param>
|
||||
/// <param name="DurationInSeconds">The duration of the track in seconds.</param>
|
||||
public sealed record TrackLiteRow(
|
||||
Guid Id,
|
||||
string Title,
|
||||
int TrackNumber,
|
||||
int? DiscNumber,
|
||||
int DurationInSeconds
|
||||
);
|
||||
+10
-22
@@ -7,25 +7,13 @@ namespace Lumina.Application.Common.DTO.MediaLibrary.WrittenContentLibrary.BookL
|
||||
/// <summary>
|
||||
/// Lightweight read model of a book, containing only the fields needed to display the book in a card-based grid or a list.
|
||||
/// </summary>
|
||||
public sealed record BookLiteRow
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the book.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the book.
|
||||
/// </summary>
|
||||
public required string Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the release year of the book (re-release year, if available, or original release year), if known.
|
||||
/// </summary>
|
||||
public int? ReleaseYear { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path of the image representing the cover of the book, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; init; }
|
||||
}
|
||||
/// <param name="Id">The Id of the book.</param>
|
||||
/// <param name="Title">The title of the book.</param>
|
||||
/// <param name="ReleaseYear">The release year of the book (re-release year, if available, or original release year), if known.</param>
|
||||
/// <param name="CoverPath">The path of the image representing the cover of the book, if available.</param>
|
||||
public sealed record BookLiteRow(
|
||||
Guid Id,
|
||||
string Title,
|
||||
int? ReleaseYear,
|
||||
string? CoverPath
|
||||
);
|
||||
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the result of appending entries to a playlist in one bulk operation.
|
||||
/// </summary>
|
||||
/// <param name="FirstPosition">The sparse order key of the first appended entry.</param>
|
||||
/// <param name="AddedCount">The number of entries appended.</param>
|
||||
[DebuggerDisplay("FirstPosition: {FirstPosition}; AddedCount: {AddedCount}")]
|
||||
public sealed record PlaylistBulkAddResultDto(
|
||||
long FirstPosition,
|
||||
int AddedCount
|
||||
);
|
||||
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// A stored playlist together with a window of its entries and their display data.
|
||||
/// </summary>
|
||||
/// <param name="Playlist">The stored playlist.</param>
|
||||
/// <param name="Entries">The requested window of entries.</param>
|
||||
public sealed record PlaylistDetailsDto(
|
||||
PlaylistEntity Playlist,
|
||||
IReadOnlyList<PlaylistEntryDto> Entries
|
||||
);
|
||||
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Display data of the media item referenced by a playlist entry, together with its collection and creator.
|
||||
/// </summary>
|
||||
/// <param name="TrackId">The Id of the track.</param>
|
||||
/// <param name="TrackTitle">The title of the track.</param>
|
||||
/// <param name="DurationInSeconds">The duration of the track in seconds.</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="AlbumTitle">The title of the album that contains the track.</param>
|
||||
/// <param name="ArtistId">The Id of the artist that produced the track.</param>
|
||||
/// <param name="ArtistName">The name of the artist that produced the track.</param>
|
||||
/// <param name="CoverPath">The path of the cover art of the album, if available.</param>
|
||||
public sealed record PlaylistEntryDisplayDto(
|
||||
Guid TrackId,
|
||||
string TrackTitle,
|
||||
int DurationInSeconds,
|
||||
Guid LibraryId,
|
||||
Guid AlbumId,
|
||||
string AlbumTitle,
|
||||
Guid ArtistId,
|
||||
string ArtistName,
|
||||
string? CoverPath
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// A stored playlist entry together with the display data of the media item it references and its dense display position.
|
||||
/// </summary>
|
||||
/// <param name="Entry">The stored entry.</param>
|
||||
/// <param name="Display">The display data of the referenced media item, or <see langword="null"/> when it no longer exists.</param>
|
||||
/// <param name="DisplayPosition">The dense zero based position shown to the client.</param>
|
||||
public sealed record PlaylistEntryDto(
|
||||
PlaylistEntryEntity Entry,
|
||||
PlaylistEntryDisplayDto? Display,
|
||||
int DisplayPosition
|
||||
);
|
||||
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a playlist in a list, without its entries.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the playlist.</param>
|
||||
/// <param name="Name">The name of the playlist.</param>
|
||||
/// <param name="Description">The description of the playlist, if applicable.</param>
|
||||
/// <param name="Type">The kind of media the playlist holds.</param>
|
||||
/// <param name="EntryCount">The number of entries of the playlist.</param>
|
||||
/// <param name="CreatedOnUtc">The date and time when the playlist was created.</param>
|
||||
/// <param name="UpdatedOnUtc">The date and time when the playlist was last updated, if applicable.</param>
|
||||
public sealed record PlaylistSummaryDto(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string? Description,
|
||||
PlaylistType Type,
|
||||
int EntryCount,
|
||||
DateTime CreatedOnUtc,
|
||||
DateTime? UpdatedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,80 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for a playlist.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Id: {Id}; Name: {Name}; Type: {Type}")]
|
||||
public class PlaylistEntity : IStorageEntity, IAuditableEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the playlist.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that owns the playlist.
|
||||
/// </summary>
|
||||
public required Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the playlist.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the description of the playlist, if applicable.
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the kind of media the playlist holds.
|
||||
/// </summary>
|
||||
public required PlaylistType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ordered entries of the playlist.
|
||||
/// </summary>
|
||||
public List<PlaylistEntryEntity> Entries { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of entries the playlist holds.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The count is maintained by the set-based entry operations in the same statement that appends or removes entries and updates the
|
||||
/// playlist, so reading a window of a very large playlist never has to count its entries.
|
||||
/// </remarks>
|
||||
public int EntryCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the concurrency token of the playlist.
|
||||
/// </summary>
|
||||
public long Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for an ordered entry of a playlist.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The entry references a media item by its Id and by the kind of media item, without a foreign key, so a playlist survives the deletion
|
||||
/// of the item it references and the entry can be shown to its owner so that it can be removed.
|
||||
/// </remarks>
|
||||
[DebuggerDisplay("Id: {Id}; MediaItemId: {MediaItemId}; MediaItemType: {MediaItemType}; Position: {Position}")]
|
||||
public class PlaylistEntryEntity : IStorageEntity, IAuditableEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the entry.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the playlist the entry belongs to.
|
||||
/// </summary>
|
||||
public required Guid PlaylistId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the media item referenced by the entry.
|
||||
/// </summary>
|
||||
public required Guid MediaItemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the kind of media item referenced by the entry.
|
||||
/// </summary>
|
||||
public PlaylistMediaItemType MediaItemType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sparse order key of the entry in the ordered entries of the playlist.
|
||||
/// </summary>
|
||||
public long Position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entry was added.
|
||||
/// </summary>
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entry.
|
||||
/// </summary>
|
||||
public Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entry was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entry.
|
||||
/// </summary>
|
||||
public Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
@@ -129,4 +129,12 @@ public interface ITrackRepository : IRepository<TrackEntity>,
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Updated>> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of tracks in <paramref name="trackIds"/> that exist, together with the distinct Ids of the libraries that contain them.
|
||||
/// </summary>
|
||||
/// <param name="trackIds">The Ids of the tracks whose access information is 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 access summary of the existing tracks, or an error.</returns>
|
||||
Task<Result<TrackAccessSummaryDto>> GetAccessInfoByIdsAsync(IReadOnlyCollection<Guid> trackIds, CancellationToken cancellationToken);
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.Application.Common.DTO.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the repository for playlists.
|
||||
/// </summary>
|
||||
public interface IPlaylistRepository : IRepository<PlaylistEntity>,
|
||||
IInsertRepositoryAction<PlaylistEntity>,
|
||||
IUpdateRepositoryAction<PlaylistEntity>,
|
||||
IDeleteByIdRepositoryAction<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the playlist 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 playlist to get.</param>
|
||||
/// <param name="userId">The Id of the user the playlist must belong to.</param>
|
||||
/// <param name="shouldIncludeNavigationProperties">Whether the entries of the playlist should be loaded together with the playlist itself.</param>
|
||||
/// <param name="shouldTrackEntities">Whether the retrieved entities should be tracked by the persistence medium, so that changes to them 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 playlist identified by <paramref name="id"/> and owned by <paramref name="userId"/>,
|
||||
/// <see langword="null"/> when no such playlist exists, or an error.
|
||||
/// </returns>
|
||||
Task<Result<PlaylistEntity?>> GetByIdForUserAsync(Guid id, Guid userId, bool shouldIncludeNavigationProperties = true, bool shouldTrackEntities = true, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the playlists of the user identified by <paramref name="userId"/>, ordered by their most recent activity.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user whose playlists 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 playlists of the user, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<PlaylistSummaryDto>>> GetAllForUserAsync(Guid userId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the playlist identified by <paramref name="id"/> together with the display details of the media items its entries reference,
|
||||
/// when the playlist belongs to the user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the playlist to get.</param>
|
||||
/// <param name="userId">The Id of the user the playlist must belong to.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the playlist details, <see langword="null"/> when no such playlist exists, or an error.
|
||||
/// </returns>
|
||||
Task<Result<PlaylistDetailsDto?>> GetDetailsForUserAsync(Guid id, Guid userId, int offset, int limit, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Appends a batch of media items of one kind to the end of the ordered entries of a playlist of the user identified by
|
||||
/// <paramref name="userId"/>, using batched bulk inserts, and updates the activity time of the playlist in the same transaction.
|
||||
/// </summary>
|
||||
/// <param name="playlistId">The Id of the playlist to append to.</param>
|
||||
/// <param name="userId">The Id of the user the playlist must belong to.</param>
|
||||
/// <param name="mediaItemIds">The Ids of the media items to append, in order. Duplicates are kept.</param>
|
||||
/// <param name="mediaItemType">The kind of media item referenced by every appended entry.</param>
|
||||
/// <param name="entryIds">The Ids to assign to the appended entries, in the same order as <paramref name="mediaItemIds"/>, or <see langword="null"/> to generate them.</param>
|
||||
/// <param name="updatedOnUtc">The activity time to store on the playlist.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the sparse order key of the first appended entry and the added count, or an error.
|
||||
/// </returns>
|
||||
Task<Result<PlaylistBulkAddResultDto>> AddEntriesAsync(Guid playlistId, Guid userId, IReadOnlyList<Guid> mediaItemIds, PlaylistMediaItemType mediaItemType, IReadOnlyList<Guid>? entryIds, DateTime updatedOnUtc, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Appends every media item of a library, an artist or an album to the end of the ordered entries of a playlist of the user identified by
|
||||
/// <paramref name="userId"/>, in catalogue order, without materializing the scope.
|
||||
/// </summary>
|
||||
/// <param name="playlistId">The Id of the playlist to append to.</param>
|
||||
/// <param name="userId">The Id of the user the playlist must belong to.</param>
|
||||
/// <param name="libraryId">The Id of the library whose media items are appended.</param>
|
||||
/// <param name="artistId">The Id of the artist the scope is limited to, or <see langword="null"/> for every artist of the library.</param>
|
||||
/// <param name="albumId">The Id of the album the scope is limited to, or <see langword="null"/> for every album of the scope.</param>
|
||||
/// <param name="mediaItemType">The kind of media item referenced by every appended entry.</param>
|
||||
/// <param name="updatedOnUtc">The activity time to store on the playlist.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the sparse order key of the first appended entry and the added count, or an error.
|
||||
/// </returns>
|
||||
Task<Result<PlaylistBulkAddResultDto>> AddScopeEntriesAsync(Guid playlistId, Guid userId, Guid libraryId, Guid? artistId, Guid? albumId, PlaylistMediaItemType mediaItemType, DateTime updatedOnUtc, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Moves one entry of a playlist of the user identified by <paramref name="userId"/> to a new dense position by changing only its
|
||||
/// sparse order key, and updates the activity time of the playlist in the same transaction.
|
||||
/// </summary>
|
||||
/// <param name="playlistId">The Id of the playlist whose entry is moved.</param>
|
||||
/// <param name="userId">The Id of the user the playlist must belong to.</param>
|
||||
/// <param name="entryId">The Id of the entry to move.</param>
|
||||
/// <param name="targetPosition">The new zero based position of the entry.</param>
|
||||
/// <param name="updatedOnUtc">The activity time to store on the playlist.</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 move, or an error.</returns>
|
||||
Task<Result<Updated>> MoveEntryAsync(Guid playlistId, Guid userId, Guid entryId, int targetPosition, DateTime updatedOnUtc, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Removes one entry of a playlist of the user identified by <paramref name="userId"/> by deleting only that row, and updates the
|
||||
/// activity time of the playlist in the same transaction.
|
||||
/// </summary>
|
||||
/// <param name="playlistId">The Id of the playlist whose entry is removed.</param>
|
||||
/// <param name="userId">The Id of the user the playlist must belong to.</param>
|
||||
/// <param name="entryId">The Id of the entry to remove.</param>
|
||||
/// <param name="updatedOnUtc">The activity time to store on the playlist.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either zero, because sparse positions need no repositioning, or an error.
|
||||
/// </returns>
|
||||
Task<Result<int>> RemoveEntryAsync(Guid playlistId, Guid userId, Guid entryId, DateTime updatedOnUtc, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entry that was just appended to a playlist of the user identified by <paramref name="userId"/>, together with the display details of the track it references.
|
||||
/// </summary>
|
||||
/// <param name="playlistId">The Id of the playlist the entry must belong to.</param>
|
||||
/// <param name="userId">The Id of the user the playlist must belong to.</param>
|
||||
/// <param name="entryId">The Id of the appended entry to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the entry details, <see langword="null"/> when the entry does not exist in that playlist of the user, or an error.
|
||||
/// </returns>
|
||||
Task<Result<PlaylistEntryDto?>> GetAppendedEntryDetailsForUserAsync(Guid playlistId, Guid userId, Guid entryId, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaContributors;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Playlists;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Themes;
|
||||
@@ -155,6 +156,11 @@ public interface IUnitOfWork
|
||||
/// </summary>
|
||||
IMusicPlayRecordRepository MusicPlayRecordRepository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the playlist repository.
|
||||
/// </summary>
|
||||
IPlaylistRepository PlaylistRepository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Saves the changes made to the database.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Playlists.Commands.AddPlaylistEntries;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="AddPlaylistEntriesRequest"/>.
|
||||
/// </summary>
|
||||
public static class AddPlaylistEntriesRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="AddPlaylistEntriesCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="playlistId">The Id of the playlist, taken from the route.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static AddPlaylistEntriesCommand ToCommand(this AddPlaylistEntriesRequest request, string? playlistId)
|
||||
{
|
||||
return new AddPlaylistEntriesCommand(playlistId, request.TrackIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Playlists.Commands.AddPlaylistEntry;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="AddPlaylistEntryRequest"/>.
|
||||
/// </summary>
|
||||
public static class AddPlaylistEntryRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="AddPlaylistEntryCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="playlistId">The Id of the playlist, taken from the route.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static AddPlaylistEntryCommand ToCommand(this AddPlaylistEntryRequest request, string? playlistId)
|
||||
{
|
||||
return new AddPlaylistEntryCommand(playlistId, request.TrackId);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Playlists.Commands.AddPlaylistScopeEntries;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="AddPlaylistScopeEntriesRequest"/>.
|
||||
/// </summary>
|
||||
public static class AddPlaylistScopeEntriesRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="AddPlaylistScopeEntriesCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="playlistId">The Id of the playlist, taken from the route.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static AddPlaylistScopeEntriesCommand ToCommand(this AddPlaylistScopeEntriesRequest request, string? playlistId)
|
||||
{
|
||||
return new AddPlaylistScopeEntriesCommand(playlistId, request.LibraryId, request.ArtistId, request.AlbumId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Playlists.Commands.CreatePlaylist;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="CreatePlaylistRequest"/>.
|
||||
/// </summary>
|
||||
public static class CreatePlaylistRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="CreatePlaylistCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static CreatePlaylistCommand ToCommand(this CreatePlaylistRequest request)
|
||||
{
|
||||
return new CreatePlaylistCommand(request.Name, request.Description, request.Type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Playlists.Commands.MovePlaylistEntry;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MovePlaylistEntryRequest"/>.
|
||||
/// </summary>
|
||||
public static class MovePlaylistEntryRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="MovePlaylistEntryCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="playlistId">The Id of the playlist, taken from the route.</param>
|
||||
/// <param name="playlistEntryId">The Id of the entry to move, taken from the route.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static MovePlaylistEntryCommand ToCommand(this MovePlaylistEntryRequest request, string? playlistId, string? playlistEntryId)
|
||||
{
|
||||
return new MovePlaylistEntryCommand(playlistId, playlistEntryId, request.TargetPosition);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="PlaylistDetailsDto"/>.
|
||||
/// </summary>
|
||||
public static class PlaylistDetailsDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="PlaylistResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The playlist details data to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static PlaylistResponse ToResponse(this PlaylistDetailsDto data)
|
||||
{
|
||||
return new PlaylistResponse(
|
||||
data.Playlist.Id,
|
||||
data.Playlist.Name,
|
||||
data.Playlist.Description,
|
||||
data.Playlist.Type,
|
||||
[.. data.Entries.Select(entry => entry.ToResponse())],
|
||||
data.Playlist.EntryCount,
|
||||
data.Playlist.CreatedOnUtc,
|
||||
data.Playlist.UpdatedOnUtc);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="PlaylistEntity"/>.
|
||||
/// </summary>
|
||||
public static class PlaylistEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="Playlist"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Playlist"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Playlist> ToDomainEntity(this PlaylistEntity repositoryEntity)
|
||||
{
|
||||
List<PlaylistEntry> entries = [];
|
||||
// The entries are ordered by their position, because the order of a navigation collection is not guaranteed by the storage medium.
|
||||
foreach (PlaylistEntryEntity entryEntity in repositoryEntity.Entries.OrderBy(entry => entry.Position))
|
||||
{
|
||||
Result<PlaylistEntry> convertEntryResult = entryEntity.ToDomainEntity();
|
||||
if (convertEntryResult.IsFailure)
|
||||
return convertEntryResult.Errors;
|
||||
entries.Add(convertEntryResult.Value);
|
||||
}
|
||||
|
||||
return Playlist.Create(
|
||||
PlaylistId.Create(repositoryEntity.Id),
|
||||
UserId.Create(repositoryEntity.UserId),
|
||||
repositoryEntity.Name,
|
||||
Optional<string>.FromNullable(repositoryEntity.Description),
|
||||
repositoryEntity.Type,
|
||||
entries,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
Optional<DateTime>.FromNullable(repositoryEntity.UpdatedOnUtc));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="PlaylistEntryDto"/>.
|
||||
/// </summary>
|
||||
public static class PlaylistEntryDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="PlaylistEntryResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The playlist entry data to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static PlaylistEntryResponse ToResponse(this PlaylistEntryDto data)
|
||||
{
|
||||
if (data.Display is null)
|
||||
return new PlaylistEntryResponse(
|
||||
data.Entry.Id,
|
||||
data.Entry.MediaItemId,
|
||||
data.Entry.MediaItemType,
|
||||
data.DisplayPosition,
|
||||
Guid.Empty,
|
||||
Guid.Empty,
|
||||
Guid.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
0,
|
||||
null);
|
||||
|
||||
PlaylistEntryDisplayDto display = data.Display;
|
||||
return new PlaylistEntryResponse(
|
||||
data.Entry.Id,
|
||||
data.Entry.MediaItemId,
|
||||
data.Entry.MediaItemType,
|
||||
data.DisplayPosition,
|
||||
display.LibraryId,
|
||||
display.AlbumId,
|
||||
display.ArtistId,
|
||||
display.TrackTitle,
|
||||
display.AlbumTitle,
|
||||
display.ArtistName,
|
||||
display.DurationInSeconds,
|
||||
display.CoverPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="PlaylistEntryEntity"/>.
|
||||
/// </summary>
|
||||
public static class PlaylistEntryEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="PlaylistEntry"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="PlaylistEntry"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<PlaylistEntry> ToDomainEntity(this PlaylistEntryEntity repositoryEntity)
|
||||
{
|
||||
return PlaylistEntry.Create(
|
||||
PlaylistEntryId.Create(repositoryEntity.Id),
|
||||
MediaItemId.Create(repositoryEntity.MediaItemId),
|
||||
repositoryEntity.MediaItemType,
|
||||
repositoryEntity.Position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Entities;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="PlaylistEntry"/>.
|
||||
/// </summary>
|
||||
public static class PlaylistEntryMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="PlaylistEntryEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <param name="playlistId">The Id of the playlist that owns the entry.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static PlaylistEntryEntity ToRepositoryEntity(this PlaylistEntry domainEntity, Guid playlistId)
|
||||
{
|
||||
return new PlaylistEntryEntity
|
||||
{
|
||||
Id = domainEntity.Id.Value,
|
||||
PlaylistId = playlistId,
|
||||
MediaItemId = domainEntity.MediaItemId.Value,
|
||||
MediaItemType = domainEntity.MediaItemType,
|
||||
Position = domainEntity.Position
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="Playlist"/>.
|
||||
/// </summary>
|
||||
public static class PlaylistMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="PlaylistEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static PlaylistEntity ToRepositoryEntity(this Playlist domainEntity)
|
||||
{
|
||||
return new PlaylistEntity
|
||||
{
|
||||
Id = domainEntity.Id.Value,
|
||||
UserId = domainEntity.UserId.Value,
|
||||
Name = domainEntity.Name,
|
||||
Description = domainEntity.Description.HasValue ? domainEntity.Description.Value : null,
|
||||
Type = domainEntity.Type,
|
||||
Entries = [.. domainEntity.Entries
|
||||
.OrderBy(entry => entry.Position)
|
||||
.Select(entry => entry.ToRepositoryEntity(domainEntity.Id.Value))],
|
||||
// This is the correct count for an insert. The update path deliberately keeps the stored count, because details edits never load the entries and must not overwrite it.
|
||||
EntryCount = domainEntity.Entries.Count,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc.Value : null,
|
||||
UpdatedBy = null
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="PlaylistSummaryDto"/>.
|
||||
/// </summary>
|
||||
public static class PlaylistSummaryDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to <see cref="PlaylistSummaryResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static PlaylistSummaryResponse ToResponse(this PlaylistSummaryDto dto)
|
||||
{
|
||||
return new PlaylistSummaryResponse(
|
||||
dto.Id,
|
||||
dto.Name,
|
||||
dto.Description,
|
||||
dto.Type,
|
||||
dto.EntryCount,
|
||||
dto.CreatedOnUtc,
|
||||
dto.UpdatedOnUtc);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.Playlists.Commands.UpdatePlaylist;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="UpdatePlaylistRequest"/>.
|
||||
/// </summary>
|
||||
public static class UpdatePlaylistRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="UpdatePlaylistCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="playlistId">The Id of the playlist, taken from the route.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static UpdatePlaylistCommand ToCommand(this UpdatePlaylistRequest request, string? playlistId)
|
||||
{
|
||||
return new UpdatePlaylistCommand(playlistId, request.Name, request.Description);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user