2018-01-20 22:03:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
2018-01-21 22:02:03 +00:00
|
|
|
use Pterodactyl\Services\Servers\BuildModificationService;
|
2018-01-20 22:03:23 +00:00
|
|
|
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;
|
2018-01-21 22:02:03 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest;
|
2018-01-20 22:03:23 +00:00
|
|
|
|
|
|
|
class ServerDetailsController extends ApplicationApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* ServerDetailsController constructor.
|
|
|
|
*/
|
2018-01-27 18:38:56 +00:00
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
private BuildModificationService $buildModificationService,
|
|
|
|
private DetailsModificationService $detailsModificationService
|
2018-01-27 18:38:56 +00:00
|
|
|
) {
|
2018-01-20 22:03:23 +00:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-21 22:02:03 +00:00
|
|
|
* Update the details for a specific server.
|
|
|
|
*
|
2018-01-20 22:03:23 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2022-05-22 18:10:01 +00:00
|
|
|
public function details(UpdateServerDetailsRequest $request, Server $server): array
|
2018-01-20 22:03:23 +00:00
|
|
|
{
|
2022-05-22 18:10:01 +00:00
|
|
|
$updated = $this->detailsModificationService->returnUpdatedModel()->handle(
|
|
|
|
$server,
|
2021-01-23 20:33:34 +00:00
|
|
|
$request->validated()
|
2018-01-27 18:38:56 +00:00
|
|
|
);
|
2018-01-21 22:02:03 +00:00
|
|
|
|
2022-05-22 18:10:01 +00:00
|
|
|
return $this->fractal->item($updated)
|
2018-01-21 22:02:03 +00:00
|
|
|
->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
|
|
|
|
*/
|
2019-12-22 21:45:40 +00:00
|
|
|
public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array
|
2018-01-21 22:02:03 +00:00
|
|
|
{
|
2019-12-22 21:45:40 +00:00
|
|
|
$server = $this->buildModificationService->handle($server, $request->validated());
|
2018-01-20 22:03:23 +00:00
|
|
|
|
|
|
|
return $this->fractal->item($server)
|
|
|
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|