mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-19 06:43:45 +02:00
api(application): relocate egg endpoints
This commit is contained in:
122
app/Http/Controllers/Api/Application/Eggs/EggController.php
Normal file
122
app/Http/Controllers/Api/Application/Eggs/EggController.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Application\Eggs;
|
||||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Transformers\Api\Application\EggTransformer;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Eggs\GetEggRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Eggs\GetEggsRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Eggs\StoreEggRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Eggs\UpdateEggRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Eggs\DeleteEggRequest;
|
||||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||
|
||||
class EggController extends ApplicationApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* EggController constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(EggRepositoryInterface $repository)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of all eggs on a given nest.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\GetEggsRequest $request
|
||||
* @param \Pterodactyl\Models\Nest $nest
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(GetEggsRequest $request, Nest $nest): array
|
||||
{
|
||||
$eggs = $this->repository->findWhere([
|
||||
['nest_id', '=', $nest->id],
|
||||
]);
|
||||
|
||||
return $this->fractal->collection($eggs)
|
||||
->transformWith($this->getTransformer(EggTransformer::class))
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single egg.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\GetEggRequest $request
|
||||
* @param \Pterodactyl\Models\Egg $egg
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function view(GetEggRequest $request, Egg $egg): array
|
||||
{
|
||||
return $this->fractal->item($egg)
|
||||
->transformWith($this->getTransformer(EggTransformer::class))
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new egg.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\StoreEggRequest $request
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function store(StoreEggRequest $request): JsonResponse
|
||||
{
|
||||
$egg = Egg::query()->create($request->validated());
|
||||
|
||||
return $this->fractal->item($egg)
|
||||
->transformWith($this->getTransformer(EggTransformer::class))
|
||||
->respond(JsonResponse::HTTP_CREATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an egg.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\UpdateEggRequest $request
|
||||
* @param \Pterodactyl\Models\Egg $egg
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function update(UpdateEggRequest $request, Egg $egg): array
|
||||
{
|
||||
$egg->update($request->validated());
|
||||
|
||||
return $this->fractal->item($egg)
|
||||
->transformWith($this->getTransformer(EggTransformer::class))
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an egg.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\DeleteEggRequest $request
|
||||
* @param \Pterodactyl\Models\Egg $egg
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(DeleteEggRequest $request, Egg $egg): JsonResponse
|
||||
{
|
||||
$egg->delete();
|
||||
|
||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Application\Nests;
|
||||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Transformers\Api\Application\EggTransformer;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Nests\Eggs\GetEggRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Nests\Eggs\GetEggsRequest;
|
||||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||
|
||||
class EggController extends ApplicationApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* EggController constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(EggRepositoryInterface $repository)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all eggs that exist for a given nest.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\Eggs\GetEggsRequest $request
|
||||
* @param \Pterodactyl\Models\Nest $nest
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(GetEggsRequest $request, Nest $nest): array
|
||||
{
|
||||
$eggs = $this->repository->findWhere([
|
||||
['nest_id', '=', $nest->id],
|
||||
]);
|
||||
|
||||
return $this->fractal->collection($eggs)
|
||||
->transformWith($this->getTransformer(EggTransformer::class))
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single egg that exists on the specified nest.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\Eggs\GetEggRequest $request
|
||||
* @param \Pterodactyl\Models\Egg $egg
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function view(GetEggRequest $request, Egg $egg): array
|
||||
{
|
||||
return $this->fractal->item($egg)
|
||||
->transformWith($this->getTransformer(EggTransformer::class))
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,9 @@ use Pterodactyl\Transformers\Api\Application\NestTransformer;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Nests\GetNestRequest;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Nests\StoreNestRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Nests\StoreEggRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Nests\UpdateNestRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Nests\DeleteNestRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Nests\DeleteEggRequest;
|
||||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||
|
||||
class NestController extends ApplicationApiController
|
||||
@@ -105,13 +105,13 @@ class NestController extends ApplicationApiController
|
||||
/**
|
||||
* Creates a new nest.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\StoreNestRequest $request
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\StoreEggRequest $request
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function store(StoreNestRequest $request): array
|
||||
public function store(StoreEggRequest $request): array
|
||||
{
|
||||
$nest = $this->nestCreationService->handle($request->validated());
|
||||
|
||||
@@ -143,13 +143,13 @@ class NestController extends ApplicationApiController
|
||||
/**
|
||||
* Deletes an existing nest.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\DeleteNestRequest $request
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\DeleteEggRequest $request
|
||||
* @param \Pterodactyl\Models\Nest $nest
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
||||
*/
|
||||
public function delete(DeleteNestRequest $request, Nest $nest): JsonResponse
|
||||
public function delete(DeleteEggRequest $request, Nest $nest): JsonResponse
|
||||
{
|
||||
$this->nestDeletionService->handle($nest->id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user