Compare commits

...

2 commits

Author SHA1 Message Date
Lance Pioch
7e1f882f60 Fix tests 2022-10-23 22:24:18 -04:00
Lance Pioch
43e419fd7e Replace nest repository 2022-10-23 20:15:11 -04:00
15 changed files with 43 additions and 189 deletions

View file

@ -1,30 +0,0 @@
<?php
namespace Pterodactyl\Contracts\Repository;
use Pterodactyl\Models\Nest;
use Illuminate\Database\Eloquent\Collection;
interface NestRepositoryInterface extends RepositoryInterface
{
/**
* Return a nest or all nests with their associated eggs and variables.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithEggs(int $id = null): Collection|Nest;
/**
* Return a nest or all nests and the count of eggs and servers for that nest.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithCounts(int $id = null): Collection|Nest;
/**
* Return a nest along with its associated eggs and the servers relation on those eggs.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithEggServers(int $id): Nest;
}

View file

@ -15,7 +15,6 @@ use Illuminate\View\Factory as ViewFactory;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Http\Requests\Admin\MountFormRequest; use Pterodactyl\Http\Requests\Admin\MountFormRequest;
use Pterodactyl\Repositories\Eloquent\MountRepository; use Pterodactyl\Repositories\Eloquent\MountRepository;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface; use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
class MountController extends Controller class MountController extends Controller
@ -25,7 +24,6 @@ class MountController extends Controller
*/ */
public function __construct( public function __construct(
protected AlertsMessageBag $alert, protected AlertsMessageBag $alert,
protected NestRepositoryInterface $nestRepository,
protected LocationRepositoryInterface $locationRepository, protected LocationRepositoryInterface $locationRepository,
protected MountRepository $repository, protected MountRepository $repository,
protected ViewFactory $view protected ViewFactory $view

View file

@ -5,6 +5,7 @@ namespace Pterodactyl\Http\Controllers\Admin\Nests;
use JavaScript; use JavaScript;
use Illuminate\View\View; use Illuminate\View\View;
use Pterodactyl\Models\Egg; use Pterodactyl\Models\Egg;
use Pterodactyl\Models\Nest;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Prologue\Alerts\AlertsMessageBag; use Prologue\Alerts\AlertsMessageBag;
use Illuminate\View\Factory as ViewFactory; use Illuminate\View\Factory as ViewFactory;
@ -14,7 +15,7 @@ use Pterodactyl\Services\Eggs\EggCreationService;
use Pterodactyl\Services\Eggs\EggDeletionService; use Pterodactyl\Services\Eggs\EggDeletionService;
use Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest; use Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface; use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface; use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
class EggController extends Controller class EggController extends Controller
{ {
@ -27,19 +28,16 @@ class EggController extends Controller
protected EggDeletionService $deletionService, protected EggDeletionService $deletionService,
protected EggRepositoryInterface $repository, protected EggRepositoryInterface $repository,
protected EggUpdateService $updateService, protected EggUpdateService $updateService,
protected NestRepositoryInterface $nestRepository,
protected ViewFactory $view protected ViewFactory $view
) { ) {
} }
/** /**
* Handle a request to display the Egg creation page. * Handle a request to display the Egg creation page.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function create(): View public function create(): View
{ {
$nests = $this->nestRepository->getWithEggs(); $nests = Nest::with('eggs.variables')->get();
JavaScript::put(['nests' => $nests->keyBy('id')]); JavaScript::put(['nests' => $nests->keyBy('id')]);
return $this->view->make('admin.eggs.new', ['nests' => $nests]); return $this->view->make('admin.eggs.new', ['nests' => $nests]);
@ -81,7 +79,7 @@ class EggController extends Controller
* Handle request to update an Egg. * Handle request to update an Egg.
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException * @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
*/ */
public function update(EggFormRequest $request, Egg $egg): RedirectResponse public function update(EggFormRequest $request, Egg $egg): RedirectResponse

View file

@ -7,10 +7,10 @@ use Illuminate\Http\RedirectResponse;
use Prologue\Alerts\AlertsMessageBag; use Prologue\Alerts\AlertsMessageBag;
use Illuminate\View\Factory as ViewFactory; use Illuminate\View\Factory as ViewFactory;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Models\Nest;
use Pterodactyl\Services\Nests\NestUpdateService; use Pterodactyl\Services\Nests\NestUpdateService;
use Pterodactyl\Services\Nests\NestCreationService; use Pterodactyl\Services\Nests\NestCreationService;
use Pterodactyl\Services\Nests\NestDeletionService; use Pterodactyl\Services\Nests\NestDeletionService;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Http\Requests\Admin\Nest\StoreNestFormRequest; use Pterodactyl\Http\Requests\Admin\Nest\StoreNestFormRequest;
class NestController extends Controller class NestController extends Controller
@ -22,7 +22,6 @@ class NestController extends Controller
protected AlertsMessageBag $alert, protected AlertsMessageBag $alert,
protected NestCreationService $nestCreationService, protected NestCreationService $nestCreationService,
protected NestDeletionService $nestDeletionService, protected NestDeletionService $nestDeletionService,
protected NestRepositoryInterface $repository,
protected NestUpdateService $nestUpdateService, protected NestUpdateService $nestUpdateService,
protected ViewFactory $view protected ViewFactory $view
) { ) {
@ -31,12 +30,13 @@ class NestController extends Controller
/** /**
* Render nest listing page. * Render nest listing page.
* *
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function index(): View public function index(): View
{ {
$nests = Nest::query()->withCount(['eggs', 'servers']);
return $this->view->make('admin.nests.index', [ return $this->view->make('admin.nests.index', [
'nests' => $this->repository->getWithCounts(), 'nests' => $nests,
]); ]);
} }
@ -64,12 +64,11 @@ class NestController extends Controller
/** /**
* Return details about a nest including all the eggs and servers per egg. * Return details about a nest including all the eggs and servers per egg.
* *
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function view(int $nest): View public function view(int $nest): View
{ {
return $this->view->make('admin.nests.view', [ return $this->view->make('admin.nests.view', [
'nest' => $this->repository->getWithEggServers($nest), 'nest' => Nest::with('eggs.servers')->findOrFail($nest),
]); ]);
} }

View file

@ -4,13 +4,13 @@ namespace Pterodactyl\Http\Controllers\Admin\Servers;
use JavaScript; use JavaScript;
use Illuminate\View\View; use Illuminate\View\View;
use Pterodactyl\Models\Nest;
use Pterodactyl\Models\Node; use Pterodactyl\Models\Node;
use Pterodactyl\Models\Location; use Pterodactyl\Models\Location;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Prologue\Alerts\AlertsMessageBag; use Prologue\Alerts\AlertsMessageBag;
use Illuminate\View\Factory as ViewFactory; use Illuminate\View\Factory as ViewFactory;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\Eloquent\NestRepository;
use Pterodactyl\Repositories\Eloquent\NodeRepository; use Pterodactyl\Repositories\Eloquent\NodeRepository;
use Pterodactyl\Http\Requests\Admin\ServerFormRequest; use Pterodactyl\Http\Requests\Admin\ServerFormRequest;
use Pterodactyl\Services\Servers\ServerCreationService; use Pterodactyl\Services\Servers\ServerCreationService;
@ -22,7 +22,6 @@ class CreateServerController extends Controller
*/ */
public function __construct( public function __construct(
private AlertsMessageBag $alert, private AlertsMessageBag $alert,
private NestRepository $nestRepository,
private NodeRepository $nodeRepository, private NodeRepository $nodeRepository,
private ServerCreationService $creationService, private ServerCreationService $creationService,
private ViewFactory $view private ViewFactory $view
@ -43,7 +42,7 @@ class CreateServerController extends Controller
return redirect()->route('admin.nodes'); return redirect()->route('admin.nodes');
} }
$nests = $this->nestRepository->getWithEggs(); $nests = Nest::with('eggs.variables')->get();
JavaScript::put([ JavaScript::put([
'nodeData' => $this->nodeRepository->getNodesForServerCreation(), 'nodeData' => $this->nodeRepository->getNodesForServerCreation(),

View file

@ -11,7 +11,6 @@ use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Servers\EnvironmentService; use Pterodactyl\Services\Servers\EnvironmentService;
use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\Factory as ViewFactory;
use Pterodactyl\Repositories\Eloquent\NestRepository;
use Pterodactyl\Repositories\Eloquent\NodeRepository; use Pterodactyl\Repositories\Eloquent\NodeRepository;
use Pterodactyl\Repositories\Eloquent\MountRepository; use Pterodactyl\Repositories\Eloquent\MountRepository;
use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository;
@ -30,7 +29,6 @@ class ServerViewController extends Controller
private DatabaseHostRepository $databaseHostRepository, private DatabaseHostRepository $databaseHostRepository,
private LocationRepository $locationRepository, private LocationRepository $locationRepository,
private MountRepository $mountRepository, private MountRepository $mountRepository,
private NestRepository $nestRepository,
private NodeRepository $nodeRepository, private NodeRepository $nodeRepository,
private ServerRepository $repository, private ServerRepository $repository,
private EnvironmentService $environmentService, private EnvironmentService $environmentService,
@ -75,7 +73,7 @@ class ServerViewController extends Controller
*/ */
public function startup(Request $request, Server $server): View public function startup(Request $request, Server $server): View
{ {
$nests = $this->nestRepository->getWithEggs(); $nests = Nest::with('eggs.variables')->get();
$variables = $this->environmentService->handle($server); $variables = $this->environmentService->handle($server);
$this->plainInject([ $this->plainInject([

View file

@ -24,7 +24,6 @@ use Pterodactyl\Services\Servers\BuildModificationService;
use Pterodactyl\Services\Databases\DatabasePasswordService; use Pterodactyl\Services\Databases\DatabasePasswordService;
use Pterodactyl\Services\Servers\DetailsModificationService; use Pterodactyl\Services\Servers\DetailsModificationService;
use Pterodactyl\Services\Servers\StartupModificationService; use Pterodactyl\Services\Servers\StartupModificationService;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository; use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
use Pterodactyl\Services\Databases\DatabaseManagementService; use Pterodactyl\Services\Databases\DatabaseManagementService;
use Illuminate\Contracts\Config\Repository as ConfigRepository; use Illuminate\Contracts\Config\Repository as ConfigRepository;
@ -54,7 +53,6 @@ class ServersController extends Controller
protected ReinstallServerService $reinstallService, protected ReinstallServerService $reinstallService,
protected ServerRepositoryInterface $repository, protected ServerRepositoryInterface $repository,
protected MountRepository $mountRepository, protected MountRepository $mountRepository,
protected NestRepositoryInterface $nestRepository,
protected ServerConfigurationStructureService $serverConfigurationStructureService, protected ServerConfigurationStructureService $serverConfigurationStructureService,
protected StartupModificationService $startupModificationService, protected StartupModificationService $startupModificationService,
protected SuspensionService $suspensionService protected SuspensionService $suspensionService

View file

@ -3,7 +3,6 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Nests; namespace Pterodactyl\Http\Controllers\Api\Application\Nests;
use Pterodactyl\Models\Nest; use Pterodactyl\Models\Nest;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\NestTransformer; use Pterodactyl\Transformers\Api\Application\NestTransformer;
use Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest; use Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController; use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
@ -13,7 +12,7 @@ class NestController extends ApplicationApiController
/** /**
* NestController constructor. * NestController constructor.
*/ */
public function __construct(private NestRepositoryInterface $repository) public function __construct()
{ {
parent::__construct(); parent::__construct();
} }
@ -23,7 +22,7 @@ class NestController extends ApplicationApiController
*/ */
public function index(GetNestsRequest $request): array public function index(GetNestsRequest $request): array
{ {
$nests = $this->repository->paginated($request->query('per_page') ?? 50); $nests = Nest::query()->paginate($request->query('per_page') ?? 50);
return $this->fractal->collection($nests) return $this->fractal->collection($nests)
->transformWith($this->getTransformer(NestTransformer::class)) ->transformWith($this->getTransformer(NestTransformer::class))

View file

@ -4,7 +4,6 @@ namespace Pterodactyl\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Pterodactyl\Repositories\Eloquent\EggRepository; use Pterodactyl\Repositories\Eloquent\EggRepository;
use Pterodactyl\Repositories\Eloquent\NestRepository;
use Pterodactyl\Repositories\Eloquent\NodeRepository; use Pterodactyl\Repositories\Eloquent\NodeRepository;
use Pterodactyl\Repositories\Eloquent\TaskRepository; use Pterodactyl\Repositories\Eloquent\TaskRepository;
use Pterodactyl\Repositories\Eloquent\UserRepository; use Pterodactyl\Repositories\Eloquent\UserRepository;
@ -19,7 +18,6 @@ use Pterodactyl\Repositories\Eloquent\SettingsRepository;
use Pterodactyl\Repositories\Eloquent\AllocationRepository; use Pterodactyl\Repositories\Eloquent\AllocationRepository;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface; use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Repositories\Eloquent\EggVariableRepository; use Pterodactyl\Repositories\Eloquent\EggVariableRepository;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface; use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface; use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface; use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
@ -53,7 +51,6 @@ class RepositoryServiceProvider extends ServiceProvider
$this->app->bind(EggRepositoryInterface::class, EggRepository::class); $this->app->bind(EggRepositoryInterface::class, EggRepository::class);
$this->app->bind(EggVariableRepositoryInterface::class, EggVariableRepository::class); $this->app->bind(EggVariableRepositoryInterface::class, EggVariableRepository::class);
$this->app->bind(LocationRepositoryInterface::class, LocationRepository::class); $this->app->bind(LocationRepositoryInterface::class, LocationRepository::class);
$this->app->bind(NestRepositoryInterface::class, NestRepository::class);
$this->app->bind(NodeRepositoryInterface::class, NodeRepository::class); $this->app->bind(NodeRepositoryInterface::class, NodeRepository::class);
$this->app->bind(ScheduleRepositoryInterface::class, ScheduleRepository::class); $this->app->bind(ScheduleRepositoryInterface::class, ScheduleRepository::class);
$this->app->bind(ServerRepositoryInterface::class, ServerRepository::class); $this->app->bind(ServerRepositoryInterface::class, ServerRepository::class);

View file

@ -1,77 +0,0 @@
<?php
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Nest;
use Illuminate\Database\Eloquent\Collection;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
class NestRepository extends EloquentRepository implements NestRepositoryInterface
{
/**
* Return the model backing this repository.
*/
public function model(): string
{
return Nest::class;
}
/**
* Return a nest or all nests with their associated eggs and variables.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithEggs(int $id = null): Collection|Nest
{
$instance = $this->getBuilder()->with('eggs', 'eggs.variables');
if (!is_null($id)) {
$instance = $instance->find($id, $this->getColumns());
if (!$instance) {
throw new RecordNotFoundException();
}
return $instance;
}
return $instance->get($this->getColumns());
}
/**
* Return a nest or all nests and the count of eggs and servers for that nest.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithCounts(int $id = null): Collection|Nest
{
$instance = $this->getBuilder()->withCount(['eggs', 'servers']);
if (!is_null($id)) {
$instance = $instance->find($id, $this->getColumns());
if (!$instance) {
throw new RecordNotFoundException();
}
return $instance;
}
return $instance->get($this->getColumns());
}
/**
* Return a nest along with its associated eggs and the servers relation on those eggs.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithEggServers(int $id): Nest
{
$instance = $this->getBuilder()->with('eggs.servers')->find($id, $this->getColumns());
if (!$instance) {
throw new RecordNotFoundException();
}
/* @var Nest $instance */
return $instance;
}
}

View file

@ -4,7 +4,6 @@ namespace Pterodactyl\Services\Nests;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\Nest; use Pterodactyl\Models\Nest;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository; use Illuminate\Contracts\Config\Repository as ConfigRepository;
class NestCreationService class NestCreationService
@ -12,7 +11,7 @@ class NestCreationService
/** /**
* NestCreationService constructor. * NestCreationService constructor.
*/ */
public function __construct(private ConfigRepository $config, private NestRepositoryInterface $repository) public function __construct(private ConfigRepository $config)
{ {
} }
@ -23,11 +22,14 @@ class NestCreationService
*/ */
public function handle(array $data, string $author = null): Nest public function handle(array $data, string $author = null): Nest
{ {
return $this->repository->create([ /** @var Nest $nest */
$nest = Nest::query()->create([
'uuid' => Uuid::uuid4()->toString(), 'uuid' => Uuid::uuid4()->toString(),
'author' => $author ?? $this->config->get('pterodactyl.service.author'), 'author' => $author ?? $this->config->get('pterodactyl.service.author'),
'name' => array_get($data, 'name'), 'name' => array_get($data, 'name'),
'description' => array_get($data, 'description'), 'description' => array_get($data, 'description'),
], true, true); ]);
return $nest;
} }
} }

View file

@ -2,7 +2,7 @@
namespace Pterodactyl\Services\Nests; namespace Pterodactyl\Services\Nests;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface; use Pterodactyl\Models\Nest;
use Pterodactyl\Exceptions\Service\HasActiveServersException; use Pterodactyl\Exceptions\Service\HasActiveServersException;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
@ -11,16 +11,14 @@ class NestDeletionService
/** /**
* NestDeletionService constructor. * NestDeletionService constructor.
*/ */
public function __construct( public function __construct(protected ServerRepositoryInterface $serverRepository)
protected ServerRepositoryInterface $serverRepository, {
protected NestRepositoryInterface $repository
) {
} }
/** /**
* Delete a nest from the system only if there are no servers attached to it. * Delete a nest from the system only if there are no servers attached to it.
* *
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException * @throws HasActiveServersException
*/ */
public function handle(int $nest): int public function handle(int $nest): int
{ {
@ -29,6 +27,8 @@ class NestDeletionService
throw new HasActiveServersException(trans('exceptions.nest.delete_has_servers')); throw new HasActiveServersException(trans('exceptions.nest.delete_has_servers'));
} }
return $this->repository->delete($nest); $nest = Nest::query()->findOrFail($nest);
return $nest->delete();
} }
} }

View file

@ -2,22 +2,13 @@
namespace Pterodactyl\Services\Nests; namespace Pterodactyl\Services\Nests;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface; use Pterodactyl\Models\Nest;
class NestUpdateService class NestUpdateService
{ {
/**
* NestUpdateService constructor.
*/
public function __construct(protected NestRepositoryInterface $repository)
{
}
/** /**
* Update a nest and prevent changing the author once it is set. * Update a nest and prevent changing the author once it is set.
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function handle(int $nest, array $data): void public function handle(int $nest, array $data): void
{ {
@ -25,6 +16,7 @@ class NestUpdateService
unset($data['author']); unset($data['author']);
} }
$this->repository->withoutFreshModel()->update($nest, $data); $nest = Nest::query()->findOrFail($nest);
$nest->update($data);
} }
} }

View file

@ -3,8 +3,8 @@
namespace Database\Seeders; namespace Database\Seeders;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Pterodactyl\Models\Nest;
use Pterodactyl\Services\Nests\NestCreationService; use Pterodactyl\Services\Nests\NestCreationService;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
class NestSeeder extends Seeder class NestSeeder extends Seeder
{ {
@ -13,20 +13,12 @@ class NestSeeder extends Seeder
*/ */
private $creationService; private $creationService;
/**
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
*/
private $repository;
/** /**
* NestSeeder constructor. * NestSeeder constructor.
*/ */
public function __construct( public function __construct(NestCreationService $creationService)
NestCreationService $creationService, {
NestRepositoryInterface $repository
) {
$this->creationService = $creationService; $this->creationService = $creationService;
$this->repository = $repository;
} }
/** /**
@ -36,9 +28,10 @@ class NestSeeder extends Seeder
*/ */
public function run() public function run()
{ {
$items = $this->repository->findWhere([ $items = Nest::query()
'author' => 'support@pterodactyl.io', ->where('author', 'support@pterodactyl.io')
])->keyBy('name')->toArray(); ->get()
->keyBy('name')->toArray();
$this->createMinecraftNest(array_get($items, 'Minecraft')); $this->createMinecraftNest(array_get($items, 'Minecraft'));
$this->createSourceEngineNest(array_get($items, 'Source Engine')); $this->createSourceEngineNest(array_get($items, 'Source Engine'));

View file

@ -3,31 +3,19 @@
namespace Pterodactyl\Tests\Integration\Api\Application\Nests; namespace Pterodactyl\Tests\Integration\Api\Application\Nests;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface; use Pterodactyl\Models\Nest;
use Pterodactyl\Transformers\Api\Application\NestTransformer; use Pterodactyl\Transformers\Api\Application\NestTransformer;
use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase; use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;
class NestControllerTest extends ApplicationApiIntegrationTestCase class NestControllerTest extends ApplicationApiIntegrationTestCase
{ {
private NestRepositoryInterface $repository;
/**
* Setup tests.
*/
public function setUp(): void
{
parent::setUp();
$this->repository = $this->app->make(NestRepositoryInterface::class);
}
/** /**
* Test that the expected nests are returned by the request. * Test that the expected nests are returned by the request.
*/ */
public function testNestResponse() public function testNestResponse()
{ {
/** @var \Pterodactyl\Models\Nest[] $nests */ /** @var Nest[] $nests */
$nests = $this->repository->all(); $nests = Nest::all();
$response = $this->getJson('/api/application/nests'); $response = $this->getJson('/api/application/nests');
$response->assertStatus(Response::HTTP_OK); $response->assertStatus(Response::HTTP_OK);
@ -65,7 +53,7 @@ class NestControllerTest extends ApplicationApiIntegrationTestCase
*/ */
public function testSingleNestResponse() public function testSingleNestResponse()
{ {
$nest = $this->repository->find(1); $nest = Nest::query()->findOrFail(1);
$response = $this->getJson('/api/application/nests/' . $nest->id); $response = $this->getJson('/api/application/nests/' . $nest->id);
$response->assertStatus(Response::HTTP_OK); $response->assertStatus(Response::HTTP_OK);
@ -85,7 +73,7 @@ class NestControllerTest extends ApplicationApiIntegrationTestCase
*/ */
public function testSingleNestWithEggsIncluded() public function testSingleNestWithEggsIncluded()
{ {
$nest = $this->repository->find(1); $nest = Nest::query()->findOrFail(1);
$nest->loadMissing('eggs'); $nest->loadMissing('eggs');
$response = $this->getJson('/api/application/nests/' . $nest->id . '?include=servers,eggs'); $response = $this->getJson('/api/application/nests/' . $nest->id . '?include=servers,eggs');
@ -118,7 +106,7 @@ class NestControllerTest extends ApplicationApiIntegrationTestCase
*/ */
public function testErrorReturnedIfNoPermission() public function testErrorReturnedIfNoPermission()
{ {
$nest = $this->repository->find(1); $nest = Nest::query()->findOrFail(1);
$this->createNewDefaultApiKey($this->getApiUser(), ['r_nests' => 0]); $this->createNewDefaultApiKey($this->getApiUser(), ['r_nests' => 0]);
$response = $this->getJson('/api/application/nests/' . $nest->id); $response = $this->getJson('/api/application/nests/' . $nest->id);