Files
CMS/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetOrderById/GetOrderByIdQueryHandler.cs
T
masoodafar-web 40da1bd8df
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m33s
feat(order): enhance order details with user contact information and update Protobuf definitions
- Added Phone property to UserAddressDto for capturing the user's mobile number.
- Updated GetOrderByIdQueryHandler to include user mobile in order details.
- Enhanced GetCustomerOrderQueryHandler and GetCustomerOrderResponseDto to include PostalCode and UserMobile.
- Modified userorder.proto to add postal_code and user_mobile fields in GetUserOrderResponse.
- Bumped Protobuf project version to reflect the addition of new features.
2026-08-07 15:48:04 +03:30

72 lines
2.5 KiB
C#

using CMSMicroservice.Application.Common.Interfaces;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.DiscountShopCQ.Queries.GetOrderById;
public class GetOrderByIdQueryHandler : IRequestHandler<GetOrderByIdQuery, OrderDetailDto?>
{
private readonly IApplicationDbContext _context;
public GetOrderByIdQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<OrderDetailDto?> Handle(GetOrderByIdQuery request, CancellationToken cancellationToken)
{
var query = _context.DiscountOrders
.Where(o => o.Id == request.OrderId);
if (request.UserId.HasValue && request.UserId.Value > 0)
{
query = query.Where(o => o.UserId == request.UserId.Value);
}
var order = await query
.Include(o => o.UserAddress)
.Include(o => o.User)
.Include(o => o.OrderDetails)
.ThenInclude(od => od.Product)
.FirstOrDefaultAsync(cancellationToken);
if (order == null)
return null;
return new OrderDetailDto
{
Id = order.Id,
UserId = order.UserId,
TotalAmount = order.TotalAmount,
DiscountBalanceUsed = order.DiscountBalanceUsed,
GatewayAmountPaid = order.GatewayAmountPaid,
VatAmount = order.VatAmount,
PaymentStatus = order.PaymentStatus,
PaymentDate = order.PaymentDate,
DeliveryStatus = order.DeliveryStatus,
TrackingCode = order.TrackingCode,
DeliveryDescription = order.DeliveryDescription,
Created = order.Created,
Address = new UserAddressDto
{
Title = order.UserAddress.Title,
Address = order.UserAddress.Address,
PostalCode = order.UserAddress.PostalCode,
Phone = order.User?.Mobile
},
Items = order.OrderDetails.Select(od => new OrderItemDto
{
ProductId = od.ProductId,
ProductTitle = od.Product.Title,
Count = od.Count,
UnitPrice = od.UnitPrice,
DiscountPercentUsed = od.DiscountPercentUsed,
DiscountAmount = od.DiscountAmount,
FinalPrice = od.FinalPrice,
ImagePath = od.Product.ImagePath ?? "",
ThumbnailPath = od.Product.ThumbnailPath ?? ""
}).ToList()
};
}
}