Implement pagination in schedules

This commit is contained in:
Irfan 2021-06-21 09:46:19 +05:00
parent 65f2536e25
commit 1f1d090a24
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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(