From 06422b20557ba2340b23e656f7bcafd60668741d Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 7 Oct 2016 14:26:50 -0400 Subject: [PATCH] fix up API route return --- CHANGELOG.md | 5 ++--- app/Http/Controllers/API/LocationController.php | 2 +- app/Http/Controllers/API/NodeController.php | 7 +++---- app/Http/Controllers/API/ServerController.php | 9 +++------ app/Http/Controllers/API/ServiceController.php | 2 +- app/Repositories/ServerRepository.php | 2 +- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c93b6ce10..0d9a4dfcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,9 +14,8 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Changed * Support for sub-folders within the `getJavascript()` route for servers. -* API route for [`/api/users`](https://pterodactyl.readme.io/v0.5.0/reference#users) now returns a non-paginated result set, and is a single array. -* API route for [`/api/users/:id`](https://pterodactyl.readme.io/v0.5.0/reference#single-user) now returns a single array including an array of all servers the user is set as the owner of. -* API route for [`/api/servers`](https://pterodactyl.readme.io/v0.5.0/reference#servers) now returns a non-paginated result set, and is a single array. +* **ALL** API routes previously returning paginated result sets, or result sets nested inside a descriptive block (e.g. `servers:`) have been changed to return a single array of all associated items. Please see the [updated documentation](https://pterodactyl.readme.io/v0.5.0/reference) for how this change might effect your API use. +* API route for [`/api/users/:id`](https://pterodactyl.readme.io/v0.5.0/reference#single-user) now includes an array of all servers the user is set as the owner of. ### Fixed * File manager would do multiple up-down-up-down loading actions if you escaped renaming a file. Fixed the binding issue. [#122](https://github.com/Pterodactyl/Panel/issues/122) diff --git a/app/Http/Controllers/API/LocationController.php b/app/Http/Controllers/API/LocationController.php index edb6e2919..27f192679 100755 --- a/app/Http/Controllers/API/LocationController.php +++ b/app/Http/Controllers/API/LocationController.php @@ -58,7 +58,7 @@ class LocationController extends BaseController $location->nodes = explode(',', $location->nodes); } - return $locations; + return $locations->toArray(); } } diff --git a/app/Http/Controllers/API/NodeController.php b/app/Http/Controllers/API/NodeController.php index 0351735d4..c3be918b2 100755 --- a/app/Http/Controllers/API/NodeController.php +++ b/app/Http/Controllers/API/NodeController.php @@ -62,8 +62,7 @@ class NodeController extends BaseController */ public function list(Request $request) { - $nodes = Models\Node::paginate(50); - return $this->response->paginator($nodes, new NodeTransformer); + return Models\Node::all()->toArray(); } /** @@ -170,11 +169,11 @@ class NodeController extends BaseController */ public function allocations(Request $request) { - $allocations = Models\Allocation::paginate(100); + $allocations = Models\Allocation::all(); if ($allocations->count() < 1) { throw new NotFoundHttpException('No allocations have been created.'); } - return $this->response->paginator($allocations, new AllocationTransformer); + return $allocations; } /** diff --git a/app/Http/Controllers/API/ServerController.php b/app/Http/Controllers/API/ServerController.php index adf4b95a3..91550f278 100755 --- a/app/Http/Controllers/API/ServerController.php +++ b/app/Http/Controllers/API/ServerController.php @@ -132,28 +132,25 @@ class ServerController extends BaseController ] ]); - $server->toArray(); - // Only return the daemon token if the request is using HTTPS if ($request->secure()) { $server->daemon_token = $server->daemonSecret; } $server->daemon = json_decode($response->getBody())->{$server->uuid}; - return $server; + return $server->toArray(); } - return $server; + return $server->toArray(); } catch (NotFoundHttpException $ex) { throw $ex; } catch (\GuzzleHttp\Exception\TransferException $ex) { // Couldn't hit the daemon, return what we have though. - $server->toArray(); $server->daemon = [ 'error' => 'There was an error encountered while attempting to connect to the remote daemon.' ]; - return $server; + return $server->toArray(); } catch (\Exception $ex) { throw new BadRequestHttpException('There was an issue with the fields passed in the request.'); } diff --git a/app/Http/Controllers/API/ServiceController.php b/app/Http/Controllers/API/ServiceController.php index 661a461db..5a60990e6 100755 --- a/app/Http/Controllers/API/ServiceController.php +++ b/app/Http/Controllers/API/ServiceController.php @@ -43,7 +43,7 @@ class ServiceController extends BaseController public function list(Request $request) { - return Models\Service::all(); + return Models\Service::all()->toArray(); } public function view(Request $request, $id) diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 728a7121a..472e1290f 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -77,7 +77,7 @@ class ServerRepository // Validate Fields $validator = Validator::make($data, [ - 'owner' => 'bail|required|string', + 'owner' => 'bail|required', 'name' => 'required|regex:/^([\w -]{4,35})$/', 'memory' => 'required|numeric|min:0', 'swap' => 'required|numeric|min:-1',