Remove NodeCreationService (#1092)

This commit is contained in:
MartinOscar 2025-03-17 05:46:33 +01:00 committed by GitHub
parent 253abf65b1
commit 22d02c0df5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 41 deletions

View File

@ -2,8 +2,8 @@
namespace App\Console\Commands\Node; namespace App\Console\Commands\Node;
use App\Models\Node;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Services\Nodes\NodeCreationService;
class MakeNodeCommand extends Command class MakeNodeCommand extends Command
{ {
@ -30,14 +30,6 @@ class MakeNodeCommand extends Command
protected $description = 'Creates a new node on the system via the CLI.'; protected $description = 'Creates a new node on the system via the CLI.';
/**
* MakeNodeCommand constructor.
*/
public function __construct(private NodeCreationService $creationService)
{
parent::__construct();
}
/** /**
* Handle the command execution process. * Handle the command execution process.
* *
@ -69,7 +61,7 @@ class MakeNodeCommand extends Command
$data['daemon_sftp_alias'] = $this->option('daemonSFTPAlias') ?? $this->ask(trans('commands.make_node.daemonSFTPAlias'), ''); $data['daemon_sftp_alias'] = $this->option('daemonSFTPAlias') ?? $this->ask(trans('commands.make_node.daemonSFTPAlias'), '');
$data['daemon_base'] = $this->option('daemonBase') ?? $this->ask(trans('commands.make_node.daemonBase'), '/var/lib/pelican/volumes'); $data['daemon_base'] = $this->option('daemonBase') ?? $this->ask(trans('commands.make_node.daemonBase'), '/var/lib/pelican/volumes');
$node = $this->creationService->handle($data); $node = Node::create($data);
$this->line(trans('commands.make_node.success', ['name' => $data['name'], 'id' => $node->id])); $this->line(trans('commands.make_node.success', ['name' => $data['name'], 'id' => $node->id]));
} }
} }

View File

@ -6,7 +6,6 @@ use App\Models\Node;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder; use Spatie\QueryBuilder\QueryBuilder;
use App\Services\Nodes\NodeUpdateService; use App\Services\Nodes\NodeUpdateService;
use App\Services\Nodes\NodeCreationService;
use App\Services\Nodes\NodeDeletionService; use App\Services\Nodes\NodeDeletionService;
use App\Transformers\Api\Application\NodeTransformer; use App\Transformers\Api\Application\NodeTransformer;
use App\Http\Requests\Api\Application\Nodes\GetNodeRequest; use App\Http\Requests\Api\Application\Nodes\GetNodeRequest;
@ -24,7 +23,6 @@ class NodeController extends ApplicationApiController
* NodeController constructor. * NodeController constructor.
*/ */
public function __construct( public function __construct(
private NodeCreationService $creationService,
private NodeDeletionService $deletionService, private NodeDeletionService $deletionService,
private NodeUpdateService $updateService private NodeUpdateService $updateService
) { ) {
@ -74,7 +72,7 @@ class NodeController extends ApplicationApiController
*/ */
public function store(StoreNodeRequest $request): JsonResponse public function store(StoreNodeRequest $request): JsonResponse
{ {
$node = $this->creationService->handle($request->validated()); $node = Node::create($request->validated());
return $this->fractal->item($node) return $this->fractal->item($node)
->transformWith($this->getTransformer(NodeTransformer::class)) ->transformWith($this->getTransformer(NodeTransformer::class))

View File

@ -1,28 +0,0 @@
<?php
namespace App\Services\Nodes;
use Ramsey\Uuid\Uuid;
use Illuminate\Support\Str;
use App\Models\Node;
class NodeCreationService
{
/**
* Create a new node on the panel.
*
* @todo remove this class
*
* @param array<string, mixed> $data
*
* @throws \App\Exceptions\Model\DataValidationException
*/
public function handle(array $data): Node
{
$data['uuid'] = Uuid::uuid4()->toString();
$data['daemon_token'] = Str::random(Node::DAEMON_TOKEN_LENGTH);
$data['daemon_token_id'] = Str::random(Node::DAEMON_TOKEN_ID_LENGTH);
return Node::query()->create($data);
}
}