Add user full name and national code to order responses
This commit is contained in:
@@ -12,8 +12,9 @@ public class GetAllUserOrderByFilterQueryHandler : IRequestHandler<GetAllUserOrd
|
||||
{
|
||||
var query = _context.UserOrders
|
||||
.Include(i => i.UserAddress)
|
||||
.Include(i => i.User)
|
||||
.Include(i => i.FactorDetailss)
|
||||
.ThenInclude(t=>t.Product)
|
||||
.ThenInclude(t => t.Product)
|
||||
.ApplyOrder(sortBy: request.SortBy)
|
||||
.AsNoTracking()
|
||||
.AsQueryable();
|
||||
@@ -31,11 +32,43 @@ public class GetAllUserOrderByFilterQueryHandler : IRequestHandler<GetAllUserOrd
|
||||
.Where(x => request.Filter.PaymentMethod == null || x.PaymentMethod == request.Filter.PaymentMethod)
|
||||
.Where(x => request.Filter.DeliveryStatus == null || x.DeliveryStatus == request.Filter.DeliveryStatus);
|
||||
}
|
||||
var meta = await query.GetMetaData(request.PaginationState, cancellationToken);
|
||||
|
||||
var models = await query
|
||||
.PaginatedListAsync(paginationState: request.PaginationState)
|
||||
.Select(x => new GetAllUserOrderByFilterResponseModel
|
||||
{
|
||||
Id = x.Id,
|
||||
Amount = x.Amount,
|
||||
PackageId = x.PackageId ?? 0,
|
||||
TransactionId = x.TransactionId,
|
||||
PaymentStatus = x.PaymentStatus,
|
||||
PaymentDate = x.PaymentDate,
|
||||
UserId = x.UserId,
|
||||
UserAddressId = x.UserAddressId,
|
||||
PaymentMethod = x.PaymentMethod,
|
||||
UserAddressText = x.UserAddress.Address,
|
||||
FactorDetails = x.FactorDetailss.Select(fd => new GetAllUserOrderByFilterResponseModelFactorDetail
|
||||
{
|
||||
ProductId = fd.ProductId,
|
||||
ProductTitle = fd.Product.Title,
|
||||
ProductThumbnailPath = fd.Product.ThumbnailPath,
|
||||
UnitPrice = fd.UnitPrice,
|
||||
Count = fd.Count,
|
||||
UnitDiscountPrice = fd.UnitDiscountPrice
|
||||
}).ToList(),
|
||||
DeliveryStatus = x.DeliveryStatus,
|
||||
TrackingCode = x.TrackingCode,
|
||||
DeliveryDescription = x.DeliveryDescription,
|
||||
UserFullName = (x.User.FirstName ?? string.Empty) + " " + (x.User.LastName ?? string.Empty),
|
||||
UserNationalCode = x.User.NationalCode
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetAllUserOrderByFilterResponseDto
|
||||
{
|
||||
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
|
||||
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
|
||||
.ProjectToType<GetAllUserOrderByFilterResponseModel>().ToListAsync(cancellationToken)
|
||||
MetaData = meta,
|
||||
Models = models
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ public class GetAllUserOrderByFilterResponseDto
|
||||
public string? TrackingCode { get; set; }
|
||||
// توضیحات ارسال
|
||||
public string? DeliveryDescription { get; set; }
|
||||
// نام کامل کاربر
|
||||
public string? UserFullName { get; set; }
|
||||
// کدملی کاربر
|
||||
public string? UserNationalCode { get; set; }
|
||||
}
|
||||
public class GetAllUserOrderByFilterResponseModelFactorDetail
|
||||
{
|
||||
|
||||
@@ -13,11 +13,38 @@ public class GetUserOrderQueryHandler : IRequestHandler<GetUserOrderQuery, GetUs
|
||||
{
|
||||
var response = await _context.UserOrders
|
||||
.Include(i => i.UserAddress)
|
||||
.Include(i => i.User)
|
||||
.Include(i => i.FactorDetailss)
|
||||
.ThenInclude(t=>t.Product)
|
||||
.ThenInclude(t => t.Product)
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.ProjectToType<GetUserOrderResponseDto>()
|
||||
.Select(x => new GetUserOrderResponseDto
|
||||
{
|
||||
Id = x.Id,
|
||||
Amount = x.Amount,
|
||||
PackageId = x.PackageId ?? 0,
|
||||
TransactionId = x.TransactionId,
|
||||
PaymentStatus = x.PaymentStatus,
|
||||
PaymentDate = x.PaymentDate,
|
||||
UserId = x.UserId,
|
||||
UserAddressId = x.UserAddressId,
|
||||
PaymentMethod = x.PaymentMethod,
|
||||
UserAddressText = x.UserAddress.Address,
|
||||
FactorDetails = x.FactorDetailss.Select(fd => new GetUserOrderResponseFactorDetail
|
||||
{
|
||||
ProductId = fd.ProductId,
|
||||
ProductTitle = fd.Product.Title,
|
||||
ProductThumbnailPath = fd.Product.ThumbnailPath,
|
||||
UnitPrice = fd.UnitPrice,
|
||||
Count = fd.Count,
|
||||
UnitDiscountPrice = fd.UnitDiscountPrice
|
||||
}).ToList(),
|
||||
DeliveryStatus = x.DeliveryStatus,
|
||||
TrackingCode = x.TrackingCode,
|
||||
DeliveryDescription = x.DeliveryDescription,
|
||||
UserFullName = (x.User.FirstName ?? string.Empty) + " " + (x.User.LastName ?? string.Empty),
|
||||
UserNationalCode = x.User.NationalCode
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
return response ?? throw new NotFoundException(nameof(UserOrder), request.Id);
|
||||
|
||||
@@ -31,6 +31,10 @@ public class GetUserOrderResponseDto
|
||||
public string? TrackingCode { get; set; }
|
||||
// توضیحات ارسال
|
||||
public string? DeliveryDescription { get; set; }
|
||||
// نام کامل کاربر
|
||||
public string? UserFullName { get; set; }
|
||||
// کدملی کاربر
|
||||
public string? UserNationalCode { get; set; }
|
||||
|
||||
}public class GetUserOrderResponseFactorDetail
|
||||
{
|
||||
|
||||
@@ -130,6 +130,9 @@ message GetUserOrderResponse
|
||||
}
|
||||
google.protobuf.StringValue tracking_code = 13;
|
||||
google.protobuf.StringValue delivery_description = 14;
|
||||
// نام کامل و کدملی کاربر
|
||||
google.protobuf.StringValue user_full_name = 15;
|
||||
google.protobuf.StringValue user_national_code = 16;
|
||||
}
|
||||
message GetUserOrderResponseFactorDetail
|
||||
{
|
||||
@@ -200,6 +203,9 @@ message GetAllUserOrderByFilterResponseModel
|
||||
}
|
||||
google.protobuf.StringValue tracking_code = 13;
|
||||
google.protobuf.StringValue delivery_description = 14;
|
||||
// نام کامل و کدملی کاربر
|
||||
google.protobuf.StringValue user_full_name = 15;
|
||||
google.protobuf.StringValue user_national_code = 16;
|
||||
}
|
||||
message GetAllUserOrderByFilterResponseModelFactorDetail
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user