Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php
10277 views
1
<?php
2
3
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
4
5
use Pterodactyl\Models\Server;
6
use Pterodactyl\Services\Servers\BuildModificationService;
7
use Pterodactyl\Services\Servers\DetailsModificationService;
8
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
9
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
10
use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerDetailsRequest;
11
use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest;
12
13
class ServerDetailsController extends ApplicationApiController
14
{
15
/**
16
* ServerDetailsController constructor.
17
*/
18
public function __construct(
19
private BuildModificationService $buildModificationService,
20
private DetailsModificationService $detailsModificationService,
21
) {
22
parent::__construct();
23
}
24
25
/**
26
* Update the details for a specific server.
27
*
28
* @throws \Pterodactyl\Exceptions\DisplayException
29
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
30
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
31
*/
32
public function details(UpdateServerDetailsRequest $request, Server $server): array
33
{
34
$updated = $this->detailsModificationService->returnUpdatedModel()->handle(
35
$server,
36
$request->validated()
37
);
38
39
return $this->fractal->item($updated)
40
->transformWith($this->getTransformer(ServerTransformer::class))
41
->toArray();
42
}
43
44
/**
45
* Update the build details for a specific server.
46
*
47
* @throws \Pterodactyl\Exceptions\DisplayException
48
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
49
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
50
*/
51
public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array
52
{
53
$server = $this->buildModificationService->handle($server, $request->validated());
54
55
return $this->fractal->item($server)
56
->transformWith($this->getTransformer(ServerTransformer::class))
57
->toArray();
58
}
59
}
60
61