1
0
mirror of synced 2024-12-19 17:55:53 +01:00
GC-local-server-rewrite/Application/Game/Card/Read/ReadCardDetailQuery.cs

45 lines
1.8 KiB
C#
Raw Normal View History

using Domain.Enums;
using Microsoft.Extensions.Logging;
namespace Application.Game.Card.Read;
public record ReadCardDetailQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadCardDetailQueryHandler : CardRequestHandlerBase<ReadCardDetailQuery, string>
{
private const string CARD_DETAILS_XPATH = "/root/card_detail";
private readonly ILogger<ReadCardDetailQueryHandler> logger;
public ReadCardDetailQueryHandler(ICardDependencyAggregate aggregate, ILogger<ReadCardDetailQueryHandler> logger) : base(aggregate)
{
this.logger = logger;
}
public override async Task<ServiceResult<string>> Handle(ReadCardDetailQuery request, CancellationToken cancellationToken)
{
var exists = await CardDbContext.CardMains.AnyAsync(card => card.CardId == request.CardId, cancellationToken: cancellationToken);
if (!exists)
{
logger.LogWarning("Card id: {CardId} does not exist!", request.CardId);
return ServiceResult.Failed<string>(
new ServiceError($"Card id: {request.CardId} does not exist!", (int)CardReturnCode.CardNotRegistered));
}
var queryCondition = request.Data.DeserializeCardData<CardDetailDto>();
var detail = await CardDbContext.CardDetails.FirstOrDefaultAsync(cardDetail =>
cardDetail.CardId == request.CardId &&
cardDetail.Pcol1 == queryCondition.Pcol1 &&
cardDetail.Pcol2 == queryCondition.Pcol2 &&
cardDetail.Pcol3 == queryCondition.Pcol3, cancellationToken: cancellationToken);
var dto = detail?.CardDetailToDto();
var result = dto?.SerializeCardData(CARD_DETAILS_XPATH) ??
new object().SerializeCardData(CARD_DETAILS_XPATH);
return new ServiceResult<string>(result);
}
}