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
|
|
|
|
|
|
|
use Spatie\Fractal\Fractal;
|
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;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
|
|
|
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-20 01:58:57 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest;
|
2018-01-20 03:47:06 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequestApplication;
|
2018-01-11 05:19:03 +00:00
|
|
|
|
|
|
|
class AllocationController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Allocations\AllocationDeletionService
|
|
|
|
*/
|
|
|
|
private $deletionService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Spatie\Fractal\Fractal
|
|
|
|
*/
|
|
|
|
private $fractal;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AllocationController constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Services\Allocations\AllocationDeletionService $deletionService
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $repository
|
|
|
|
* @param \Spatie\Fractal\Fractal $fractal
|
|
|
|
*/
|
|
|
|
public function __construct(AllocationDeletionService $deletionService, AllocationRepositoryInterface $repository, Fractal $fractal)
|
|
|
|
{
|
|
|
|
$this->deletionService = $deletionService;
|
|
|
|
$this->fractal = $fractal;
|
|
|
|
$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
|
|
|
|
* @param \Pterodactyl\Models\Node $node
|
2018-01-11 05:19:03 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2018-01-13 20:08:19 +00:00
|
|
|
public function index(GetAllocationsRequest $request, Node $node): array
|
2018-01-11 05:19:03 +00:00
|
|
|
{
|
2018-01-13 20:08:19 +00:00
|
|
|
$allocations = $this->repository->getPaginatedAllocationsForNode($node->id, 100);
|
2018-01-11 05:19:03 +00:00
|
|
|
|
|
|
|
return $this->fractal->collection($allocations)
|
2018-01-13 20:08:19 +00:00
|
|
|
->transformWith((new AllocationTransformer)->setKey($request->key()))
|
2018-01-11 05:19:03 +00:00
|
|
|
->withResourceName('allocation')
|
|
|
|
->paginateWith(new IlluminatePaginatorAdapter($allocations))
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a specific allocation from the Panel.
|
|
|
|
*
|
2018-01-20 03:47:06 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequestApplication $request
|
|
|
|
* @param \Pterodactyl\Models\Node $node
|
|
|
|
* @param \Pterodactyl\Models\Allocation $allocation
|
2018-01-11 05:19:03 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
|
|
|
|
*/
|
2018-01-20 03:47:06 +00:00
|
|
|
public function delete(DeleteAllocationRequestApplication $request, Node $node, Allocation $allocation): Response
|
2018-01-11 05:19:03 +00:00
|
|
|
{
|
|
|
|
$this->deletionService->handle($allocation);
|
|
|
|
|
|
|
|
return response('', 204);
|
|
|
|
}
|
|
|
|
}
|