feat(package): enhance pagination logic in GetCustomerPackagePurchaseRollupQueryHandler
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m42s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m42s
- Updated pagination handling to allow for exporting all results when PageSize is set to 0. - Adjusted page size and number calculations to accommodate the new export functionality. - Improved clarity in pagination logic by distinguishing between export and paginated results.
This commit is contained in:
+16
-10
@@ -22,7 +22,9 @@ public class GetCustomerPackagePurchaseRollupQueryHandler
|
||||
var filter = request.Filter;
|
||||
var pagination = request.PaginationState ?? new PaginationState { PageNumber = 1, PageSize = 20 };
|
||||
if (pagination.PageNumber < 1) pagination.PageNumber = 1;
|
||||
if (pagination.PageSize < 1) pagination.PageSize = 20;
|
||||
// PageSize == 0 → خروجی کامل (بدون صفحهبندی)، مثلاً Excel
|
||||
var exportAll = pagination.PageSize == 0;
|
||||
if (!exportAll && pagination.PageSize < 1) pagination.PageSize = 20;
|
||||
|
||||
// خرید معتبر: بدون تراکنش یا تراکنش موفق
|
||||
var purchases = _context.UserPackagePurchases
|
||||
@@ -104,14 +106,18 @@ public class GetCustomerPackagePurchaseRollupQueryHandler
|
||||
.ToList();
|
||||
|
||||
var totalCount = grouped.Count;
|
||||
var pageSize = pagination.PageSize;
|
||||
var pageNumber = pagination.PageNumber;
|
||||
var totalPage = pageSize > 0 ? (int)Math.Ceiling(totalCount / (double)pageSize) : 0;
|
||||
var pageNumber = exportAll ? 1 : pagination.PageNumber;
|
||||
var pageSize = exportAll ? totalCount : pagination.PageSize;
|
||||
var totalPage = exportAll || pageSize <= 0
|
||||
? (totalCount > 0 ? 1 : 0)
|
||||
: (int)Math.Ceiling(totalCount / (double)pageSize);
|
||||
|
||||
var pageModels = grouped
|
||||
.Skip((pageNumber - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
var pageModels = exportAll
|
||||
? grouped
|
||||
: grouped
|
||||
.Skip((pageNumber - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
|
||||
return new GetCustomerPackagePurchaseRollupResponseDto
|
||||
{
|
||||
@@ -121,8 +127,8 @@ public class GetCustomerPackagePurchaseRollupQueryHandler
|
||||
PageSize = pageSize,
|
||||
TotalCount = totalCount,
|
||||
TotalPage = totalPage,
|
||||
HasPrevious = pageNumber > 1,
|
||||
HasNext = pageNumber < totalPage
|
||||
HasPrevious = !exportAll && pageNumber > 1,
|
||||
HasNext = !exportAll && pageNumber < totalPage
|
||||
},
|
||||
Models = pageModels
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user