More work on the API utilizing Laravel 5.5 exception rendering
Also corrects API format to maintain JSONAPI spec
This commit is contained in:
parent
f30f4b45ba
commit
54b6fb5ebd
28 changed files with 464 additions and 391 deletions
69
app/Transformers/Api/Admin/LocationTransformer.php
Normal file
69
app/Transformers/Api/Admin/LocationTransformer.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Transformers\Api\Admin;
|
||||
|
||||
use Pterodactyl\Models\Location;
|
||||
use Pterodactyl\Transformers\Api\ApiTransformer;
|
||||
|
||||
class LocationTransformer extends ApiTransformer
|
||||
{
|
||||
/**
|
||||
* List of resources that can be included.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['nodes', 'servers'];
|
||||
|
||||
/**
|
||||
* Return a generic transformed pack array.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Location $location
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Location $location): array
|
||||
{
|
||||
return $location->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Location $location
|
||||
* @return bool|\League\Fractal\Resource\Collection
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\PterodactylException
|
||||
*/
|
||||
public function includeServers(Location $location)
|
||||
{
|
||||
if (! $this->authorize('server-list')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $location->relationLoaded('servers')) {
|
||||
$location->load('servers');
|
||||
}
|
||||
|
||||
return $this->collection($location->getRelation('servers'), new ServerTransformer($this->getRequest()), 'server');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Location $location
|
||||
* @return bool|\League\Fractal\Resource\Collection
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\PterodactylException
|
||||
*/
|
||||
public function includeNodes(Location $location)
|
||||
{
|
||||
if (! $this->authorize('node-list')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $location->relationLoaded('nodes')) {
|
||||
$location->load('nodes');
|
||||
}
|
||||
|
||||
return $this->collection($location->getRelation('nodes'), new NodeTransformer($this->getRequest()), 'node');
|
||||
}
|
||||
}
|
Reference in a new issue