2023-02-16 09:53:02 +01:00
|
|
|
|
using Domain.Enums;
|
2023-02-11 18:09:29 +01:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace Application.Game.Card.Read;
|
|
|
|
|
|
|
|
|
|
public record ReadCardQuery(long CardId) : IRequestWrapper<string>;
|
|
|
|
|
|
2023-02-16 17:38:01 +01:00
|
|
|
|
public class ReadQueryHandler : RequestHandlerBase<ReadCardQuery, string>
|
2023-02-11 18:09:29 +01:00
|
|
|
|
{
|
2023-02-16 17:38:01 +01:00
|
|
|
|
private readonly ILogger<ReadQueryHandler> logger;
|
2023-02-11 18:09:29 +01:00
|
|
|
|
|
2023-02-16 17:38:01 +01:00
|
|
|
|
public ReadQueryHandler(ICardDependencyAggregate aggregate, ILogger<ReadQueryHandler> logger) : base(aggregate) {
|
2023-02-11 18:09:29 +01:00
|
|
|
|
this.logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async Task<ServiceResult<string>> Handle(ReadCardQuery request, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var card = await CardDbContext.CardMains.FirstOrDefaultAsync(card => card.CardId == request.CardId, cancellationToken: cancellationToken);
|
|
|
|
|
if (card is null)
|
|
|
|
|
{
|
|
|
|
|
logger.LogInformation("Card with {CardId} does not exist! Registering a new one...", request.CardId);
|
|
|
|
|
return ServiceResult.Failed<string>(new ServiceError($"Card id: {request.CardId} does not exist!", (int)CardReturnCode.CardNotRegistered));
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-14 19:14:19 +01:00
|
|
|
|
var result = card.CardMainToCardDto().SerializeCardData("/root/card");
|
2023-02-11 18:09:29 +01:00
|
|
|
|
|
|
|
|
|
return new ServiceResult<string>(result);
|
|
|
|
|
}
|
|
|
|
|
}
|