Skip to content

Commit

Permalink
Fix issues with offset-based pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed May 28, 2019
1 parent 57313e2 commit f417f66
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public function getFirstLink(string $uri, string $queryString): ?Link

public function getLastLink(string $uri, string $queryString): ?Link
{
return $this->createPaginatedLink($uri, $queryString, $this->getTotalItems() - $this->getLimit() - 1, $this->getLimit());
return $this->createPaginatedLink($uri, $queryString, max($this->getTotalItems() - $this->getLimit(), 0), $this->getLimit());
}

public function getPrevLink(string $uri, string $queryString): ?Link
{
if ($this->getOffset() <= 0 || $this->getOffset() + $this->getLimit() >= $this->getTotalItems()) {
if ($this->getOffset() <= 0 || $this->getOffset() + $this->getLimit() > $this->getTotalItems()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function getLastLinkWhenQueryStringIsProvided()

$link = $provider->getLastLink("https://example.com/api/users?a=b", "");

$this->assertEquals("https://example.com/api/users?a=b&page[offset]=39&page[limit]=10", urldecode($link->getHref()));
$this->assertEquals("https://example.com/api/users?a=b&page[offset]=40&page[limit]=10", urldecode($link->getHref()));
}

/**
Expand Down

0 comments on commit f417f66

Please sign in to comment.