using Application.Common.Extensions; using Application.Common.Models; using Application.Interfaces; using Application.Mappers; using Domain.Enums; using Microsoft.EntityFrameworkCore; namespace Application.Game.Card.Read; public record ReadMusicExtraQuery(long CardId) : IRequestWrapper; public class ReadMusicExtraQueryHandler : CardRequestHandlerBase { private const string MUSIC_EXTRA_XPATH = "/root/music_extra"; private const string RECORD_XPATH = $"{MUSIC_EXTRA_XPATH}/record"; public ReadMusicExtraQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) { } public override async Task> Handle(ReadMusicExtraQuery request, CancellationToken cancellationToken) { var musics = await MusicDbContext.MusicExtras.ToListAsync(cancellationToken: cancellationToken); var dtoList = musics.Select((aou, i) => { var dto = aou.MusicExtraToDto(); dto.Id = i; return dto; }).ToList(); var result = dtoList.Count == 0 ? new object().SerializeCardData(MUSIC_EXTRA_XPATH) : dtoList.SerializeCardDataList(RECORD_XPATH); return new ServiceResult(result); } }