1
0
mirror of synced 2024-12-19 09:45:54 +01:00
GC-local-server-rewrite/Application/Game/Card/Read/ReadMusicAouQuery.cs

36 lines
1.2 KiB
C#
Raw Normal View History

2023-02-13 17:38:19 +01:00
using System.Diagnostics.CodeAnalysis;
namespace Application.Game.Card.Read;
public record ReadMusicAouQuery(long CardId) : IRequestWrapper<string>;
2023-02-16 17:38:01 +01:00
public class ReadMusicAouQueryHandler : RequestHandlerBase<ReadMusicAouQuery, string>
{
2023-02-13 17:38:19 +01:00
private const string MUSIC_AOU_XPATH = "/root/music_aou";
private const string RECORD_XPATH = $"{MUSIC_AOU_XPATH}/record";
public ReadMusicAouQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
2023-02-13 17:38:19 +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(ReadMusicAouQuery request, CancellationToken cancellationToken)
{
2023-02-13 17:38:19 +01:00
var musics = await MusicDbContext.MusicAous.ToListAsync(cancellationToken: cancellationToken);
var dtoList = musics.Select((aou, i) =>
{
var dto = aou.MusicAouToDto();
dto.Id = i;
return dto;
}).ToList();
var result = dtoList.Count == 0 ? new object().SerializeCardData(MUSIC_AOU_XPATH)
: dtoList.SerializeCardDataList(RECORD_XPATH);
return new ServiceResult<string>(result);
}
}