From f3e7aab27c2b703ddf86611bd48d6492cff20e07 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Fri, 5 Feb 2021 09:43:48 -0700 Subject: [PATCH] api(application): remove old database node endpoints --- .../Databases/DatabaseController.php | 81 +------------------ .../Databases/DatabaseNodesRequest.php | 17 ---- .../Application/DatabaseHostTransformer.php | 1 + routes/api-application.php | 3 - 4 files changed, 5 insertions(+), 97 deletions(-) delete mode 100644 app/Http/Requests/Api/Application/Databases/DatabaseNodesRequest.php diff --git a/app/Http/Controllers/Api/Application/Databases/DatabaseController.php b/app/Http/Controllers/Api/Application/Databases/DatabaseController.php index f06e9b05d..db6ffae6b 100644 --- a/app/Http/Controllers/Api/Application/Databases/DatabaseController.php +++ b/app/Http/Controllers/Api/Application/Databases/DatabaseController.php @@ -12,28 +12,17 @@ use Pterodactyl\Transformers\Api\Application\DatabaseHostTransformer; use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController; use Pterodactyl\Http\Requests\Api\Application\Databases\GetDatabaseRequest; use Pterodactyl\Http\Requests\Api\Application\Databases\GetDatabasesRequest; -use Pterodactyl\Http\Requests\Api\Application\Databases\DatabaseNodesRequest; use Pterodactyl\Http\Requests\Api\Application\Databases\StoreDatabaseRequest; -use Pterodactyl\Http\Requests\Api\Application\Databases\UpdateDatabaseRequest; use Pterodactyl\Http\Requests\Api\Application\Databases\DeleteDatabaseRequest; +use Pterodactyl\Http\Requests\Api\Application\Databases\UpdateDatabaseRequest; class DatabaseController extends ApplicationApiController { - /** - * @var \Pterodactyl\Services\Databases\Hosts\HostCreationService - */ - private $creationService; - - /** - * @var \Pterodactyl\Services\Databases\Hosts\HostUpdateService - */ - private $updateService; + private HostCreationService $creationService; + private HostUpdateService $updateService; /** * DatabaseController constructor. - * - * @param \Pterodactyl\Services\Databases\Hosts\HostCreationService $creationService - * @param \Pterodactyl\Services\Databases\Hosts\HostUpdateService $updateService */ public function __construct(HostCreationService $creationService, HostUpdateService $updateService) { @@ -46,9 +35,6 @@ class DatabaseController extends ApplicationApiController /** * Returns an array of all database hosts. * - * @param \Pterodactyl\Http\Requests\Api\Application\Databases\GetDatabasesRequest $request - * - * @return array * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetDatabasesRequest $request): array @@ -56,7 +42,7 @@ class DatabaseController extends ApplicationApiController $perPage = $request->query('per_page', 10); if ($perPage < 1) { $perPage = 10; - } else if ($perPage > 100) { + } elseif ($perPage > 100) { throw new BadRequestHttpException('"per_page" query parameter must be below 100.'); } @@ -73,10 +59,6 @@ class DatabaseController extends ApplicationApiController /** * Returns a single database host. * - * @param \Pterodactyl\Http\Requests\Api\Application\Databases\GetDatabaseRequest $request - * @param \Pterodactyl\Models\DatabaseHost $databaseHost - * - * @return array * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function view(GetDatabaseRequest $request, DatabaseHost $databaseHost): array @@ -89,9 +71,6 @@ class DatabaseController extends ApplicationApiController /** * Creates a new database host. * - * @param \Pterodactyl\Http\Requests\Api\Application\Databases\StoreDatabaseRequest $request - * - * @return \Illuminate\Http\JsonResponse * @throws \Throwable */ public function store(StoreDatabaseRequest $request): JsonResponse @@ -106,10 +85,6 @@ class DatabaseController extends ApplicationApiController /** * Updates a database host. * - * @param \Pterodactyl\Http\Requests\Api\Application\Databases\UpdateDatabaseRequest $request - * @param \Pterodactyl\Models\DatabaseHost $databaseHost - * - * @return array * @throws \Throwable */ public function update(UpdateDatabaseRequest $request, DatabaseHost $databaseHost): array @@ -124,10 +99,6 @@ class DatabaseController extends ApplicationApiController /** * Deletes a database host. * - * @param \Pterodactyl\Http\Requests\Api\Application\Databases\DeleteDatabaseRequest $request - * @param \Pterodactyl\Models\DatabaseHost $databaseHost - * - * @return \Illuminate\Http\JsonResponse * @throws \Exception */ public function delete(DeleteDatabaseRequest $request, DatabaseHost $databaseHost): JsonResponse @@ -136,48 +107,4 @@ class DatabaseController extends ApplicationApiController return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } - - /** - * ? - * - * @param \Pterodactyl\Http\Requests\Api\Application\Databases\DatabaseNodesRequest $request - * @param \Pterodactyl\Models\Mount $mount - * - * @return array - */ - public function addNodes(DatabaseNodesRequest $request, DatabaseHost $databaseHost): array - { - $data = $request->validated(); - - $nodes = $data['nodes'] ?? []; - if (count($nodes) > 0) { - $databaseHost->nodes()->syncWithoutDetaching($nodes); - } - - return $this->fractal->item($databaseHost) - ->transformWith($this->getTransformer(DatabaseHostTransformer::class)) - ->toArray(); - } - - /** - * ? - * - * @param \Pterodactyl\Http\Requests\Api\Application\Databases\DatabaseNodesRequest $request - * @param \Pterodactyl\Models\Mount $mount - * - * @return array - */ - public function deleteNodes(DatabaseNodesRequest $request, DatabaseHost $databaseHost): array - { - $data = $request->validated(); - - $nodes = $data['nodes'] ?? []; - if (count($nodes) > 0) { - $databaseHost->nodes()->detach($nodes); - } - - return $this->fractal->item($databaseHost) - ->transformWith($this->getTransformer(DatabaseHostTransformer::class)) - ->toArray(); - } } diff --git a/app/Http/Requests/Api/Application/Databases/DatabaseNodesRequest.php b/app/Http/Requests/Api/Application/Databases/DatabaseNodesRequest.php deleted file mode 100644 index 6227fec30..000000000 --- a/app/Http/Requests/Api/Application/Databases/DatabaseNodesRequest.php +++ /dev/null @@ -1,17 +0,0 @@ - 'required|exists:nodes,id']; - } -} diff --git a/app/Transformers/Api/Application/DatabaseHostTransformer.php b/app/Transformers/Api/Application/DatabaseHostTransformer.php index 46f0ab343..4c9e86d44 100644 --- a/app/Transformers/Api/Application/DatabaseHostTransformer.php +++ b/app/Transformers/Api/Application/DatabaseHostTransformer.php @@ -50,6 +50,7 @@ class DatabaseHostTransformer extends BaseTransformer * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * + * @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException */ public function includeDatabases(DatabaseHost $model) diff --git a/routes/api-application.php b/routes/api-application.php index 1492d7840..fd7253a02 100644 --- a/routes/api-application.php +++ b/routes/api-application.php @@ -18,12 +18,9 @@ Route::group(['prefix' => '/databases'], function () { Route::post('/', 'Databases\DatabaseController@store'); - Route::put('/{databaseHost}/nodes', 'Databases\DatabaseController@addNodes'); - Route::patch('/{databaseHost}', 'Databases\DatabaseController@update'); Route::delete('/{databaseHost}', 'Databases\DatabaseController@delete'); - Route::delete('/{databaseHost}/nodes', 'Databases\DatabaseController@deleteNodes'); }); /*