Always allow specifying a page size with the API; closes #3218
This commit is contained in:
parent
9b46d59045
commit
48ad8f538e
8 changed files with 10 additions and 9 deletions
|
@ -65,7 +65,7 @@ class LocationController extends ApplicationApiController
|
||||||
$locations = QueryBuilder::for(Location::query())
|
$locations = QueryBuilder::for(Location::query())
|
||||||
->allowedFilters(['short', 'long'])
|
->allowedFilters(['short', 'long'])
|
||||||
->allowedSorts(['id'])
|
->allowedSorts(['id'])
|
||||||
->paginate(100);
|
->paginate($request->query('per_page') ?? 50);
|
||||||
|
|
||||||
return $this->fractal->collection($locations)
|
return $this->fractal->collection($locations)
|
||||||
->transformWith($this->getTransformer(LocationTransformer::class))
|
->transformWith($this->getTransformer(LocationTransformer::class))
|
||||||
|
|
|
@ -30,7 +30,7 @@ class NestController extends ApplicationApiController
|
||||||
*/
|
*/
|
||||||
public function index(GetNestsRequest $request): array
|
public function index(GetNestsRequest $request): array
|
||||||
{
|
{
|
||||||
$nests = $this->repository->paginated(50);
|
$nests = $this->repository->paginated($request->query('per_page') ?? 50);
|
||||||
|
|
||||||
return $this->fractal->collection($nests)
|
return $this->fractal->collection($nests)
|
||||||
->transformWith($this->getTransformer(NestTransformer::class))
|
->transformWith($this->getTransformer(NestTransformer::class))
|
||||||
|
|
|
@ -43,7 +43,7 @@ class AllocationController extends ApplicationApiController
|
||||||
*/
|
*/
|
||||||
public function index(GetAllocationsRequest $request, Node $node): array
|
public function index(GetAllocationsRequest $request, Node $node): array
|
||||||
{
|
{
|
||||||
$allocations = $node->allocations()->paginate(50);
|
$allocations = $node->allocations()->paginate($request->query('per_page') ?? 50);
|
||||||
|
|
||||||
return $this->fractal->collection($allocations)
|
return $this->fractal->collection($allocations)
|
||||||
->transformWith($this->getTransformer(AllocationTransformer::class))
|
->transformWith($this->getTransformer(AllocationTransformer::class))
|
||||||
|
@ -53,6 +53,7 @@ class AllocationController extends ApplicationApiController
|
||||||
/**
|
/**
|
||||||
* Store new allocations for a given node.
|
* Store new allocations for a given node.
|
||||||
*
|
*
|
||||||
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||||
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
|
||||||
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
|
||||||
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
|
||||||
|
|
|
@ -64,7 +64,7 @@ class NodeController extends ApplicationApiController
|
||||||
$nodes = QueryBuilder::for(Node::query())
|
$nodes = QueryBuilder::for(Node::query())
|
||||||
->allowedFilters(['uuid', 'name', 'fqdn', 'daemon_token_id'])
|
->allowedFilters(['uuid', 'name', 'fqdn', 'daemon_token_id'])
|
||||||
->allowedSorts(['id', 'uuid', 'memory', 'disk'])
|
->allowedSorts(['id', 'uuid', 'memory', 'disk'])
|
||||||
->paginate(100);
|
->paginate($request->query('per_page') ?? 50);
|
||||||
|
|
||||||
return $this->fractal->collection($nodes)
|
return $this->fractal->collection($nodes)
|
||||||
->transformWith($this->getTransformer(NodeTransformer::class))
|
->transformWith($this->getTransformer(NodeTransformer::class))
|
||||||
|
|
|
@ -37,7 +37,7 @@ class NodeDeploymentController extends ApplicationApiController
|
||||||
$nodes = $this->viableNodesService->setLocations($data['location_ids'] ?? [])
|
$nodes = $this->viableNodesService->setLocations($data['location_ids'] ?? [])
|
||||||
->setMemory($data['memory'])
|
->setMemory($data['memory'])
|
||||||
->setDisk($data['disk'])
|
->setDisk($data['disk'])
|
||||||
->handle($request->input('page') ?? 0);
|
->handle($request->query('per_page'), $request->query('page'));
|
||||||
|
|
||||||
return $this->fractal->collection($nodes)
|
return $this->fractal->collection($nodes)
|
||||||
->transformWith($this->getTransformer(NodeTransformer::class))
|
->transformWith($this->getTransformer(NodeTransformer::class))
|
||||||
|
|
|
@ -56,7 +56,7 @@ class ServerController extends ApplicationApiController
|
||||||
$servers = QueryBuilder::for(Server::query())
|
$servers = QueryBuilder::for(Server::query())
|
||||||
->allowedFilters(['uuid', 'name', 'image', 'external_id'])
|
->allowedFilters(['uuid', 'name', 'image', 'external_id'])
|
||||||
->allowedSorts(['id', 'uuid'])
|
->allowedSorts(['id', 'uuid'])
|
||||||
->paginate(100);
|
->paginate($request->query('per_page') ?? 50);
|
||||||
|
|
||||||
return $this->fractal->collection($servers)
|
return $this->fractal->collection($servers)
|
||||||
->transformWith($this->getTransformer(ServerTransformer::class))
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
||||||
|
|
|
@ -66,7 +66,7 @@ class UserController extends ApplicationApiController
|
||||||
$users = QueryBuilder::for(User::query())
|
$users = QueryBuilder::for(User::query())
|
||||||
->allowedFilters(['email', 'uuid', 'username', 'external_id'])
|
->allowedFilters(['email', 'uuid', 'username', 'external_id'])
|
||||||
->allowedSorts(['id', 'uuid'])
|
->allowedSorts(['id', 'uuid'])
|
||||||
->paginate(100);
|
->paginate($request->query('per_page') ?? 50);
|
||||||
|
|
||||||
return $this->fractal->collection($users)
|
return $this->fractal->collection($users)
|
||||||
->transformWith($this->getTransformer(UserTransformer::class))
|
->transformWith($this->getTransformer(UserTransformer::class))
|
||||||
|
|
|
@ -83,7 +83,7 @@ class FindViableNodesService
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
|
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
|
||||||
*/
|
*/
|
||||||
public function handle(int $page = null)
|
public function handle(int $perPage = null, int $page = null)
|
||||||
{
|
{
|
||||||
Assert::integer($this->disk, 'Disk space must be an int, got %s');
|
Assert::integer($this->disk, 'Disk space must be an int, got %s');
|
||||||
Assert::integer($this->memory, 'Memory usage must be an int, got %s');
|
Assert::integer($this->memory, 'Memory usage must be an int, got %s');
|
||||||
|
@ -103,7 +103,7 @@ class FindViableNodesService
|
||||||
->havingRaw('(IFNULL(SUM(servers.disk), 0) + ?) <= (nodes.disk * (1 + (nodes.disk_overallocate / 100)))', [$this->disk]);
|
->havingRaw('(IFNULL(SUM(servers.disk), 0) + ?) <= (nodes.disk * (1 + (nodes.disk_overallocate / 100)))', [$this->disk]);
|
||||||
|
|
||||||
if (!is_null($page)) {
|
if (!is_null($page)) {
|
||||||
$results = $results->paginate(50, ['*'], 'page', $page);
|
$results = $results->paginate($perPage ?? 50, ['*'], 'page', $page);
|
||||||
} else {
|
} else {
|
||||||
$results = $results->get()->toBase();
|
$results = $results->get()->toBase();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue