Highlight active playlist. Various optimizations and fixes.
This commit is contained in:
60
Harmonia.Core/Playlists/PlaylistDto.cs
Normal file
60
Harmonia.Core/Playlists/PlaylistDto.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Harmonia.Core.Models;
|
||||
|
||||
namespace Harmonia.Core.Playlists;
|
||||
|
||||
internal sealed record PlaylistDto
|
||||
{
|
||||
public string UID { get; init; } = Guid.NewGuid().ToString();
|
||||
public string? Name { get; init; }
|
||||
public List<PlaylistSongDto> Songs { get; init; } = [];
|
||||
public List<GroupOption> GroupOptions { get; init; } = [];
|
||||
public List<SortOption> SortOptions { get; init; } = [];
|
||||
public bool IsLocked { get; init; }
|
||||
|
||||
public static PlaylistDto FromPlaylist(Playlist playlist)
|
||||
{
|
||||
return new PlaylistDto
|
||||
{
|
||||
UID = playlist.UID,
|
||||
Name = playlist.Name,
|
||||
Songs = [.. playlist.Songs.Select(PlaylistSongDto.FromPlaylistSong)],
|
||||
GroupOptions = [.. playlist.GroupOptions],
|
||||
SortOptions = [.. playlist.SortOptions],
|
||||
IsLocked = playlist.IsLocked
|
||||
};
|
||||
}
|
||||
|
||||
public Playlist ToPlaylist()
|
||||
{
|
||||
return Playlist.Restore(
|
||||
UID,
|
||||
Name,
|
||||
Songs.Select(song => song.ToPlaylistSong()),
|
||||
GroupOptions,
|
||||
SortOptions,
|
||||
IsLocked);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed record PlaylistSongDto
|
||||
{
|
||||
public string UID { get; init; } = Guid.NewGuid().ToString();
|
||||
public required Song Song { get; init; }
|
||||
|
||||
public static PlaylistSongDto FromPlaylistSong(PlaylistSong playlistSong)
|
||||
{
|
||||
return new PlaylistSongDto
|
||||
{
|
||||
UID = playlistSong.UID,
|
||||
Song = playlistSong.Song
|
||||
};
|
||||
}
|
||||
|
||||
public PlaylistSong ToPlaylistSong()
|
||||
{
|
||||
return new PlaylistSong(Song)
|
||||
{
|
||||
UID = UID
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user