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
@@ -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