Skip to content

Commit e273c7c

Browse files
committed
Refactor asset retrieval to support pagination.
Introduced offset and limit handling for API asset queries to enable proper pagination. Adjusted the total count logic to maintain consistency in responses and ensure accurate transformation of assets.
1 parent 2d3514b commit e273c7c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/Http/Controllers/Api/AssetsController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,14 @@ public function showBySerial(Request $request, $serial): JsonResponse | array
498498
$assets = $assets->withTrashed();
499499
}
500500

501-
if (($assets = $assets->get()) && ($assets->count()) > 0) {
502-
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
501+
$offset = ($request->input('offset') > $assets->count()) ? $assets->count() : app('api_offset_value');
502+
$limit = app('api_limit_value');
503+
504+
$total = $assets->count();
505+
$assets = $assets->skip($offset)->take($limit)->get();
506+
507+
if (($assets) && ($assets->count()) > 0) {
508+
return (new AssetsTransformer)->transformAssets($assets, $total);
503509
}
504510

505511
// If there are 0 results, return the "no such asset" response

0 commit comments

Comments
 (0)