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

29 lines
1.2 KiB
C#
Raw Normal View History

2023-02-16 09:53:02 +01:00
using Domain.Enums;
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-16 17:38:01 +01:00
private readonly ILogger<ReadQueryHandler> logger;
2023-02-16 17:38:01 +01:00
public ReadQueryHandler(ICardDependencyAggregate aggregate, ILogger<ReadQueryHandler> logger) : base(aggregate) {
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));
}
var result = card.CardMainToCardDto().SerializeCardData("/root/card");
return new ServiceResult<string>(result);
}
}