1
0
mirror of synced 2024-12-19 17:55:53 +01:00
GC-local-server-rewrite/Application/Game/Card/Read/ReadCardQuery.cs
2023-02-21 22:45:51 +08:00

29 lines
1.2 KiB
C#

using Domain.Enums;
using Microsoft.Extensions.Logging;
namespace Application.Game.Card.Read;
public record ReadCardQuery(long CardId) : IRequestWrapper<string>;
public class ReadQueryHandler : RequestHandlerBase<ReadCardQuery, string>
{
private readonly ILogger<ReadQueryHandler> logger;
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 of id: {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);
}
}