2018-01-11 05:19:03 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-20 01:58:57 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Application\Nodes;
|
2018-01-11 05:19:03 +00:00
|
|
|
|
2018-01-13 20:08:19 +00:00
|
|
|
use Pterodactyl\Models\Node;
|
2018-01-11 05:19:03 +00:00
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Pterodactyl\Models\Allocation;
|
2018-01-27 18:38:56 +00:00
|
|
|
use Pterodactyl\Services\Allocations\AssignmentService;
|
2018-01-11 05:19:03 +00:00
|
|
|
use Pterodactyl\Services\Allocations\AllocationDeletionService;
|
|
|
|
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
2018-01-20 03:47:06 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Application\AllocationTransformer;
|
2018-01-27 18:38:56 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
2018-01-20 01:58:57 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest;
|
2018-01-27 18:38:56 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Allocations\StoreAllocationRequest;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequest;
|
2018-01-11 05:19:03 +00:00
|
|
|
|
2018-01-27 18:38:56 +00:00
|
|
|
class AllocationController extends ApplicationApiController
|
2018-01-11 05:19:03 +00:00
|
|
|
{
|
2018-01-27 18:38:56 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Allocations\AssignmentService
|
|
|
|
*/
|
|
|
|
private $assignmentService;
|
|
|
|
|
2018-01-11 05:19:03 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Allocations\AllocationDeletionService
|
|
|
|
*/
|
|
|
|
private $deletionService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AllocationController constructor.
|
|
|
|
*
|
2018-01-27 18:38:56 +00:00
|
|
|
* @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
|
2018-01-11 05:19:03 +00:00
|
|
|
* @param \Pterodactyl\Services\Allocations\AllocationDeletionService $deletionService
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $repository
|
|
|
|
*/
|
2018-01-27 18:38:56 +00:00
|
|
|
public function __construct(
|
|
|
|
AssignmentService $assignmentService,
|
|
|
|
AllocationDeletionService $deletionService,
|
|
|
|
AllocationRepositoryInterface $repository
|
|
|
|
) {
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->assignmentService = $assignmentService;
|
2018-01-11 05:19:03 +00:00
|
|
|
$this->deletionService = $deletionService;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all of the allocations that exist for a given node.
|
|
|
|
*
|
2018-01-20 01:58:57 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest $request
|
2018-01-11 05:19:03 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2018-01-27 18:38:56 +00:00
|
|
|
public function index(GetAllocationsRequest $request): array
|
2018-01-11 05:19:03 +00:00
|
|
|
{
|
2018-01-27 18:38:56 +00:00
|
|
|
$allocations = $this->repository->getPaginatedAllocationsForNode(
|
|
|
|
$request->getModel(Node::class)->id, 50
|
|
|
|
);
|
2018-01-11 05:19:03 +00:00
|
|
|
|
|
|
|
return $this->fractal->collection($allocations)
|
2018-01-27 18:38:56 +00:00
|
|
|
->transformWith($this->getTransformer(AllocationTransformer::class))
|
2018-01-11 05:19:03 +00:00
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
|
2018-01-27 18:38:56 +00:00
|
|
|
/**
|
|
|
|
* Store new allocations for a given node.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\StoreAllocationRequest $request
|
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
*/
|
|
|
|
public function store(StoreAllocationRequest $request): array
|
|
|
|
{
|
|
|
|
$this->assignmentService->handle($request->getModel(Node::class), $request->validated());
|
|
|
|
|
|
|
|
return response('', 204);
|
|
|
|
}
|
|
|
|
|
2018-01-11 05:19:03 +00:00
|
|
|
/**
|
|
|
|
* Delete a specific allocation from the Panel.
|
|
|
|
*
|
2018-01-27 18:38:56 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequest $request
|
2018-01-11 05:19:03 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
|
|
|
|
*/
|
2018-01-27 18:38:56 +00:00
|
|
|
public function delete(DeleteAllocationRequest $request): Response
|
2018-01-11 05:19:03 +00:00
|
|
|
{
|
2018-01-27 18:38:56 +00:00
|
|
|
$this->deletionService->handle($request->getModel(Allocation::class));
|
2018-01-11 05:19:03 +00:00
|
|
|
|
|
|
|
return response('', 204);
|
|
|
|
}
|
|
|
|
}
|