API: ability to search for an allocation based on the assigned server id (#194)

This commit is contained in:
Emmet Young 2016-12-05 14:17:35 +11:00 committed by Dane Everitt
parent e3587966e2
commit f687fab9a2
2 changed files with 31 additions and 0 deletions

View File

@ -229,6 +229,32 @@ class NodeController extends BaseController
return $allocations;
}
/**
* List Node Allocation based on assigned to ID
*
* Returns a listing of the allocation for the specified server id.
*
* @Get("/nodes/allocations/{id}")
* @Versions({"v1"})
* @Response(200)
*/
public function allocationsView(Request $request, $id)
{
$query = Models\Allocation::where('assigned_to', $id)->get();
try {
if (empty($query)) {
throw new NotFoundHttpException('No allocations for that server were found.');
}
return $query;
} catch (NotFoundHttpException $ex) {
throw $ex;
} catch (\Exception $ex) {
throw new BadRequestHttpException('There was an issue with the fields passed in the request.');
}
}
/**
* Delete Node
*

View File

@ -140,6 +140,11 @@ class APIRoutes
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@allocations'
]);
$api->get('nodes/allocations/{id}', [
'as' => 'api.admin.nodes.allocations',
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@allocationsView'
]);
$api->get('nodes/{id}', [
'as' => 'api.admin.nodes.view',
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@view'