From a606ceadaade5d70e99aefdb4e7cb8e79d33f0f0 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sun, 1 Mar 2026 11:57:33 +0200 Subject: [PATCH] plan schedules all nodes of text - impl of use case --- app/Plan/UseCases/CreatePlan.php | 25 ++++++++++++++++++++++--- app/Plan/UseCases/CreatePlanRequest.php | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/Plan/UseCases/CreatePlan.php b/app/Plan/UseCases/CreatePlan.php index c172653..2ce21c4 100644 --- a/app/Plan/UseCases/CreatePlan.php +++ b/app/Plan/UseCases/CreatePlan.php @@ -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; } } diff --git a/app/Plan/UseCases/CreatePlanRequest.php b/app/Plan/UseCases/CreatePlanRequest.php index db9a51a..2af3e1e 100644 --- a/app/Plan/UseCases/CreatePlanRequest.php +++ b/app/Plan/UseCases/CreatePlanRequest.php @@ -6,6 +6,7 @@ class CreatePlanRequest { public function __construct( public int $userId, + public int $textId, public string $name, ) {} }