Skip to content

Commit

Permalink
Add start cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
mdpoulter committed Nov 14, 2023
1 parent 7da82ae commit 0778084
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Common/Paginators/VendCursorPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class VendCursorPaginator extends Paginator

protected string $limitKeyName = 'page_size';

protected int $startCursor = 0;

protected function isLastPage(Response $response): bool
{
return empty($response->json('data'));
Expand All @@ -26,14 +28,25 @@ protected function getPageItems(Response $response, Request $request): array

protected function applyPagination(Request $request): Request
{
$cursor = $this->startCursor;

if ($this->currentResponse instanceof Response) {
$request->query()->add($this->cursorKeyName, $this->currentResponse->json('version.max'));
$cursor = max($cursor, $this->currentResponse->json('version.max'));
}

$request->query()->add($this->cursorKeyName, $cursor);

if (isset($this->perPageLimit)) {
$request->query()->add($this->limitKeyName, $this->perPageLimit);
}

return $request;
}

public function setStartCursor(int $cursor): static
{
$this->startCursor = $cursor;

return $this;
}
}
9 changes: 9 additions & 0 deletions src/Common/Paginators/VendOffsetPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@ protected function applyPagination(Request $request): Request

return $request;
}

public function setStartPage(int $startPage): static
{
parent::setStartPage($startPage);

$this->page = max($this->page, $this->startPage);

return $this;
}
}

0 comments on commit 0778084

Please sign in to comment.