creationService = $creationService; $this->deletionService = $deletionService; $this->updateService = $updateService; $this->repository = $repository; } /** * Return all of the locations currently registered on the Panel. * * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetLocationsRequest $request): array { $perPage = $request->query('per_page', 10); if ($perPage < 1) { $perPage = 10; } elseif ($perPage > 100) { throw new BadRequestHttpException('"per_page" query parameter must be below 100.'); } $locations = QueryBuilder::for(Location::query()) ->allowedFilters(['short', 'long']) ->allowedSorts(['id']) ->paginate($perPage); return $this->fractal->collection($locations) ->transformWith($this->getTransformer(LocationTransformer::class)) ->toArray(); } /** * Return a single location. * * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function view(GetLocationRequest $request, Location $location): array { return $this->fractal->item($location) ->transformWith($this->getTransformer(LocationTransformer::class)) ->toArray(); } /** * Store a new location on the Panel and return a HTTP/201 response code with the * new location attached. * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function store(StoreLocationRequest $request): JsonResponse { $location = $this->creationService->handle($request->validated()); return $this->fractal->item($location) ->transformWith($this->getTransformer(LocationTransformer::class)) ->addMeta([ 'resource' => route('api.application.locations.view', [ 'location' => $location->id, ]), ]) ->respond(201); } /** * Update a location on the Panel and return the updated record to the user. * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function update(UpdateLocationRequest $request, Location $location): array { $location = $this->updateService->handle($location, $request->validated()); return $this->fractal->item($location) ->transformWith($this->getTransformer(LocationTransformer::class)) ->toArray(); } /** * Delete a location from the Panel. * * @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException */ public function delete(DeleteLocationRequest $request, Location $location): Response { $this->deletionService->handle($location); return $this->returnNoContent(); } }