Add limit param to all endpoints

This commit is contained in:
James Cole
2023-10-05 18:52:01 +02:00
parent a29d056a9b
commit 664a08d42f
46 changed files with 136 additions and 138 deletions

View File

@@ -64,6 +64,7 @@ class ShowController extends Controller
public function index(Request $request): JsonResponse
{
$collection = new Collection();
$pageSize = $this->parameters->get('limit');
// if the user has the system owner role, get all. Otherwise, get only the users' groups.
if (!auth()->user()->hasRole('owner')) {
$collection = $this->repository->get();
@@ -72,9 +73,9 @@ class ShowController extends Controller
$collection = $this->repository->getAll();
}
$count = $collection->count();
$userGroups = $collection->slice(($this->parameters->get('page') - 1) * $this->pageSize, $this->pageSize);
$userGroups = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($userGroups, $count, $this->pageSize, $this->parameters->get('page'));
$paginator = new LengthAwarePaginator($userGroups, $count, $pageSize, $this->parameters->get('page'));
$transformer = new UserGroupTransformer();
$transformer->setParameters($this->parameters); // give params to transformer