databaseManagementService = $databaseManagementService; $this->databasePasswordService = $databasePasswordService; $this->repository = $repository; } /** * Return a listing of all databases currently available to a single * server. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\GetServerDatabasesRequest $request * @param \Pterodactyl\Models\Server $server * @return array */ public function index(GetServerDatabasesRequest $request, Server $server): array { return $this->fractal->collection($server->databases) ->transformWith($this->getTransformer(ServerDatabaseTransformer::class)) ->toArray(); } /** * Return a single server database. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\GetServerDatabaseRequest $request * @param \Pterodactyl\Models\Server $server * @param \Pterodactyl\Models\Database $database * @return array */ public function view(GetServerDatabaseRequest $request, Server $server, Database $database): array { return $this->fractal->item($database) ->transformWith($this->getTransformer(ServerDatabaseTransformer::class)) ->toArray(); } /** * Reset the password for a specific server database. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\ServerDatabaseWriteRequest $request * @param \Pterodactyl\Models\Server $server * @param \Pterodactyl\Models\Database $database * @return \Illuminate\Http\JsonResponse * * @throws \Throwable */ public function resetPassword(ServerDatabaseWriteRequest $request, Server $server, Database $database): JsonResponse { $this->databasePasswordService->handle($database); return JsonResponse::create([], JsonResponse::HTTP_NO_CONTENT); } /** * Create a new database on the Panel for a given server. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\StoreServerDatabaseRequest $request * @param \Pterodactyl\Models\Server $server * @return \Illuminate\Http\JsonResponse * * @throws \Throwable */ public function store(StoreServerDatabaseRequest $request, Server $server): JsonResponse { $database = $this->databaseManagementService->create($server, $request->validated()); return $this->fractal->item($database) ->transformWith($this->getTransformer(ServerDatabaseTransformer::class)) ->addMeta([ 'resource' => route('api.application.servers.databases.view', [ 'server' => $server->id, 'database' => $database->id, ]), ]) ->respond(Response::HTTP_CREATED); } /** * Handle a request to delete a specific server database from the Panel. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\ServerDatabaseWriteRequest $request * @return \Illuminate\Http\Response * * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function delete(ServerDatabaseWriteRequest $request): Response { $this->databaseManagementService->delete($request->getModel(Database::class)); return response('', 204); } }