Skip to content

Commit

Permalink
[Update] Season Controller
Browse files Browse the repository at this point in the history
- Updated episodes endpoint to order episodes by `number_total`
- Updated pagination to use `cursorPaginate` instead of traditional pagination
  • Loading branch information
kiritokatklian committed Nov 3, 2024
1 parent 0c3db78 commit 6833b23
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/Http/Controllers/API/v1/SeasonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,22 @@ public function details(Request $request, Season $season): JsonResponse
*
* @return JsonResponse
*/
public function episodes(GetSeasonEpisodesRequest $request, Season $season): JsonResponse
public function episodes(GetSeasonEpisodesRequest $request, Season $season)
{
$data = $request->validated();

// Get the episodes
$episodes = $season->episodes();
$episodes = $season->episodes()
->select('id', 'number_total')
->orderBy('number_total');

// Fillers
if ($data['hide_fillers'] ?? false) {
$episodes = $episodes->where('is_filler', '!=', $data['hide_fillers']);
}

// Paginate
$episodes = $episodes->paginate($data['limit'] ?? 25, page: $data['page'] ?? 1);
$episodes = $episodes->cursorPaginate($data['limit'] ?? 25);

// Get next page url minus domain
$nextPageURL = str_replace($request->root(), '', $episodes->nextPageUrl() ?? '');
Expand Down

0 comments on commit 6833b23

Please sign in to comment.