Replace egg repository

This commit is contained in:
Lance Pioch 2022-10-23 17:27:18 -04:00
parent 860b2d890b
commit 6e4f7f16c1
11 changed files with 54 additions and 206 deletions

View file

@ -4,7 +4,6 @@ namespace Pterodactyl\Services\Eggs;
use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\Egg;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
@ -14,33 +13,35 @@ class EggCreationService
/**
* EggCreationService constructor.
*/
public function __construct(private ConfigRepository $config, private EggRepositoryInterface $repository)
public function __construct(private ConfigRepository $config)
{
}
/**
* Create a new service option and assign it to the given service.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
* @throws NoParentConfigurationFoundException
*/
public function handle(array $data): Egg
{
$data['config_from'] = array_get($data, 'config_from');
if (!is_null($data['config_from'])) {
$results = $this->repository->findCountWhere([
['nest_id', '=', array_get($data, 'nest_id')],
['id', '=', array_get($data, 'config_from')],
]);
$results = Egg::query()
->where('nest_id', array_get($data, 'nest_id'))
->where('id', array_get($data, 'config_from'))
->count();
if ($results !== 1) {
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
}
}
return $this->repository->create(array_merge($data, [
/** @var Egg $egg */
$egg = Egg::query()->create(array_merge($data, [
'uuid' => Uuid::uuid4()->toString(),
'author' => $this->config->get('pterodactyl.service.author'),
]), true, true);
]));
return $egg;
}
}