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
|
var query = _context.UserOrders
|
||||||
.Include(i => i.UserAddress)
|
.Include(i => i.UserAddress)
|
||||||
|
.Include(i => i.User)
|
||||||
.Include(i => i.FactorDetailss)
|
.Include(i => i.FactorDetailss)
|
||||||
.ThenInclude(t=>t.Product)
|
.ThenInclude(t => t.Product)
|
||||||
.ApplyOrder(sortBy: request.SortBy)
|
.ApplyOrder(sortBy: request.SortBy)
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.AsQueryable();
|
.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.PaymentMethod == null || x.PaymentMethod == request.Filter.PaymentMethod)
|
||||||
.Where(x => request.Filter.DeliveryStatus == null || x.DeliveryStatus == request.Filter.DeliveryStatus);
|
.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
|
return new GetAllUserOrderByFilterResponseDto
|
||||||
{
|
{
|
||||||
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
|
MetaData = meta,
|
||||||
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
|
Models = models
|
||||||
.ProjectToType<GetAllUserOrderByFilterResponseModel>().ToListAsync(cancellationToken)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ public class GetAllUserOrderByFilterResponseDto
|
|||||||
public string? TrackingCode { get; set; }
|
public string? TrackingCode { get; set; }
|
||||||
// توضیحات ارسال
|
// توضیحات ارسال
|
||||||
public string? DeliveryDescription { get; set; }
|
public string? DeliveryDescription { get; set; }
|
||||||
|
// نام کامل کاربر
|
||||||
|
public string? UserFullName { get; set; }
|
||||||
|
// کدملی کاربر
|
||||||
|
public string? UserNationalCode { get; set; }
|
||||||
}
|
}
|
||||||
public class GetAllUserOrderByFilterResponseModelFactorDetail
|
public class GetAllUserOrderByFilterResponseModelFactorDetail
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,11 +13,38 @@ public class GetUserOrderQueryHandler : IRequestHandler<GetUserOrderQuery, GetUs
|
|||||||
{
|
{
|
||||||
var response = await _context.UserOrders
|
var response = await _context.UserOrders
|
||||||
.Include(i => i.UserAddress)
|
.Include(i => i.UserAddress)
|
||||||
|
.Include(i => i.User)
|
||||||
.Include(i => i.FactorDetailss)
|
.Include(i => i.FactorDetailss)
|
||||||
.ThenInclude(t=>t.Product)
|
.ThenInclude(t => t.Product)
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Where(x => x.Id == request.Id)
|
.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);
|
.FirstOrDefaultAsync(cancellationToken);
|
||||||
|
|
||||||
return response ?? throw new NotFoundException(nameof(UserOrder), request.Id);
|
return response ?? throw new NotFoundException(nameof(UserOrder), request.Id);
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ public class GetUserOrderResponseDto
|
|||||||
public string? TrackingCode { get; set; }
|
public string? TrackingCode { get; set; }
|
||||||
// توضیحات ارسال
|
// توضیحات ارسال
|
||||||
public string? DeliveryDescription { get; set; }
|
public string? DeliveryDescription { get; set; }
|
||||||
|
// نام کامل کاربر
|
||||||
|
public string? UserFullName { get; set; }
|
||||||
|
// کدملی کاربر
|
||||||
|
public string? UserNationalCode { get; set; }
|
||||||
|
|
||||||
}public class GetUserOrderResponseFactorDetail
|
}public class GetUserOrderResponseFactorDetail
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -130,6 +130,9 @@ message GetUserOrderResponse
|
|||||||
}
|
}
|
||||||
google.protobuf.StringValue tracking_code = 13;
|
google.protobuf.StringValue tracking_code = 13;
|
||||||
google.protobuf.StringValue delivery_description = 14;
|
google.protobuf.StringValue delivery_description = 14;
|
||||||
|
// نام کامل و کدملی کاربر
|
||||||
|
google.protobuf.StringValue user_full_name = 15;
|
||||||
|
google.protobuf.StringValue user_national_code = 16;
|
||||||
}
|
}
|
||||||
message GetUserOrderResponseFactorDetail
|
message GetUserOrderResponseFactorDetail
|
||||||
{
|
{
|
||||||
@@ -200,6 +203,9 @@ message GetAllUserOrderByFilterResponseModel
|
|||||||
}
|
}
|
||||||
google.protobuf.StringValue tracking_code = 13;
|
google.protobuf.StringValue tracking_code = 13;
|
||||||
google.protobuf.StringValue delivery_description = 14;
|
google.protobuf.StringValue delivery_description = 14;
|
||||||
|
// نام کامل و کدملی کاربر
|
||||||
|
google.protobuf.StringValue user_full_name = 15;
|
||||||
|
google.protobuf.StringValue user_national_code = 16;
|
||||||
}
|
}
|
||||||
message GetAllUserOrderByFilterResponseModelFactorDetail
|
message GetAllUserOrderByFilterResponseModelFactorDetail
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user