59 lines
2.4 KiB
C#
59 lines
2.4 KiB
C#
|
|
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
|
||
|
|
|
||
|
|
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetOrderById;
|
||
|
|
|
||
|
|
public class GetOrderByIdQueryHandler : IRequestHandler<GetOrderByIdQuery, GetOrderByIdResponseDto>
|
||
|
|
{
|
||
|
|
private readonly IApplicationContractContext _context;
|
||
|
|
|
||
|
|
public GetOrderByIdQueryHandler(IApplicationContractContext context)
|
||
|
|
{
|
||
|
|
_context = context;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<GetOrderByIdResponseDto> Handle(GetOrderByIdQuery request, CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
var response = await _context.DiscountOrders.GetOrderByIdAsync(
|
||
|
|
new GetOrderByIdRequest { OrderId = request.OrderId },
|
||
|
|
cancellationToken: cancellationToken);
|
||
|
|
|
||
|
|
return new GetOrderByIdResponseDto
|
||
|
|
{
|
||
|
|
Id = response.Id,
|
||
|
|
UserId = response.UserId,
|
||
|
|
TrackingCode = response.TrackingCode,
|
||
|
|
Status = response.Status,
|
||
|
|
StatusTitle = response.StatusTitle,
|
||
|
|
TotalPrice = response.TotalPrice,
|
||
|
|
DiscountBalanceUsed = response.DiscountBalanceUsed,
|
||
|
|
GatewayPayment = response.GatewayPayment,
|
||
|
|
FinalPrice = response.FinalPrice,
|
||
|
|
PaymentTransactionCode = response.PaymentTransactionCode,
|
||
|
|
AdminNote = response.AdminNote,
|
||
|
|
CreatedAt = response.CreatedAt.ToDateTime(),
|
||
|
|
PaidAt = response.HasPaidAt ? response.PaidAt.ToDateTime() : null,
|
||
|
|
ShippingAddress = new AddressInfoDto
|
||
|
|
{
|
||
|
|
Id = response.ShippingAddress.Id,
|
||
|
|
RecipientName = response.ShippingAddress.RecipientName,
|
||
|
|
RecipientPhone = response.ShippingAddress.RecipientPhone,
|
||
|
|
Province = response.ShippingAddress.Province,
|
||
|
|
City = response.ShippingAddress.City,
|
||
|
|
PostalCode = response.ShippingAddress.PostalCode,
|
||
|
|
FullAddress = response.ShippingAddress.FullAddress
|
||
|
|
},
|
||
|
|
Items = response.Items.Select(item => new OrderItemDto
|
||
|
|
{
|
||
|
|
Id = item.Id,
|
||
|
|
ProductId = item.ProductId,
|
||
|
|
ProductTitle = item.ProductTitle,
|
||
|
|
UnitPrice = item.UnitPrice,
|
||
|
|
DiscountPercent = item.DiscountPercent,
|
||
|
|
Quantity = item.Quantity,
|
||
|
|
TotalPrice = item.TotalPrice,
|
||
|
|
DiscountedPrice = item.DiscountedPrice
|
||
|
|
}).ToList()
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|