feat: Implement Public Message management features including create, update, delete, and publish functionalities
This commit is contained in:
+29
-7
@@ -1,4 +1,6 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using BackOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -6,22 +8,42 @@ namespace BackOffice.BFF.Application.UserOrderCQ.Commands.ApplyDiscountToOrder;
|
||||
|
||||
public class ApplyDiscountToOrderCommandHandler : IRequestHandler<ApplyDiscountToOrderCommand, ApplyDiscountToOrderResponse>
|
||||
{
|
||||
private readonly UserOrderContract.UserOrderContractClient _orderClient;
|
||||
private readonly IApplicationContractContext _context;
|
||||
private readonly ILogger<ApplyDiscountToOrderCommandHandler> _logger;
|
||||
|
||||
public ApplyDiscountToOrderCommandHandler(
|
||||
UserOrderContract.UserOrderContractClient orderClient,
|
||||
IApplicationContractContext context,
|
||||
ILogger<ApplyDiscountToOrderCommandHandler> logger)
|
||||
{
|
||||
_orderClient = orderClient;
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<ApplyDiscountToOrderResponse> Handle(ApplyDiscountToOrderCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// TODO: پیادهسازی ApplyDiscountToOrder
|
||||
// 1. ایجاد gRPC Request و فراخوانی CMS
|
||||
// 2. return response از CMS
|
||||
throw new NotImplementedException("ApplyDiscountToOrder needs implementation");
|
||||
var grpcRequest = new ApplyDiscountToOrderRequest
|
||||
{
|
||||
OrderId = request.OrderId,
|
||||
DiscountAmount = request.DiscountAmount,
|
||||
Reason = request.Reason ?? string.Empty
|
||||
};
|
||||
|
||||
var response = await _context.UserOrders.ApplyDiscountToOrderAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
_logger.LogInformation(
|
||||
"Applied discount to order {OrderId}. Success={Success}, Discount={DiscountAmount}, FinalAmount={FinalAmount}",
|
||||
request.OrderId,
|
||||
response.Success,
|
||||
response.DiscountAmount,
|
||||
response.FinalAmount);
|
||||
|
||||
return new ApplyDiscountToOrderResponse
|
||||
{
|
||||
Success = response.Success,
|
||||
Message = response.Message,
|
||||
OriginalAmount = response.OriginalAmount,
|
||||
DiscountAmount = response.DiscountAmount,
|
||||
FinalAmount = response.FinalAmount
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+27
-7
@@ -1,4 +1,6 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using BackOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -6,22 +8,40 @@ namespace BackOffice.BFF.Application.UserOrderCQ.Commands.UpdateOrderStatus;
|
||||
|
||||
public class UpdateOrderStatusCommandHandler : IRequestHandler<UpdateOrderStatusCommand, UpdateOrderStatusResponse>
|
||||
{
|
||||
private readonly UserOrderContract.UserOrderContractClient _orderClient;
|
||||
private readonly IApplicationContractContext _context;
|
||||
private readonly ILogger<UpdateOrderStatusCommandHandler> _logger;
|
||||
|
||||
public UpdateOrderStatusCommandHandler(
|
||||
UserOrderContract.UserOrderContractClient orderClient,
|
||||
IApplicationContractContext context,
|
||||
ILogger<UpdateOrderStatusCommandHandler> logger)
|
||||
{
|
||||
_orderClient = orderClient;
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<UpdateOrderStatusResponse> Handle(UpdateOrderStatusCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// TODO: پیادهسازی UpdateOrderStatus
|
||||
// 1. ایجاد gRPC Request و فراخوانی CMS
|
||||
// 2. return response از CMS
|
||||
throw new NotImplementedException("UpdateOrderStatus needs implementation");
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+31
-7
@@ -1,22 +1,46 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using BackOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
using MediatR;
|
||||
|
||||
namespace BackOffice.BFF.Application.UserOrderCQ.Queries.CalculateOrderPV;
|
||||
|
||||
public class CalculateOrderPVQueryHandler : IRequestHandler<CalculateOrderPVQuery, CalculateOrderPVResponse>
|
||||
{
|
||||
private readonly UserOrderContract.UserOrderContractClient _orderClient;
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public CalculateOrderPVQueryHandler(UserOrderContract.UserOrderContractClient orderClient)
|
||||
public CalculateOrderPVQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_orderClient = orderClient;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<CalculateOrderPVResponse> Handle(CalculateOrderPVQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// TODO: پیادهسازی CalculateOrderPV
|
||||
// 1. ایجاد gRPC Request و فراخوانی CMS
|
||||
// 2. return response از CMS
|
||||
throw new NotImplementedException("CalculateOrderPV needs implementation");
|
||||
var grpcRequest = new CalculateOrderPVRequest
|
||||
{
|
||||
OrderId = request.OrderId
|
||||
};
|
||||
|
||||
var response = await _context.UserOrders.CalculateOrderPVAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
var result = new CalculateOrderPVResponse
|
||||
{
|
||||
OrderId = response.OrderId,
|
||||
TotalPv = response.TotalPv
|
||||
};
|
||||
|
||||
foreach (var product in response.Products)
|
||||
{
|
||||
result.Products.Add(new ProductPVDto
|
||||
{
|
||||
ProductId = product.ProductId,
|
||||
ProductTitle = product.ProductTitle,
|
||||
Quantity = product.Quantity,
|
||||
UnitPv = product.UnitPv,
|
||||
TotalPv = product.TotalPv
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+56
-7
@@ -1,22 +1,71 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using BackOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MediatR;
|
||||
|
||||
namespace BackOffice.BFF.Application.UserOrderCQ.Queries.GetOrdersByDateRange;
|
||||
|
||||
public class GetOrdersByDateRangeQueryHandler : IRequestHandler<GetOrdersByDateRangeQuery, GetOrdersByDateRangeResponse>
|
||||
{
|
||||
private readonly UserOrderContract.UserOrderContractClient _orderClient;
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetOrdersByDateRangeQueryHandler(UserOrderContract.UserOrderContractClient orderClient)
|
||||
public GetOrdersByDateRangeQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_orderClient = orderClient;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetOrdersByDateRangeResponse> Handle(GetOrdersByDateRangeQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// TODO: پیادهسازی GetOrdersByDateRange
|
||||
// 1. ایجاد gRPC Request و فراخوانی CMS
|
||||
// 2. return response از CMS
|
||||
throw new NotImplementedException("GetOrdersByDateRange needs implementation");
|
||||
var grpcRequest = new GetOrdersByDateRangeRequest
|
||||
{
|
||||
StartDate = Timestamp.FromDateTime(request.StartDate.ToUniversalTime()),
|
||||
EndDate = Timestamp.FromDateTime(request.EndDate.ToUniversalTime()),
|
||||
PageNumber = request.PageNumber,
|
||||
PageSize = request.PageSize
|
||||
};
|
||||
|
||||
if (request.Status.HasValue)
|
||||
{
|
||||
grpcRequest.Status = new Int32Value { Value = request.Status.Value };
|
||||
}
|
||||
|
||||
if (request.UserId.HasValue)
|
||||
{
|
||||
grpcRequest.UserId = new Int64Value { Value = request.UserId.Value };
|
||||
}
|
||||
|
||||
var response = await _context.UserOrders.GetOrdersByDateRangeAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
var result = new GetOrdersByDateRangeResponse
|
||||
{
|
||||
MetaData = new MetaData
|
||||
{
|
||||
CurrentPage = response.MetaData.CurrentPage,
|
||||
TotalPage = response.MetaData.TotalPage,
|
||||
PageSize = response.MetaData.PageSize,
|
||||
TotalCount = response.MetaData.TotalCount,
|
||||
HasPrevious = response.MetaData.HasPrevious,
|
||||
HasNext = response.MetaData.HasNext
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var order in response.Orders)
|
||||
{
|
||||
result.Orders.Add(new OrderSummaryDto
|
||||
{
|
||||
OrderId = order.OrderId,
|
||||
OrderNumber = order.OrderNumber,
|
||||
UserId = order.UserId,
|
||||
UserFullName = order.UserFullName,
|
||||
TotalAmount = order.TotalAmount,
|
||||
Status = order.Status,
|
||||
StatusName = order.StatusName,
|
||||
ItemsCount = order.ItemsCount,
|
||||
CreatedAt = order.CreatedAt
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user