api(application): add endpoints for (de)attaching eggs and nodes on mounts
This commit is contained in:
parent
4dab137b51
commit
a71392d632
4 changed files with 157 additions and 0 deletions
|
@ -12,6 +12,8 @@ use Pterodactyl\Http\Requests\Api\Application\Mounts\GetMountsRequest;
|
||||||
use Pterodactyl\Http\Requests\Api\Application\Mounts\StoreMountRequest;
|
use Pterodactyl\Http\Requests\Api\Application\Mounts\StoreMountRequest;
|
||||||
use Pterodactyl\Http\Requests\Api\Application\Mounts\UpdateMountRequest;
|
use Pterodactyl\Http\Requests\Api\Application\Mounts\UpdateMountRequest;
|
||||||
use Pterodactyl\Http\Requests\Api\Application\Mounts\DeleteMountRequest;
|
use Pterodactyl\Http\Requests\Api\Application\Mounts\DeleteMountRequest;
|
||||||
|
use Pterodactyl\Http\Requests\Api\Application\Mounts\MountAddEggsRequest;
|
||||||
|
use Pterodactyl\Http\Requests\Api\Application\Mounts\MountAddNodesRequest;
|
||||||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||||
|
|
||||||
class MountController extends ApplicationApiController
|
class MountController extends ApplicationApiController
|
||||||
|
@ -117,4 +119,92 @@ class MountController extends ApplicationApiController
|
||||||
|
|
||||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ?
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\MountAddEggsRequest $request
|
||||||
|
* @param \Pterodactyl\Models\Mount $mount
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function addEggs(MountAddEggsRequest $request, Mount $mount): array
|
||||||
|
{
|
||||||
|
$data = $request->validated();
|
||||||
|
|
||||||
|
$eggs = $data['eggs'] ?? [];
|
||||||
|
if (count($eggs) > 0) {
|
||||||
|
$mount->eggs()->syncWithoutDetaching($eggs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->fractal->item($mount)
|
||||||
|
->transformWith($this->getTransformer(MountTransformer::class))
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ?
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\MountAddNodesRequest $request
|
||||||
|
* @param \Pterodactyl\Models\Mount $mount
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function addNodes(MountAddNodesRequest $request, Mount $mount): array
|
||||||
|
{
|
||||||
|
$data = $request->validated();
|
||||||
|
|
||||||
|
$nodes = $data['nodes'] ?? [];
|
||||||
|
if (count($nodes) > 0) {
|
||||||
|
$mount->nodes()->syncWithoutDetaching($nodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->fractal->item($mount)
|
||||||
|
->transformWith($this->getTransformer(MountTransformer::class))
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ?
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\MountAddEggsRequest $request
|
||||||
|
* @param \Pterodactyl\Models\Mount $mount
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function deleteEggs(MountAddEggsRequest $request, Mount $mount): array
|
||||||
|
{
|
||||||
|
$data = $request->validated();
|
||||||
|
|
||||||
|
$eggs = $data['eggs'] ?? [];
|
||||||
|
if (count($eggs) > 0) {
|
||||||
|
$mount->eggs()->detach($eggs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->fractal->item($mount)
|
||||||
|
->transformWith($this->getTransformer(MountTransformer::class))
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ?
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\MountAddNodesRequest $request
|
||||||
|
* @param \Pterodactyl\Models\Mount $mount
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function deleteNodes(MountAddNodesRequest $request, Mount $mount): array
|
||||||
|
{
|
||||||
|
$data = $request->validated();
|
||||||
|
|
||||||
|
$nodes = $data['nodes'] ?? [];
|
||||||
|
if (count($nodes) > 0) {
|
||||||
|
$mount->nodes()->detach($nodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->fractal->item($mount)
|
||||||
|
->transformWith($this->getTransformer(MountTransformer::class))
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Http\Requests\Api\Application\Mounts;
|
||||||
|
|
||||||
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||||
|
|
||||||
|
class MountAddEggsRequest extends ApplicationApiRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $resource = AdminAcl::RESOURCE_MOUNTS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $permission = AdminAcl::WRITE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ?
|
||||||
|
*
|
||||||
|
* @param array|null $rules
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules(array $rules = null): array
|
||||||
|
{
|
||||||
|
return $rules ?? ['eggs' => 'required|exists:eggs,id'];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Http\Requests\Api\Application\Mounts;
|
||||||
|
|
||||||
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||||
|
|
||||||
|
class MountAddNodesRequest extends ApplicationApiRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $resource = AdminAcl::RESOURCE_MOUNTS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $permission = AdminAcl::WRITE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ?
|
||||||
|
*
|
||||||
|
* @param array|null $rules
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules(array $rules = null): array
|
||||||
|
{
|
||||||
|
return $rules ?? ['nodes' => 'required|exists:nodes,id'];
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,9 +74,14 @@ Route::group(['prefix' => '/mounts'], function () {
|
||||||
|
|
||||||
Route::post('/', 'Mounts\MountController@store');
|
Route::post('/', 'Mounts\MountController@store');
|
||||||
|
|
||||||
|
Route::put('/{mount}/eggs', 'Mounts\MountController@addEggs');
|
||||||
|
Route::put('/{mount}/nodes', 'Mounts\MountController@addNodes');
|
||||||
|
|
||||||
Route::patch('/{mount}', 'Mounts\MountController@update');
|
Route::patch('/{mount}', 'Mounts\MountController@update');
|
||||||
|
|
||||||
Route::delete('/{mount}', 'Mounts\MountController@delete');
|
Route::delete('/{mount}', 'Mounts\MountController@delete');
|
||||||
|
Route::delete('/{mount}/eggs', 'Mounts\MountController@deleteEggs');
|
||||||
|
Route::delete('/{mount}/nodes', 'Mounts\MountController@deleteNodes');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue