feat: Implement Cancel Order functionality with command, handler, and validation
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using BackOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BackOffice.BFF.Application.UserOrderCQ.Commands.CancelOrder;
|
||||
|
||||
public class CancelOrderCommandHandler : IRequestHandler<CancelOrderCommand, CancelOrderResponse>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
private readonly ILogger<CancelOrderCommandHandler> _logger;
|
||||
|
||||
public CancelOrderCommandHandler(
|
||||
IApplicationContractContext context,
|
||||
ILogger<CancelOrderCommandHandler> logger)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<CancelOrderResponse> Handle(CancelOrderCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var grpcRequest = new CMSMicroservice.Protobuf.Protos.UserOrder.CancelOrderRequest
|
||||
{
|
||||
OrderId = request.OrderId,
|
||||
CancelReason = request.CancelReason ?? string.Empty,
|
||||
RefundPayment = request.RefundPayment
|
||||
};
|
||||
|
||||
var response = await _context.UserOrders.CancelOrderAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
_logger.LogInformation(
|
||||
"Cancelled order {OrderId}. Status={Status} RefundProcessed={RefundProcessed}",
|
||||
response.OrderId,
|
||||
response.Status,
|
||||
response.RefundProcessed);
|
||||
|
||||
return new CancelOrderResponse
|
||||
{
|
||||
OrderId = response.OrderId,
|
||||
Status = (int)response.Status,
|
||||
Message = response.Message,
|
||||
RefundProcessed = response.RefundProcessed
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user