More API updates, better support for node config edits

This commit is contained in:
Dane Everitt 2018-01-10 23:19:03 -06:00
parent 800e2df6b2
commit cf21fd5a4b
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
21 changed files with 449 additions and 125 deletions

View file

@ -74,7 +74,7 @@ class LocationController extends Controller
*/
public function index(Request $request): array
{
$locations = $this->repository->all(50);
$locations = $this->repository->paginated(100);
return $this->fractal->collection($locations)
->transformWith(new LocationTransformer($request))

View file

@ -0,0 +1,78 @@
<?php
namespace Pterodactyl\Http\Controllers\API\Admin\Nodes;
use Spatie\Fractal\Fractal;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Http\Controllers\Controller;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use Pterodactyl\Transformers\Api\Admin\AllocationTransformer;
use Pterodactyl\Services\Allocations\AllocationDeletionService;
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
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.
*
* @param \Illuminate\Http\Request $request
* @param int $node
* @return array
*/
public function index(Request $request, int $node): array
{
$allocations = $this->repository->getPaginatedAllocationsForNode($node, 100);
return $this->fractal->collection($allocations)
->transformWith(new AllocationTransformer($request))
->withResourceName('allocation')
->paginateWith(new IlluminatePaginatorAdapter($allocations))
->toArray();
}
/**
* Delete a specific allocation from the Panel.
*
* @param \Pterodactyl\Models\Allocation $allocation
* @return \Illuminate\Http\Response
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
*/
public function delete(Request $request, int $node, Allocation $allocation): Response
{
$this->deletionService->handle($allocation);
return response('', 204);
}
}

View file

@ -74,7 +74,7 @@ class NodeController extends Controller
*/
public function index(Request $request): array
{
$nodes = $this->repository->all(config('pterodactyl.paginate.api.nodes'));
$nodes = $this->repository->paginated(100);
$fractal = $this->fractal->collection($nodes)
->transformWith(new NodeTransformer($request))

View file

@ -76,7 +76,7 @@ class UserController extends Controller
*/
public function index(Request $request): array
{
$users = $this->repository->all(config('pterodactyl.paginate.api.users'));
$users = $this->repository->paginated(100);
return $this->fractal->collection($users)
->transformWith(new UserTransformer($request))
@ -113,7 +113,6 @@ class UserController extends Controller
* @param \Pterodactyl\Models\User $user
* @return array
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/

View file

@ -12,6 +12,8 @@ namespace Pterodactyl\Http\Controllers\Admin;
use Javascript;
use Illuminate\Http\Request;
use Pterodactyl\Models\Node;
use Illuminate\Http\Response;
use Pterodactyl\Models\Allocation;
use Prologue\Alerts\AlertsMessageBag;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Nodes\NodeUpdateService;
@ -23,6 +25,7 @@ use Pterodactyl\Services\Helpers\SoftwareVersionService;
use Pterodactyl\Http\Requests\Admin\Node\NodeFormRequest;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Http\Requests\Admin\Node\AllocationFormRequest;
use Pterodactyl\Services\Allocations\AllocationDeletionService;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
use Pterodactyl\Http\Requests\Admin\Node\AllocationAliasFormRequest;
@ -78,11 +81,16 @@ class NodesController extends Controller
* @var \Pterodactyl\Services\Helpers\SoftwareVersionService
*/
protected $versionService;
/**
* @var \Pterodactyl\Services\Allocations\AllocationDeletionService
*/
private $allocationDeletionService;
/**
* NodesController constructor.
*
* @param \Prologue\Alerts\AlertsMessageBag $alert
* @param \Pterodactyl\Services\Allocations\AllocationDeletionService $allocationDeletionService
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
* @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
* @param \Illuminate\Cache\Repository $cache
@ -95,6 +103,7 @@ class NodesController extends Controller
*/
public function __construct(
AlertsMessageBag $alert,
AllocationDeletionService $allocationDeletionService,
AllocationRepositoryInterface $allocationRepository,
AssignmentService $assignmentService,
CacheRepository $cache,
@ -106,6 +115,7 @@ class NodesController extends Controller
SoftwareVersionService $versionService
) {
$this->alert = $alert;
$this->allocationDeletionService = $allocationDeletionService;
$this->allocationRepository = $allocationRepository;
$this->assignmentService = $assignmentService;
$this->cache = $cache;
@ -262,17 +272,14 @@ class NodesController extends Controller
/**
* Removes a single allocation from a node.
*
* @param int $node
* @param int $allocation
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
* @param \Pterodactyl\Models\Allocation $allocation
* @return \Illuminate\Http\Response
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
*/
public function allocationRemoveSingle($node, $allocation)
public function allocationRemoveSingle(Allocation $allocation): Response
{
$this->allocationRepository->deleteWhere([
['id', '=', $allocation],
['node_id', '=', $node],
['server_id', '=', null],
]);
$this->allocationDeletionService->handle($allocation);
return response('', 204);
}