2023-02-12 19:40:40 +01:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2023-02-12 18:46:08 +01:00
|
|
|
|
|
|
|
namespace Application.Game.Card.Read;
|
|
|
|
|
|
|
|
|
2023-02-12 19:12:26 +01:00
|
|
|
public record ReadMusicQuery(long CardId) : IRequestWrapper<string>;
|
2023-02-12 18:46:08 +01:00
|
|
|
|
2023-02-16 17:38:01 +01:00
|
|
|
public class ReadMusicQueryHandler : RequestHandlerBase<ReadMusicQuery, string>
|
2023-02-12 18:46:08 +01:00
|
|
|
{
|
2023-02-12 19:40:40 +01:00
|
|
|
private const string MUSIC_XPATH = "/root/music/record";
|
2023-02-12 18:46:08 +01:00
|
|
|
public ReadMusicQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-12 19:40:40 +01:00
|
|
|
[SuppressMessage("ReSharper.DPA", "DPA0007: Large number of DB records",
|
|
|
|
Justification = "To return all musics, the whole table need to be returned")]
|
|
|
|
public override async Task<ServiceResult<string>> Handle(ReadMusicQuery request, CancellationToken cancellationToken)
|
2023-02-12 18:46:08 +01:00
|
|
|
{
|
2023-02-12 19:40:40 +01:00
|
|
|
var musics = await MusicDbContext.MusicUnlocks.ToListAsync(cancellationToken: cancellationToken);
|
|
|
|
var dtoList = musics.Select((unlock, i) =>
|
|
|
|
{
|
|
|
|
var dto = unlock.MusicToDto();
|
|
|
|
dto.Id = i;
|
|
|
|
return dto;
|
|
|
|
});
|
|
|
|
|
|
|
|
var result = dtoList.SerializeCardDataList(MUSIC_XPATH);
|
|
|
|
|
|
|
|
return new ServiceResult<string>(result);
|
2023-02-12 18:46:08 +01:00
|
|
|
}
|
|
|
|
}
|