misc_pterodactyl-panel/app/Http/Controllers/Api/Application/Nests/NestController.php

63 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Http\Controllers\Api\Application\Nests;
use Pterodactyl\Models\Nest;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\NestTransformer;
use Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class NestController extends ApplicationApiController
{
/**
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
*/
private $repository;
/**
* NestController constructor.
*
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository
*/
public function __construct(NestRepositoryInterface $repository)
{
parent::__construct();
$this->repository = $repository;
}
/**
* Return all Nests that exist on the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetNestsRequest $request): array
{
$nests = $this->repository->paginated(1);
return $this->fractal->collection($nests)
->transformWith($this->getTransformer(NestTransformer::class))
->toArray();
}
/**
* Return information about a single Nest model.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest $request
* @param \Pterodactyl\Models\Nest $nest
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetNestsRequest $request, Nest $nest): array
{
return $this->fractal->item($nest)
->transformWith($this->getTransformer(NestTransformer::class))
->toArray();
}
}