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