Skip to content

Commit

Permalink
Merge 677f923 into 3716126
Browse files Browse the repository at this point in the history
  • Loading branch information
webant-ltd committed Apr 16, 2020
2 parents 3716126 + 677f923 commit 73c2621
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions features/jsonapi/pagination.feature
Expand Up @@ -36,3 +36,7 @@ Feature: JSON API pagination handling
Scenario: Get an error when provided page number is not valid
When I send a "GET" request to "/dummies?page[page]=0"
Then the response status code should be 400

Scenario: Get an error when provided page number is too large
When I send a "GET" request to "/dummies?page[page]=9223372036854775807"
Then the response status code should be 400
8 changes: 7 additions & 1 deletion src/DataProvider/Pagination.php
Expand Up @@ -90,8 +90,14 @@ public function getOffset(string $resourceClass = null, string $operationName =
if ($graphql && null !== ($last = $this->getParameterFromContext($context, 'last'))) {
return ($offset = ($context['count'] ?? 0) - $last) < 0 ? 0 : $offset;
}

$offset = ($this->getPage($context) - 1) * $limit;

if (!\is_int($offset)) {
throw new InvalidArgumentException('Page parameter is too large.');
}

return ($this->getPage($context) - 1) * $limit;
return $offset;
}

/**
Expand Down

0 comments on commit 73c2621

Please sign in to comment.