diff --git a/src/Infra/Http/Helpers/RequestHelper.php b/src/Infra/Http/Helpers/RequestHelper.php index 02a1f30..d514bfb 100644 --- a/src/Infra/Http/Helpers/RequestHelper.php +++ b/src/Infra/Http/Helpers/RequestHelper.php @@ -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) ); } diff --git a/src/Presentation/Console/Commands/ListBrandsCommand.php b/src/Presentation/Console/Commands/ListBrandsCommand.php index e897ad2..577f276 100644 --- a/src/Presentation/Console/Commands/ListBrandsCommand.php +++ b/src/Presentation/Console/Commands/ListBrandsCommand.php @@ -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)) ); } } diff --git a/src/Presentation/Console/Commands/ListClientsCommand.php b/src/Presentation/Console/Commands/ListClientsCommand.php index 6e40b48..12d6f1e 100644 --- a/src/Presentation/Console/Commands/ListClientsCommand.php +++ b/src/Presentation/Console/Commands/ListClientsCommand.php @@ -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)) ); } } diff --git a/tests/Unit/Presentation/Console/Presenters/Clients/FindClientPresenterTest.php b/tests/Unit/Presentation/Console/Presenters/Clients/FindClientPresenterTest.php index 3560b97..91c755b 100644 --- a/tests/Unit/Presentation/Console/Presenters/Clients/FindClientPresenterTest.php +++ b/tests/Unit/Presentation/Console/Presenters/Clients/FindClientPresenterTest.php @@ -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();