2023-02-12 18:46:08 +01:00
|
|
|
using Application.Common.Extensions;
|
|
|
|
using Application.Common.Models;
|
|
|
|
using Application.Interfaces;
|
2023-02-13 17:38:19 +01:00
|
|
|
using Application.Mappers;
|
2023-02-12 18:46:08 +01:00
|
|
|
using Domain.Enums;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
namespace Application.Game.Card.Read;
|
|
|
|
|
|
|
|
|
2023-02-12 19:12:26 +01:00
|
|
|
public record ReadMusicExtraQuery(long CardId) : IRequestWrapper<string>;
|
2023-02-12 18:46:08 +01:00
|
|
|
|
|
|
|
public class ReadMusicExtraQueryHandler : CardRequestHandlerBase<ReadMusicExtraQuery, string>
|
|
|
|
{
|
2023-02-13 17:38:19 +01:00
|
|
|
private const string MUSIC_EXTRA_XPATH = "/root/music_extra";
|
|
|
|
|
|
|
|
private const string RECORD_XPATH = $"{MUSIC_EXTRA_XPATH}/record";
|
|
|
|
|
2023-02-12 18:46:08 +01:00
|
|
|
public ReadMusicExtraQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-13 17:38:19 +01:00
|
|
|
public override async Task<ServiceResult<string>> Handle(ReadMusicExtraQuery request, CancellationToken cancellationToken)
|
2023-02-12 18:46:08 +01:00
|
|
|
{
|
2023-02-13 17:38:19 +01:00
|
|
|
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<string>(result);
|
2023-02-12 18:46:08 +01:00
|
|
|
}
|
|
|
|
}
|