From 1f1d090a24725731570092933207a4995bf3e137 Mon Sep 17 00:00:00 2001 From: Irfan Date: Mon, 21 Jun 2021 09:46:19 +0500 Subject: [PATCH] Implement pagination in schedules --- .env.dist | 9 ++++++++- app/Http/Controllers/V4DB/ScheduleController.php | 13 ++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.env.dist b/.env.dist index da38245..925b8df 100755 --- a/.env.dist +++ b/.env.dist @@ -20,6 +20,11 @@ DB_ADMIN=jikan DB_USERNAME= DB_PASSWORD= +### +# Database query default values +### +MAX_RESULTS_PER_PAGE=25 + ### # Enable MyAnimeList Heartbeat # @@ -110,5 +115,7 @@ PATREON=false PATREON_CLIENT_ID= PATREON_CLIENT_SECRET= - +### +# OpenAPI +### SWAGGER_VERSION=3.0 \ No newline at end of file diff --git a/app/Http/Controllers/V4DB/ScheduleController.php b/app/Http/Controllers/V4DB/ScheduleController.php index cff3704..aee4607 100644 --- a/app/Http/Controllers/V4DB/ScheduleController.php +++ b/app/Http/Controllers/V4DB/ScheduleController.php @@ -142,6 +142,9 @@ class ScheduleController extends Controller { $this->request = $request; + $page = $this->request->get('page') ?? 1; + $limit = $this->request->get('limit') ?? (int) env('MAX_RESULTS_PER_PAGE', 25); + if (!is_null($day)) { $this->day = strtolower($day); } @@ -173,8 +176,16 @@ class ScheduleController extends Controller ->where('broadcast', 'Not scheduled once per week'); } + $results = $results + ->paginate( + $limit, + ['*'], + null, + $page + ); + $response = (new AnimeCollection( - $results->get() + $results ))->response(); return $this->prepareResponse(