Skip to content

Commit f687fab

Browse files
death-droidDaneEveritt
authored andcommitted
API: ability to search for an allocation based on the assigned server id (pterodactyl#194)
1 parent e358796 commit f687fab

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

app/Http/Controllers/API/NodeController.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,32 @@ public function allocations(Request $request)
228228
}
229229
return $allocations;
230230
}
231+
232+
/**
233+
* List Node Allocation based on assigned to ID
234+
*
235+
* Returns a listing of the allocation for the specified server id.
236+
*
237+
* @Get("/nodes/allocations/{id}")
238+
* @Versions({"v1"})
239+
* @Response(200)
240+
*/
241+
public function allocationsView(Request $request, $id)
242+
{
243+
$query = Models\Allocation::where('assigned_to', $id)->get();
244+
try {
245+
246+
if (empty($query)) {
247+
throw new NotFoundHttpException('No allocations for that server were found.');
248+
}
249+
250+
return $query;
251+
} catch (NotFoundHttpException $ex) {
252+
throw $ex;
253+
} catch (\Exception $ex) {
254+
throw new BadRequestHttpException('There was an issue with the fields passed in the request.');
255+
}
256+
}
231257

232258
/**
233259
* Delete Node

app/Http/Routes/APIRoutes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public function map(Router $router) {
140140
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@allocations'
141141
]);
142142

143+
$api->get('nodes/allocations/{id}', [
144+
'as' => 'api.admin.nodes.allocations',
145+
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@allocationsView'
146+
]);
147+
143148
$api->get('nodes/{id}', [
144149
'as' => 'api.admin.nodes.view',
145150
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@view'

0 commit comments

Comments
 (0)