Files
CMS/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetCustomerOrder/GetCustomerOrderQueryHandler.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

71 lines
2.9 KiB
C#

using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities;
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetCustomerOrder;
public class GetCustomerOrderQueryHandler : IRequestHandler<GetCustomerOrderQuery, GetCustomerOrderResponseDto>
{
private readonly IApplicationDbContext _context;
public GetCustomerOrderQueryHandler(
IApplicationDbContext context)
{
_context = context;
}
public async Task<GetCustomerOrderResponseDto> Handle(GetCustomerOrderQuery request, CancellationToken cancellationToken)
{
// UserId > 0 → filter by that user (customer security)
// UserId == 0 → no user filter (admin can view any order by ID)
var userId = request.UserId;
var order = await _context.UserOrders
.AsNoTracking()
.Where(x => x.Id == request.OrderId && (userId == 0 || x.UserId == userId))
.Include(x => x.Package)
.Include(x => x.Transaction)
.Include(x => x.UserAddress)
.Include(x => x.User)
.Include(x => x.FactorDetails)
.ThenInclude(f => f.Product)
.Include(x => x.OrderVAT)
.FirstOrDefaultAsync(cancellationToken);
if (order == null)
throw new NotFoundException(nameof(UserOrder), request.OrderId);
return new GetCustomerOrderResponseDto
{
Id = order.Id,
Amount = order.Amount,
PackageId = order.PackageId,
TransactionId = order.TransactionId,
PaymentStatus = order.PaymentStatus,
PaymentDate = order.PaymentDate,
UserId = order.UserId,
UserAddressId = order.UserAddressId,
PaymentMethod = order.PaymentMethod,
UserAddressText = order.UserAddress?.Address ?? "",
DeliveryStatus = order.DeliveryStatus,
TrackingCode = order.TrackingCode ?? "",
DeliveryDescription = order.DeliveryDescription ?? "",
UserFullName = $"{order.User?.FirstName ?? ""} {order.User?.LastName ?? ""}".Trim(),
UserNationalCode = order.User?.NationalCode ?? "",
PostalCode = order.UserAddress?.PostalCode ?? "",
UserMobile = order.User?.Mobile ?? "",
VatAmount = order.OrderVAT?.VATAmount ?? 0,
VatPercentage = order.OrderVAT != null ? (double)order.OrderVAT.VATRate * 100 : 0,
FactorDetails = order.FactorDetails?.Select(fd => new FactorDetailDto
{
ProductId = fd.ProductId,
ProductTitle = fd.Product?.Title ?? "",
ProductThumbnailPath = fd.Product?.ThumbnailPath ?? "",
UnitPrice = fd.UnitPrice,
Count = fd.Count,
UnitDiscountPrice = fd.UnitDiscountPrice
}).ToList() ?? new List<FactorDetailDto>()
};
}
}