add node to scheduled node
This commit is contained in:
parent
d47a0235d2
commit
a9265abeae
8 changed files with 88 additions and 6 deletions
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ class CreateScheduledNodeRequest
|
|||
public function __construct(
|
||||
public ?string $date,
|
||||
public ?int $planId,
|
||||
public ?int $nodeId,
|
||||
) {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue