plan schedules all nodes of text - impl of use case

This commit is contained in:
Yisroel Baum 2026-03-01 11:57:33 +02:00
parent 0d00254e5f
commit a606ceadaa
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 23 additions and 3 deletions

View file

@ -2,10 +2,15 @@
namespace App\Plan\UseCases;
use App\Node\NodeRepository;
use App\Plan\CreatePlanDto;
use App\Plan\Plan;
use App\Plan\PlanRepository;
use App\ScheduledNode\UseCases\CreateScheduledNode;
use App\ScheduledNode\UseCases\CreateScheduledNodeRequest;
use App\Text\TextRepository;
use App\User\UserRepository;
use DateTimeImmutable;
use DomainException;
class CreatePlan
@ -13,6 +18,9 @@ class CreatePlan
public function __construct(
private PlanRepository $planRepo,
private UserRepository $userRepo,
private TextRepository $textRepo,
private NodeRepository $nodeRepo,
private CreateScheduledNode $createScheduledNode,
) {}
/**
@ -22,14 +30,25 @@ class CreatePlan
{
$userId = $request->userId;
$user = $this->userRepo->find($userId);
if ($user === null) {
throw new DomainException("User with id: $userId doesnt exist");
}
return $this->planRepo->create(new CreatePlanDto(
$textId = $request->textId;
$text = $this->textRepo->find($textId);
$nodesOfText = $this->nodeRepo->findByTextId($textId);
$plan = $this->planRepo->create(new CreatePlanDto(
name: $request->name,
user: $user,
));
foreach ($nodesOfText as $node) {
$this->createScheduledNode->execute(
new CreateScheduledNodeRequest(
date: new DateTimeImmutable(),
planId: $plan->getId(),
)
);
}
return $plan;
}
}

View file

@ -6,6 +6,7 @@ class CreatePlanRequest
{
public function __construct(
public int $userId,
public int $textId,
public string $name,
) {}
}