From c25276b9a842f1bfd79eb05ad417ee8b15d7d2aa Mon Sep 17 00:00:00 2001 From: Constantin Graf Date: Fri, 26 Apr 2024 15:14:28 +0200 Subject: [PATCH] Added per page pagination config --- .../Controllers/Api/V1/ClientController.php | 2 +- .../Api/V1/InvitationController.php | 2 +- .../Controllers/Api/V1/MemberController.php | 2 +- .../Controllers/Api/V1/ProjectController.php | 5 ++-- .../Api/V1/ProjectMemberController.php | 2 +- app/Http/Controllers/Api/V1/TagController.php | 2 +- .../Controllers/Api/V1/TaskController.php | 2 +- .../V1/Project/ProjectIndexRequest.php | 26 +++++++++++++++++++ config/app.php | 3 ++- 9 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 app/Http/Requests/V1/Project/ProjectIndexRequest.php diff --git a/app/Http/Controllers/Api/V1/ClientController.php b/app/Http/Controllers/Api/V1/ClientController.php index 5108511a..cc23e920 100644 --- a/app/Http/Controllers/Api/V1/ClientController.php +++ b/app/Http/Controllers/Api/V1/ClientController.php @@ -40,7 +40,7 @@ public function index(Organization $organization): ClientCollection $clients = Client::query() ->whereBelongsTo($organization, 'organization') ->orderBy('created_at', 'desc') - ->paginate(); + ->paginate(config('app.pagination_per_page_default')); return new ClientCollection($clients); } diff --git a/app/Http/Controllers/Api/V1/InvitationController.php b/app/Http/Controllers/Api/V1/InvitationController.php index 94875cbc..e7d45a79 100644 --- a/app/Http/Controllers/Api/V1/InvitationController.php +++ b/app/Http/Controllers/Api/V1/InvitationController.php @@ -40,7 +40,7 @@ public function index(Organization $organization, InvitationIndexRequest $reques $this->checkPermission($organization, 'invitations:view'); $invitations = $organization->teamInvitations() - ->paginate(); + ->paginate(config('app.pagination_per_page_default')); return InvitationCollection::make($invitations); } diff --git a/app/Http/Controllers/Api/V1/MemberController.php b/app/Http/Controllers/Api/V1/MemberController.php index 38a5f12b..786bc527 100644 --- a/app/Http/Controllers/Api/V1/MemberController.php +++ b/app/Http/Controllers/Api/V1/MemberController.php @@ -45,7 +45,7 @@ public function index(Organization $organization, MemberIndexRequest $request): $this->checkPermission($organization, 'members:view'); $members = $organization->users() - ->paginate(); + ->paginate(config('app.pagination_per_page_default')); return MemberCollection::make($members); } diff --git a/app/Http/Controllers/Api/V1/ProjectController.php b/app/Http/Controllers/Api/V1/ProjectController.php index 4a4ff3a8..58c4e248 100644 --- a/app/Http/Controllers/Api/V1/ProjectController.php +++ b/app/Http/Controllers/Api/V1/ProjectController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api\V1; use App\Exceptions\Api\EntityStillInUseApiException; +use App\Http\Requests\V1\Project\ProjectIndexRequest; use App\Http\Requests\V1\Project\ProjectStoreRequest; use App\Http\Requests\V1\Project\ProjectUpdateRequest; use App\Http\Resources\V1\Project\ProjectCollection; @@ -38,7 +39,7 @@ protected function checkPermission(Organization $organization, string $permissio * * @operationId getProjects */ - public function index(Organization $organization): ProjectCollection + public function index(Organization $organization, ProjectIndexRequest $request): ProjectCollection { $this->checkPermission($organization, 'projects:view'); $canViewAllProjects = $this->hasPermission($organization, 'projects:view:all'); @@ -52,7 +53,7 @@ public function index(Organization $organization): ProjectCollection $projectsQuery->visibleByUser($user); } - $projects = $projectsQuery->paginate(); + $projects = $projectsQuery->paginate(config('app.pagination_per_page_default')); return new ProjectCollection($projects); } diff --git a/app/Http/Controllers/Api/V1/ProjectMemberController.php b/app/Http/Controllers/Api/V1/ProjectMemberController.php index 2b0e1e5a..b6cd1881 100644 --- a/app/Http/Controllers/Api/V1/ProjectMemberController.php +++ b/app/Http/Controllers/Api/V1/ProjectMemberController.php @@ -46,7 +46,7 @@ public function index(Organization $organization, Project $project): ProjectMemb $projectMembers = ProjectMember::query() ->whereBelongsTo($project, 'project') - ->paginate(); + ->paginate(config('app.pagination_per_page_default')); return new ProjectMemberCollection($projectMembers); } diff --git a/app/Http/Controllers/Api/V1/TagController.php b/app/Http/Controllers/Api/V1/TagController.php index 240d50f7..eb857a94 100644 --- a/app/Http/Controllers/Api/V1/TagController.php +++ b/app/Http/Controllers/Api/V1/TagController.php @@ -41,7 +41,7 @@ public function index(Organization $organization): TagCollection $tags = Tag::query() ->whereBelongsTo($organization, 'organization') ->orderBy('created_at', 'desc') - ->paginate(); + ->paginate(config('app.pagination_per_page_default')); return new TagCollection($tags); } diff --git a/app/Http/Controllers/Api/V1/TaskController.php b/app/Http/Controllers/Api/V1/TaskController.php index 20b96626..0cb0e947 100644 --- a/app/Http/Controllers/Api/V1/TaskController.php +++ b/app/Http/Controllers/Api/V1/TaskController.php @@ -62,7 +62,7 @@ public function index(Organization $organization, TaskIndexRequest $request): Ta }); } - $tasks = $query->paginate(); + $tasks = $query->paginate(config('app.pagination_per_page_default')); return new TaskCollection($tasks); } diff --git a/app/Http/Requests/V1/Project/ProjectIndexRequest.php b/app/Http/Requests/V1/Project/ProjectIndexRequest.php new file mode 100644 index 00000000..f71b3e16 --- /dev/null +++ b/app/Http/Requests/V1/Project/ProjectIndexRequest.php @@ -0,0 +1,26 @@ +> + */ + public function rules(): array + { + return [ + 'page' => [ + 'integer', + 'min:1', + ], + ]; + } +} diff --git a/config/app.php b/config/app.php index f2da18e5..d05bf660 100644 --- a/config/app.php +++ b/config/app.php @@ -115,6 +115,8 @@ 'faker_locale' => 'en_US', + 'pagination_per_page_default' => (int) env('PAGINATION_PER_PAGE_DEFAULT', 15), + /* |-------------------------------------------------------------------------- | Encryption Key @@ -191,5 +193,4 @@ 'aliases' => Facade::defaultAliases()->merge([ // 'Example' => App\Facades\Example::class, ])->toArray(), - ];