Replace nest repository

This commit is contained in:
Lance Pioch 2022-10-23 20:15:11 -04:00
parent 860b2d890b
commit 43e419fd7e
15 changed files with 40 additions and 186 deletions

View file

@ -4,7 +4,6 @@ namespace Pterodactyl\Services\Nests;
use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\Nest;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
class NestCreationService
@ -12,7 +11,7 @@ class NestCreationService
/**
* 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
{
return $this->repository->create([
/** @var Nest $nest */
$nest = Nest::query()->create([
'uuid' => Uuid::uuid4()->toString(),
'author' => $author ?? $this->config->get('pterodactyl.service.author'),
'name' => array_get($data, 'name'),
'description' => array_get($data, 'description'),
], true, true);
]);
return $nest;
}
}

View file

@ -2,7 +2,7 @@
namespace Pterodactyl\Services\Nests;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Models\Nest;
use Pterodactyl\Exceptions\Service\HasActiveServersException;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
@ -11,16 +11,14 @@ class NestDeletionService
/**
* NestDeletionService constructor.
*/
public function __construct(
protected ServerRepositoryInterface $serverRepository,
protected NestRepositoryInterface $repository
) {
public function __construct(protected ServerRepositoryInterface $serverRepository)
{
}
/**
* 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
{
@ -29,6 +27,8 @@ class NestDeletionService
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;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Models\Nest;
class NestUpdateService
{
/**
* NestUpdateService constructor.
*/
public function __construct(protected NestRepositoryInterface $repository)
{
}
/**
* 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
{
@ -25,6 +16,7 @@ class NestUpdateService
unset($data['author']);
}
$this->repository->withoutFreshModel()->update($nest, $data);
$nest = Nest::query()->findOrFail($nest);
$nest->update($data);
}
}