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 filter = request.Filter;
|
||||||
var pagination = request.PaginationState ?? new PaginationState { PageNumber = 1, PageSize = 20 };
|
var pagination = request.PaginationState ?? new PaginationState { PageNumber = 1, PageSize = 20 };
|
||||||
if (pagination.PageNumber < 1) pagination.PageNumber = 1;
|
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
|
var purchases = _context.UserPackagePurchases
|
||||||
@@ -104,14 +106,18 @@ public class GetCustomerPackagePurchaseRollupQueryHandler
|
|||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var totalCount = grouped.Count;
|
var totalCount = grouped.Count;
|
||||||
var pageSize = pagination.PageSize;
|
var pageNumber = exportAll ? 1 : pagination.PageNumber;
|
||||||
var pageNumber = pagination.PageNumber;
|
var pageSize = exportAll ? totalCount : pagination.PageSize;
|
||||||
var totalPage = pageSize > 0 ? (int)Math.Ceiling(totalCount / (double)pageSize) : 0;
|
var totalPage = exportAll || pageSize <= 0
|
||||||
|
? (totalCount > 0 ? 1 : 0)
|
||||||
|
: (int)Math.Ceiling(totalCount / (double)pageSize);
|
||||||
|
|
||||||
var pageModels = grouped
|
var pageModels = exportAll
|
||||||
.Skip((pageNumber - 1) * pageSize)
|
? grouped
|
||||||
.Take(pageSize)
|
: grouped
|
||||||
.ToList();
|
.Skip((pageNumber - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
return new GetCustomerPackagePurchaseRollupResponseDto
|
return new GetCustomerPackagePurchaseRollupResponseDto
|
||||||
{
|
{
|
||||||
@@ -121,8 +127,8 @@ public class GetCustomerPackagePurchaseRollupQueryHandler
|
|||||||
PageSize = pageSize,
|
PageSize = pageSize,
|
||||||
TotalCount = totalCount,
|
TotalCount = totalCount,
|
||||||
TotalPage = totalPage,
|
TotalPage = totalPage,
|
||||||
HasPrevious = pageNumber > 1,
|
HasPrevious = !exportAll && pageNumber > 1,
|
||||||
HasNext = pageNumber < totalPage
|
HasNext = !exportAll && pageNumber < totalPage
|
||||||
},
|
},
|
||||||
Models = pageModels
|
Models = pageModels
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user