2025-12-04 17:29:05 +03:30
|
|
|
using BackOffice.BFF.Application.Common.Interfaces;
|
2025-12-04 03:43:28 +03:30
|
|
|
using BackOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
|
2025-12-04 17:29:05 +03:30
|
|
|
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
2025-12-04 03:43:28 +03:30
|
|
|
using MediatR;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace BackOffice.BFF.Application.UserOrderCQ.Commands.UpdateOrderStatus;
|
|
|
|
|
|
|
|
|
|
public class UpdateOrderStatusCommandHandler : IRequestHandler<UpdateOrderStatusCommand, UpdateOrderStatusResponse>
|
|
|
|
|
{
|
2025-12-04 17:29:05 +03:30
|
|
|
private readonly IApplicationContractContext _context;
|
2025-12-04 03:43:28 +03:30
|
|
|
private readonly ILogger<UpdateOrderStatusCommandHandler> _logger;
|
|
|
|
|
|
|
|
|
|
public UpdateOrderStatusCommandHandler(
|
2025-12-04 17:29:05 +03:30
|
|
|
IApplicationContractContext context,
|
2025-12-04 03:43:28 +03:30
|
|
|
ILogger<UpdateOrderStatusCommandHandler> logger)
|
|
|
|
|
{
|
2025-12-04 17:29:05 +03:30
|
|
|
_context = context;
|
2025-12-04 03:43:28 +03:30
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<UpdateOrderStatusResponse> Handle(UpdateOrderStatusCommand request, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2025-12-04 17:29:05 +03:30
|
|
|
var grpcRequest = new 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 UpdateOrderStatusResponse
|
|
|
|
|
{
|
|
|
|
|
Success = response.Success,
|
|
|
|
|
Message = response.Message,
|
|
|
|
|
OldStatus = response.OldStatus,
|
|
|
|
|
NewStatus = response.NewStatus
|
|
|
|
|
};
|
2025-12-04 03:43:28 +03:30
|
|
|
}
|
|
|
|
|
}
|