add node to scheduled node

This commit is contained in:
Yisroel Baum 2026-04-27 09:28:43 +03:00
parent d47a0235d2
commit a9265abeae
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
8 changed files with 88 additions and 6 deletions

View file

@ -64,6 +64,7 @@ class CreatePlan
new CreateScheduledNodeRequest(
date: $scheduledDate->format('Y-m-d'),
planId: $plan->getId(),
nodeId: $node->getId(),
)
);
}

View file

@ -20,6 +20,7 @@ class JsonScheduledNodeRepository implements ScheduledNodeRepository
'id' => $id,
'date' => $dto->date->format('Y-m-d'),
'planId' => $dto->plan->getId(),
'nodeId' => $dto->node->getId(),
];
$this->writeScheduledNodes($scheduledNodes);
@ -27,6 +28,7 @@ class JsonScheduledNodeRepository implements ScheduledNodeRepository
id: $id,
date: $dto->date,
plan: $dto->plan,
node: $dto->node,
);
}

View file

@ -3,6 +3,7 @@
namespace App\ScheduledNode\UseCases;
use App\Exceptions\BadRequestException;
use App\Node\NodeRepository;
use App\Plan\PlanRepository;
use App\ScheduledNode\ScheduledNode;
use App\ScheduledNode\CreateScheduledNodeDto;
@ -15,6 +16,7 @@ class CreateScheduledNode
public function __construct(
private ScheduledNodeRepository $scheduledNodeRepo,
private PlanRepository $planRepo,
private NodeRepository $nodeRepo,
) {}
/**
@ -24,24 +26,40 @@ class CreateScheduledNode
public function execute(
CreateScheduledNodeRequest $request
): ScheduledNode {
if ($request->date === null) {
$nodeId = $request->nodeId;
$planId = $request->planId;
$date = $request->date;
if ($date === null) {
throw new BadRequestException('date is required');
}
if ($request->planId === null) {
if ($planId === null) {
throw new BadRequestException('planId is required');
}
$id = $request->planId;
$plan = $this->planRepo->find($id);
if ($nodeId === null) {
throw new BadRequestException('nodeId is required');
}
$plan = $this->planRepo->find($planId);
if ($plan === null) {
throw new DomainException("Plan with id: $id doesnt exist");
throw new DomainException(
"Plan with id: $planId doesnt exist"
);
}
$node = $this->nodeRepo->find($nodeId);
if ($node === null) {
throw new DomainException(
"Node with id: $nodeId doesnt exist"
);
}
return $this->scheduledNodeRepo->create(
new CreateScheduledNodeDto(
date: new DateTimeImmutable($request->date),
date: new DateTimeImmutable($date),
plan: $plan,
node: $node,
)
);
}

View file

@ -7,5 +7,6 @@ class CreateScheduledNodeRequest
public function __construct(
public ?string $date,
public ?int $planId,
public ?int $nodeId,
) {}
}