refactor(pagination): use PageNumber and PageSize value objects in http helpers and console commands
This commit is contained in:
parent
0c361c5ff7
commit
16573cb30c
4 changed files with 15 additions and 7 deletions
|
|
@ -6,6 +6,8 @@ namespace Infra\Http\Helpers;
|
|||
|
||||
use Illuminate\Http\Request as HttpRequest;
|
||||
use Shared\Pagination;
|
||||
use Shared\Pagination\PageNumber;
|
||||
use Shared\Pagination\PageSize;
|
||||
use Uri\Rfc3986\Uri;
|
||||
|
||||
final class RequestHelper
|
||||
|
|
@ -30,8 +32,8 @@ final class RequestHelper
|
|||
);
|
||||
|
||||
return Pagination::ofPage(
|
||||
$request->integer('page', 1),
|
||||
$pageSize
|
||||
new PageNumber($request->integer('page', 1)),
|
||||
new PageSize($pageSize)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ use Presentation\Console\Presenters\Brands\ListBrandsView;
|
|||
use Shared\DDD\Usecase\Builder\UsecaseBuilder;
|
||||
use Shared\DDD\Usecase\Builder\UsecaseExecutor;
|
||||
use Shared\Pagination;
|
||||
use Shared\Pagination\PageNumber;
|
||||
use Shared\Pagination\PageSize;
|
||||
|
||||
final class ListBrandsCommand extends Command
|
||||
{
|
||||
|
|
@ -69,8 +71,8 @@ final class ListBrandsCommand extends Command
|
|||
private function getPaginationFromOptions(): Pagination
|
||||
{
|
||||
return Pagination::ofPage(
|
||||
max(1, (int) $this->option('page')),
|
||||
clamp(1, (int) $this->option('per-page'), Pagination::MAX_PAGE_SIZE)
|
||||
new PageNumber(max(1, (int) $this->option('page'))),
|
||||
new PageSize(clamp((int) $this->option('per-page'), 1, Pagination::MAX_PAGE_SIZE))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ use Presentation\Console\Presenters\Clients\ListClientsView;
|
|||
use Shared\DDD\Usecase\Builder\UsecaseBuilder;
|
||||
use Shared\DDD\Usecase\Builder\UsecaseExecutor;
|
||||
use Shared\Pagination;
|
||||
use Shared\Pagination\PageNumber;
|
||||
use Shared\Pagination\PageSize;
|
||||
|
||||
final class ListClientsCommand extends Command
|
||||
{
|
||||
|
|
@ -69,8 +71,8 @@ final class ListClientsCommand extends Command
|
|||
private function getPaginationFromOptions(): Pagination
|
||||
{
|
||||
return Pagination::ofPage(
|
||||
max(1, (int) $this->option('page')),
|
||||
clamp(1, (int) $this->option('per-page'), Pagination::MAX_PAGE_SIZE)
|
||||
new PageNumber(max(1, (int) $this->option('page'))),
|
||||
new PageSize(clamp((int) $this->option('per-page'), 1, Pagination::MAX_PAGE_SIZE))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ use Presentation\Console\Presenters\Clients\FoundClientItem;
|
|||
use Ramsey\Uuid\Uuid;
|
||||
use Shared\Paginated;
|
||||
use Shared\Pagination;
|
||||
use Shared\Pagination\PageNumber;
|
||||
use Shared\Pagination\PageSize;
|
||||
|
||||
covers(
|
||||
FindClientPresenter::class,
|
||||
|
|
@ -40,7 +42,7 @@ describe('FindClientPresenter Unit Tests', function (): void {
|
|||
updatedAt: new \DateTimeImmutable('2024-01-01'),
|
||||
);
|
||||
|
||||
$paginated = new Paginated(Pagination::ofPage(1, 10), [$client], 1);
|
||||
$paginated = new Paginated(Pagination::ofPage(new PageNumber(1), new PageSize(10)), [$client], 1);
|
||||
$output = new Output($paginated);
|
||||
|
||||
$presenter = new FindClientPresenter();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue