Skip to content

Commit

Permalink
obtain itemsPerPage in PagerFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Apr 8, 2024
1 parent ccf4937 commit e28ffd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use ApiPlatform\State\Pagination\Pagination;
use Rekalogika\Contracts\Rekapager\Exception\InvalidArgumentException;
use Rekalogika\Contracts\Rekapager\Exception\UnexpectedValueException;
use Rekalogika\Contracts\Rekapager\PageableInterface;
Expand All @@ -31,6 +32,7 @@ class PagerFactory
public function __construct(
private readonly ?ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory,
private readonly PageIdentifierEncoderLocatorInterface $pageIdentifierEncoderLocator,
private readonly Pagination $pagination,
private readonly string $pageParameterName = 'page',
private readonly int $urlGenerationStrategy = UrlGeneratorInterface::ABS_PATH,
) {
Expand All @@ -49,6 +51,12 @@ public function getPage(
?Operation $operation = null,
array $context = []
): PageInterface {
$itemsPerPage = $this->pagination->getLimit($operation, $context);

if ($itemsPerPage > 1) {
$pageable = $pageable->withItemsPerPage($itemsPerPage);
}

$pageIdentifierEncoder = $this->pageIdentifierEncoderLocator
->getPageIdentifierEncoder($pageable::getPageIdentifierClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ public function getResult(
array $context = []
): iterable {
$pageable = new KeysetPageable(new QueryBuilderAdapter($queryBuilder));

$itemsPerPage = $this->pagination->getLimit($operation, $context);

if ($itemsPerPage > 1) {
$pageable = $pageable->withItemsPerPage($itemsPerPage);
}

$pager = $this->pagerFactory->createPager($pageable, $operation, $context);

return $pager;
Expand Down

0 comments on commit e28ffd7

Please sign in to comment.