Make server listing and single server view API endpoints work

This commit is contained in:
Dane Everitt 2018-01-19 21:47:06 -06:00
parent 74bdbea6a4
commit a497a3d153
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
39 changed files with 367 additions and 176 deletions

View file

@ -11,8 +11,8 @@ use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use Pterodactyl\Services\Locations\LocationUpdateService;
use Pterodactyl\Services\Locations\LocationCreationService;
use Pterodactyl\Services\Locations\LocationDeletionService;
use Pterodactyl\Transformers\Api\Admin\LocationTransformer;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\LocationTransformer;
use Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationsRequest;
use Pterodactyl\Http\Requests\Api\Application\Locations\DeleteLocationRequest;
use Pterodactyl\Http\Requests\Api\Application\Locations\UpdateLocationRequest;

View file

@ -8,11 +8,11 @@ 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;
use Pterodactyl\Transformers\Api\Application\AllocationTransformer;
use Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest;
use Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequest;
use Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequestApplication;
class AllocationController extends Controller
{
@ -66,14 +66,14 @@ class AllocationController extends Controller
/**
* Delete a specific allocation from the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequest $request
* @param \Pterodactyl\Models\Node $node
* @param \Pterodactyl\Models\Allocation $allocation
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequestApplication $request
* @param \Pterodactyl\Models\Node $node
* @param \Pterodactyl\Models\Allocation $allocation
* @return \Illuminate\Http\Response
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
*/
public function delete(DeleteAllocationRequest $request, Node $node, Allocation $allocation): Response
public function delete(DeleteAllocationRequestApplication $request, Node $node, Allocation $allocation): Response
{
$this->deletionService->handle($allocation);

View file

@ -10,9 +10,9 @@ use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Nodes\NodeUpdateService;
use Pterodactyl\Services\Nodes\NodeCreationService;
use Pterodactyl\Services\Nodes\NodeDeletionService;
use Pterodactyl\Transformers\Api\Admin\NodeTransformer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\NodeTransformer;
use Pterodactyl\Http\Requests\Api\Application\Nodes\GetNodeRequest;
use Pterodactyl\Http\Requests\Api\Application\Nodes\GetNodesRequest;
use Pterodactyl\Http\Requests\Api\Application\Nodes\StoreNodeRequest;

View file

@ -1,20 +1,18 @@
<?php
namespace Pterodactyl\Http\Controllers\Api\Admin;
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
use Spatie\Fractal\Fractal;
use Illuminate\Http\Request;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Transformers\Api\Admin\ServerTransformer;
use Pterodactyl\Models\Server;
use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
use Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest;
use Pterodactyl\Http\Requests\Api\Application\Servers\GetServersRequest;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class ServerController extends Controller
class ServerController extends ApplicationApiController
{
/**
* @var \Spatie\Fractal\Fractal
*/
private $fractal;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
@ -23,22 +21,43 @@ class ServerController extends Controller
/**
* ServerController constructor.
*
* @param \Spatie\Fractal\Fractal $fractal
* @param \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal $fractal
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
*/
public function __construct(Fractal $fractal, ServerRepositoryInterface $repository)
public function __construct(Fractal $fractal, Request $request, ServerRepositoryInterface $repository)
{
$this->fractal = $fractal;
parent::__construct($fractal, $request);
$this->repository = $repository;
}
public function index(Request $request): array
/**
* Return all of the servers that currently exist on the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServersRequest $request
* @return array
*/
public function index(GetServersRequest $request): array
{
$servers = $this->repository->paginated(50);
$servers = $this->repository->setSearchTerm($request->input('search'))->paginated(50);
return $this->fractal->collection($servers)
->transformWith((new ServerTransformer)->setKey())
->withResourceName('server')
->transformWith($this->getTransformer(ServerTransformer::class))
->toArray();
}
/**
* Show a single server transformed for the application API.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest $request
* @param \Pterodactyl\Models\Server $server
* @return array
*/
public function view(GetServerRequest $request, Server $server): array
{
return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class))
->toArray();
}
}

View file

@ -11,9 +11,9 @@ use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Users\UserUpdateService;
use Pterodactyl\Services\Users\UserCreationService;
use Pterodactyl\Services\Users\UserDeletionService;
use Pterodactyl\Transformers\Api\Admin\UserTransformer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\UserTransformer;
use Pterodactyl\Http\Requests\Api\Application\Users\GetUserRequest;
use Pterodactyl\Http\Requests\Api\Application\Users\GetUsersRequest;
use Pterodactyl\Http\Requests\Api\Application\Users\StoreUserRequest;