Skip to content

Commit

Permalink
Add params paginate mode to user webinars list (#53)
Browse files Browse the repository at this point in the history
Co-authored-by: Hubert Krzysztofiak <hubert.krzysztofiak@escolasoft.com>
  • Loading branch information
HerbertIV and Hubert Krzysztofiak committed Dec 16, 2022
1 parent ad0d053 commit e2d6c7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/Http/Controllers/Swagger/WebinarAPISwagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ public function show(int $id): JsonResponse;
* ),
* ),
* @OA\Parameter(
* name="paginate",
* description="If true, list convert to paginate",
* required=false,
* in="query",
* @OA\Schema(
* type="boolean",
* default=false,
* ),
* ),
* @OA\Parameter(
* name="page",
* description="Pagination Page Number",
* required=false,
Expand Down
12 changes: 9 additions & 3 deletions src/Http/Controllers/WebinarAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ public function show(int $id): JsonResponse
public function forCurrentUser(ListWebinarsRequest $listWebinarsRequest): JsonResponse
{
$search = $listWebinarsRequest->except(['limit', 'skip', 'order', 'order_by']);
$webinars = $this->webinarServiceContract
->getWebinarsListForCurrentUser($search)
->get();
$webinars = $this->webinarServiceContract->getWebinarsListForCurrentUser($search);
if ($listWebinarsRequest->input('paginate', false)) {
$webinars = $webinars->paginate(
$listWebinarsRequest->get('per_page') ??
config('escolalms_webinar.perPage', ConstantEnum::PER_PAGE)
);
} else {
$webinars = $webinars->get();
}

return $this->sendResponseForResource(
$this->webinarServiceContract->extendResponse(WebinarSimpleResource::collection($webinars), true),
Expand Down

0 comments on commit e2d6c7c

Please sign in to comment.