-
Notifications
You must be signed in to change notification settings - Fork 1
Cursor pagination #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
KondukterCRO
wants to merge
4
commits into
develop
Choose a base branch
from
dev-feature/cursor-pagination
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
60c34a9
feat(pagination): define cursor based pagination behaviour
KondukterCRO de42f6c
test(pagination): add cursor based test
KondukterCRO dd388c3
test(pagination): refactor data providers for more readability
KondukterCRO 3b4e4d8
refactor(pagination): make 1 interface
KondukterCRO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/Definition/Exception/Request/InvalidParameterValueException.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Undabot\JsonApi\Definition\Exception\Request; | ||
|
||
use Throwable; | ||
use Undabot\JsonApi\Implementation\Model\Source\Source; | ||
|
||
class InvalidParameterValueException extends RequestException | ||
{ | ||
public function __construct( | ||
private Source $source, | ||
string $message, | ||
$code = 0, | ||
Throwable $previous = null | ||
) { | ||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
public function source(): Source | ||
{ | ||
return $this->source; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Definition/Exception/Request/MaxPageSizeExceededException.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Undabot\JsonApi\Definition\Exception\Request; | ||
|
||
use Throwable; | ||
|
||
class MaxPageSizeExceededException extends RequestException | ||
{ | ||
public function __construct( | ||
int $requestedPageSize, | ||
int $maxPageSize, | ||
$code = 0, | ||
Throwable $previous = null | ||
) { | ||
parent::__construct( | ||
sprintf('You requested a size of %d, but %d is the maximum.', $requestedPageSize, $maxPageSize), | ||
$code, | ||
$previous, | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Definition/Exception/Request/RangePaginationNotSupportedException.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Undabot\JsonApi\Definition\Exception\Request; | ||
|
||
use Throwable; | ||
|
||
class RangePaginationNotSupportedException extends RequestException | ||
{ | ||
public function __construct( | ||
$code = 0, | ||
Throwable $previous = null | ||
) { | ||
parent::__construct( | ||
'Range pagination not supported', | ||
$code, | ||
$previous, | ||
); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Definition/Model/Request/Pagination/CursorInterface.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Undabot\JsonApi\Definition\Model\Request\Pagination; | ||
|
||
interface CursorInterface extends PaginationInterface | ||
{ | ||
public function getAfter(): ?string; | ||
|
||
public function getBefore(): ?string; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Implementation/Model/Request/Pagination/CursorBasedPagination.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Undabot\JsonApi\Implementation\Model\Request\Pagination; | ||
|
||
use Undabot\JsonApi\Definition\Exception\Request\InvalidParameterValueException; | ||
use Undabot\JsonApi\Definition\Model\Request\Pagination\CursorInterface; | ||
use Undabot\JsonApi\Implementation\Model\Source\Source; | ||
|
||
class CursorBasedPagination implements CursorInterface | ||
{ | ||
public const PARAM_PAGE_AFTER = 'after'; | ||
public const PARAM_PAGE_BEFORE = 'before'; | ||
public const PARAM_PAGE_SIZE = 'size'; | ||
|
||
public function __construct(private ?string $after, private ?string $before, private ?int $size) | ||
{ | ||
if (null === $this->after && null === $this->before && null === $this->size) { | ||
throw new InvalidParameterValueException(new Source(null), 'At least one of the params must be not null.'); | ||
} | ||
} | ||
|
||
public function getSize(): int | ||
{ | ||
return $this->size ?? 0; | ||
} | ||
|
||
public function getAfter(): ?string | ||
{ | ||
return $this->after; | ||
} | ||
|
||
public function getBefore(): ?string | ||
{ | ||
return $this->before; | ||
} | ||
|
||
public function getOffset(): int | ||
{ | ||
throw new \LogicException('Cursor based pagination does not have offset'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add extension of getOffset here: