e313dff674
Changes the API internals to use normal Laravel binding which automatically supports nested-models and can determine their relationships. This removes a lot of confusingly complex internal logic and replaces it with standard Laravel code. This also removes a deprecated "getModel" method and fully replaces it with a "parameter" method that does stricter type-checking.
72 lines
2.5 KiB
PHP
72 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
use Pterodactyl\Services\Servers\BuildModificationService;
|
|
use Pterodactyl\Services\Servers\DetailsModificationService;
|
|
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
|
|
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
|
use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerDetailsRequest;
|
|
use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest;
|
|
|
|
class ServerDetailsController extends ApplicationApiController
|
|
{
|
|
/**
|
|
* @var \Pterodactyl\Services\Servers\BuildModificationService
|
|
*/
|
|
private $buildModificationService;
|
|
|
|
/**
|
|
* @var \Pterodactyl\Services\Servers\DetailsModificationService
|
|
*/
|
|
private $detailsModificationService;
|
|
|
|
/**
|
|
* ServerDetailsController constructor.
|
|
*/
|
|
public function __construct(
|
|
BuildModificationService $buildModificationService,
|
|
DetailsModificationService $detailsModificationService
|
|
) {
|
|
parent::__construct();
|
|
|
|
$this->buildModificationService = $buildModificationService;
|
|
$this->detailsModificationService = $detailsModificationService;
|
|
}
|
|
|
|
/**
|
|
* Update the details for a specific server.
|
|
*
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
*/
|
|
public function details(UpdateServerDetailsRequest $request, Server $server): array
|
|
{
|
|
$updated = $this->detailsModificationService->returnUpdatedModel()->handle(
|
|
$server,
|
|
$request->validated()
|
|
);
|
|
|
|
return $this->fractal->item($updated)
|
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
|
->toArray();
|
|
}
|
|
|
|
/**
|
|
* Update the build details for a specific server.
|
|
*
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
*/
|
|
public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array
|
|
{
|
|
$server = $this->buildModificationService->handle($server, $request->validated());
|
|
|
|
return $this->fractal->item($server)
|
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
|
->toArray();
|
|
}
|
|
}
|