48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using BackOffice.BFF.Application.Common.Interfaces;
|
|
using MediatR;
|
|
using Microsoft.Extensions.Logging;
|
|
using BffProto = BackOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
|
|
using CmsProto = CMSMicroservice.Protobuf.Protos.UserOrder;
|
|
|
|
namespace BackOffice.BFF.Application.UserOrderCQ.Commands.UpdateOrderStatus;
|
|
|
|
public class UpdateOrderStatusCommandHandler : IRequestHandler<UpdateOrderStatusCommand, BffProto.UpdateOrderStatusResponse>
|
|
{
|
|
private readonly IApplicationContractContext _context;
|
|
private readonly ILogger<UpdateOrderStatusCommandHandler> _logger;
|
|
|
|
public UpdateOrderStatusCommandHandler(
|
|
IApplicationContractContext context,
|
|
ILogger<UpdateOrderStatusCommandHandler> logger)
|
|
{
|
|
_context = context;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<BffProto.UpdateOrderStatusResponse> Handle(UpdateOrderStatusCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var grpcRequest = new CmsProto.UpdateOrderStatusRequest
|
|
{
|
|
OrderId = request.OrderId,
|
|
NewStatus = request.NewStatus
|
|
};
|
|
|
|
var response = await _context.UserOrders.UpdateOrderStatusAsync(grpcRequest, cancellationToken: cancellationToken);
|
|
|
|
_logger.LogInformation(
|
|
"Updated order {OrderId} status from {OldStatus} to {NewStatus}. Success={Success}",
|
|
request.OrderId,
|
|
response.OldStatus,
|
|
response.NewStatus,
|
|
response.Success);
|
|
|
|
return new BffProto.UpdateOrderStatusResponse
|
|
{
|
|
Success = response.Success,
|
|
Message = response.Message,
|
|
OldStatus = response.OldStatus,
|
|
NewStatus = response.NewStatus
|
|
};
|
|
}
|
|
}
|