feat(order): refactor order data mapping for improved clarity and structure
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 13m4s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 13m4s
- Updated GetAllDiscountOrdersQueryHandler to enhance order data mapping by using a more structured approach with AdminOrderDto. - Refactored user full name construction in GetCustomerOrderQueryHandler and GetCustomerOrdersQueryHandler to utilize UserDisplayName for better readability. - Added necessary using directives for consistency across query handlers.
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
namespace CMSMicroservice.Application.Common;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// نام نمایشی کاربر برای گزارشها؛ اگر نام خالی باشد موبایل یا شناسه.
|
||||||
|
/// </summary>
|
||||||
|
public static class UserDisplayName
|
||||||
|
{
|
||||||
|
public static string From(string? firstName, string? lastName, string? mobile, long userId)
|
||||||
|
{
|
||||||
|
var name = string.Join(" ",
|
||||||
|
new[] { firstName, lastName }.Where(s => !string.IsNullOrWhiteSpace(s)));
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(name))
|
||||||
|
return name;
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(mobile))
|
||||||
|
return mobile.Trim();
|
||||||
|
|
||||||
|
return userId > 0 ? $"کاربر {userId}" : "—";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string From(Domain.Entities.User? user)
|
||||||
|
{
|
||||||
|
if (user is null)
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
return From(user.FirstName, user.LastName, user.Mobile, user.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
+42
-18
@@ -1,3 +1,4 @@
|
|||||||
|
using CMSMicroservice.Application.Common;
|
||||||
using CMSMicroservice.Application.Common.Interfaces;
|
using CMSMicroservice.Application.Common.Interfaces;
|
||||||
using CMSMicroservice.Application.Common.Models;
|
using CMSMicroservice.Application.Common.Models;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
@@ -80,35 +81,58 @@ public class GetAllDiscountOrdersQueryHandler : IRequestHandler<GetAllDiscountOr
|
|||||||
// Apply pagination
|
// Apply pagination
|
||||||
var pagination = request.PaginationQuery ?? new PaginationState { PageNumber = 1, PageSize = 20 };
|
var pagination = request.PaginationQuery ?? new PaginationState { PageNumber = 1, PageSize = 20 };
|
||||||
|
|
||||||
var orders = await query
|
var rows = await query
|
||||||
.OrderByDescending(o => o.Created)
|
.OrderByDescending(o => o.Created)
|
||||||
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
|
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
|
||||||
.Take(pagination.PageSize)
|
.Take(pagination.PageSize)
|
||||||
.Select(o => new AdminOrderDto
|
.Select(o => new
|
||||||
{
|
{
|
||||||
Id = o.Id,
|
o.Id,
|
||||||
UserId = o.UserId,
|
o.UserId,
|
||||||
UserFullName = (o.User.FirstName ?? "") + " " + (o.User.LastName ?? ""),
|
FirstName = o.User.FirstName,
|
||||||
UserMobile = o.User.Mobile,
|
LastName = o.User.LastName,
|
||||||
TotalAmount = o.TotalAmount,
|
Mobile = o.User.Mobile,
|
||||||
DiscountBalanceUsed = o.DiscountBalanceUsed,
|
o.TotalAmount,
|
||||||
GatewayAmountPaid = o.GatewayAmountPaid,
|
o.DiscountBalanceUsed,
|
||||||
VatAmount = o.VatAmount,
|
o.GatewayAmountPaid,
|
||||||
PaymentStatus = o.PaymentStatus,
|
o.VatAmount,
|
||||||
PaymentDate = o.PaymentDate,
|
o.PaymentStatus,
|
||||||
DeliveryStatus = o.DeliveryStatus,
|
o.PaymentDate,
|
||||||
DeliveryDate = null, // TODO: Add DeliveryDate to DiscountOrder if needed
|
o.DeliveryStatus,
|
||||||
ShippingAddress = o.UserAddress.Address,
|
ShippingAddress = o.UserAddress.Address,
|
||||||
ReceiverName = o.UserAddress.Title,
|
ReceiverName = o.UserAddress.Title,
|
||||||
ReceiverMobile = o.User.Mobile,
|
o.TrackingCode,
|
||||||
TrackingCode = o.TrackingCode,
|
|
||||||
AdminNote = o.DeliveryDescription,
|
AdminNote = o.DeliveryDescription,
|
||||||
Created = o.Created,
|
o.Created,
|
||||||
LastModified = o.LastModified,
|
o.LastModified,
|
||||||
ItemsCount = o.OrderDetails.Count
|
ItemsCount = o.OrderDetails.Count
|
||||||
})
|
})
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
var orders = rows.Select(o => new AdminOrderDto
|
||||||
|
{
|
||||||
|
Id = o.Id,
|
||||||
|
UserId = o.UserId,
|
||||||
|
UserFullName = UserDisplayName.From(o.FirstName, o.LastName, o.Mobile, o.UserId),
|
||||||
|
UserMobile = o.Mobile,
|
||||||
|
TotalAmount = o.TotalAmount,
|
||||||
|
DiscountBalanceUsed = o.DiscountBalanceUsed,
|
||||||
|
GatewayAmountPaid = o.GatewayAmountPaid,
|
||||||
|
VatAmount = o.VatAmount,
|
||||||
|
PaymentStatus = o.PaymentStatus,
|
||||||
|
PaymentDate = o.PaymentDate,
|
||||||
|
DeliveryStatus = o.DeliveryStatus,
|
||||||
|
DeliveryDate = null,
|
||||||
|
ShippingAddress = o.ShippingAddress,
|
||||||
|
ReceiverName = o.ReceiverName,
|
||||||
|
ReceiverMobile = o.Mobile,
|
||||||
|
TrackingCode = o.TrackingCode,
|
||||||
|
AdminNote = o.AdminNote,
|
||||||
|
Created = o.Created,
|
||||||
|
LastModified = o.LastModified,
|
||||||
|
ItemsCount = o.ItemsCount
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
return new GetAllDiscountOrdersResponseDto
|
return new GetAllDiscountOrdersResponseDto
|
||||||
{
|
{
|
||||||
MetaData = new MetaData
|
MetaData = new MetaData
|
||||||
|
|||||||
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
|
using CMSMicroservice.Application.Common;
|
||||||
using CMSMicroservice.Application.Common.Exceptions;
|
using CMSMicroservice.Application.Common.Exceptions;
|
||||||
using CMSMicroservice.Application.Common.Interfaces;
|
using CMSMicroservice.Application.Common.Interfaces;
|
||||||
using CMSMicroservice.Domain.Entities;
|
using CMSMicroservice.Domain.Entities;
|
||||||
@@ -50,7 +51,7 @@ public class GetCustomerOrderQueryHandler : IRequestHandler<GetCustomerOrderQuer
|
|||||||
DeliveryStatus = order.DeliveryStatus,
|
DeliveryStatus = order.DeliveryStatus,
|
||||||
TrackingCode = order.TrackingCode ?? "",
|
TrackingCode = order.TrackingCode ?? "",
|
||||||
DeliveryDescription = order.DeliveryDescription ?? "",
|
DeliveryDescription = order.DeliveryDescription ?? "",
|
||||||
UserFullName = $"{order.User?.FirstName ?? ""} {order.User?.LastName ?? ""}".Trim(),
|
UserFullName = UserDisplayName.From(order.User),
|
||||||
UserNationalCode = order.User?.NationalCode ?? "",
|
UserNationalCode = order.User?.NationalCode ?? "",
|
||||||
PostalCode = order.UserAddress?.PostalCode ?? "",
|
PostalCode = order.UserAddress?.PostalCode ?? "",
|
||||||
UserMobile = order.User?.Mobile ?? "",
|
UserMobile = order.User?.Mobile ?? "",
|
||||||
|
|||||||
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
|
using CMSMicroservice.Application.Common;
|
||||||
using CMSMicroservice.Application.Common.Extensions;
|
using CMSMicroservice.Application.Common.Extensions;
|
||||||
using CMSMicroservice.Application.Common.Interfaces;
|
using CMSMicroservice.Application.Common.Interfaces;
|
||||||
using CMSMicroservice.Application.Common.Models;
|
using CMSMicroservice.Application.Common.Models;
|
||||||
@@ -72,7 +73,7 @@ public class GetCustomerOrdersQueryHandler : IRequestHandler<GetCustomerOrdersQu
|
|||||||
DeliveryStatus = order.DeliveryStatus,
|
DeliveryStatus = order.DeliveryStatus,
|
||||||
TrackingCode = order.TrackingCode ?? "",
|
TrackingCode = order.TrackingCode ?? "",
|
||||||
DeliveryDescription = order.DeliveryDescription ?? "",
|
DeliveryDescription = order.DeliveryDescription ?? "",
|
||||||
UserFullName = $"{order.User?.FirstName ?? ""} {order.User?.LastName ?? ""}".Trim(),
|
UserFullName = UserDisplayName.From(order.User),
|
||||||
UserNationalCode = order.User?.NationalCode ?? "",
|
UserNationalCode = order.User?.NationalCode ?? "",
|
||||||
VatAmount = order.OrderVAT?.VATAmount ?? 0,
|
VatAmount = order.OrderVAT?.VATAmount ?? 0,
|
||||||
VatPercentage = order.OrderVAT != null ? (double)order.OrderVAT.VATRate * 100 : 0,
|
VatPercentage = order.OrderVAT != null ? (double)order.OrderVAT.VATRate * 100 : 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user