61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
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
|
|
};
|
|
}
|
|
}
|