using Domain.Enums; using Microsoft.Extensions.Logging; namespace Application.Game.Card.Read; public record ReadCardQuery(long CardId) : IRequestWrapper; public class ReadQueryHandler : RequestHandlerBase { private readonly ILogger logger; public ReadQueryHandler(ICardDependencyAggregate aggregate, ILogger logger) : base(aggregate) { this.logger = logger; } public override async Task> 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 of id: {CardId} does not exist! Registering a new one...", request.CardId); return ServiceResult.Failed(new ServiceError($"Card id: {request.CardId} does not exist!", (int)CardReturnCode.CardNotRegistered)); } var result = card.CardMainToCardDto().SerializeCardData("/root/card"); return new ServiceResult(result); } }