diff --git a/app/Node/UseCases/CreateNode.php b/app/Node/UseCases/CreateNode.php index 736ad26..f67b2de 100644 --- a/app/Node/UseCases/CreateNode.php +++ b/app/Node/UseCases/CreateNode.php @@ -6,6 +6,7 @@ use App\Node\Node; use App\Node\CreateNodeDto; use App\Node\NodeRepository; use App\Text\TextRepository; +use DomainException; class CreateNode { @@ -16,7 +17,12 @@ class CreateNode public function execute(CreateNodeRequest $request): Node { - $text = $this->textRepo->find($request->textId); + $id = $request->textId; + $text = $this->textRepo->find($id); + if ($text === null) { + throw new DomainException("Text with id: $id doesnt exist"); + } + return $this->nodeRepo->create(new CreateNodeDto( text: $text, title: $request->title,