Add database list endpoint, add more resource name magic

This commit is contained in:
Dane Everitt 2018-01-25 21:26:06 -06:00
parent 407120a854
commit 2bd691efad
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
36 changed files with 416 additions and 187 deletions

View file

@ -0,0 +1,44 @@
<?php
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
use Pterodactyl\Models\Server;
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\ServerDatabaseTransformer;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class DatabaseController extends ApplicationApiController
{
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
*/
private $repository;
/**
* DatabaseController constructor.
*
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $repository
*/
public function __construct(DatabaseRepositoryInterface $repository)
{
parent::__construct();
$this->repository = $repository;
}
/**
* Return a listing of all databases currently available to a single
* server.
*
* @param \Pterodactyl\Models\Server $server
* @return array
*/
public function index(Server $server): array
{
$databases = $this->repository->getDatabasesForServer($server->id);
return $this->fractal->collection($databases)
->transformWith($this->getTransformer(ServerDatabaseTransformer::class))
->toArray();
}
}