mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 19:14:45 +02:00

* Remove old admin * Remove controller test * Remove unused exceptions * Remove unused files * More small tweaks * Fix doc block * Remove unused service * Restore these * Add back autoDeploy * Revert "Add back autoDeploy" This reverts commit 630c1e08acf8056ce8e612f376fcd00c23d90aea. * Add these back * Add back exception * Remove ApiController again --------- Co-authored-by: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com> Co-authored-by: Boy132 <mail@boy132.de> Co-authored-by: notCharles <charles@pelican.dev>
73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers\Api\Application;
|
|
|
|
use App\Models\Node;
|
|
use App\Models\Server;
|
|
use League\Fractal\Resource\Item;
|
|
use App\Models\Allocation;
|
|
use League\Fractal\Resource\NullResource;
|
|
|
|
class AllocationTransformer extends BaseTransformer
|
|
{
|
|
/**
|
|
* Relationships that can be loaded onto allocation transformations.
|
|
*/
|
|
protected array $availableIncludes = ['node', 'server'];
|
|
|
|
/**
|
|
* Return the resource name for the JSONAPI output.
|
|
*/
|
|
public function getResourceName(): string
|
|
{
|
|
return Allocation::RESOURCE_NAME;
|
|
}
|
|
|
|
/**
|
|
* Return a generic transformed allocation array.
|
|
*/
|
|
public function transform(Allocation $allocation): array
|
|
{
|
|
return [
|
|
'id' => $allocation->id,
|
|
'ip' => $allocation->ip,
|
|
'alias' => $allocation->ip_alias,
|
|
'port' => $allocation->port,
|
|
'notes' => $allocation->notes,
|
|
'assigned' => !is_null($allocation->server_id),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Load the node relationship onto a given transformation.
|
|
*/
|
|
public function includeNode(Allocation $allocation): Item|NullResource
|
|
{
|
|
if (!$this->authorize(Node::RESOURCE_NAME)) {
|
|
return $this->null();
|
|
}
|
|
|
|
return $this->item(
|
|
$allocation->node,
|
|
$this->makeTransformer(NodeTransformer::class),
|
|
Node::RESOURCE_NAME
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Load the server relationship onto a given transformation.
|
|
*/
|
|
public function includeServer(Allocation $allocation): Item|NullResource
|
|
{
|
|
if (!$this->authorize(Server::RESOURCE_NAME) || !$allocation->server) {
|
|
return $this->null();
|
|
}
|
|
|
|
return $this->item(
|
|
$allocation->server,
|
|
$this->makeTransformer(ServerTransformer::class),
|
|
Server::RESOURCE_NAME
|
|
);
|
|
}
|
|
}
|