From 021a2a6f1587e2f15eae3968ed89c6a9d6bded5b Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sat, 21 Feb 2026 22:15:24 +0200 Subject: [PATCH] add parent node to node, fix type of null --- app/Node/CreateNodeDto.php | 1 + app/Node/Node.php | 12 ++++++++++++ app/Node/UseCases/CreateNode.php | 9 +++++++++ app/Node/UseCases/CreateNodeRequest.php | 1 + tests/Fakes/FakeNodeRepository.php | 2 +- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/Node/CreateNodeDto.php b/app/Node/CreateNodeDto.php index ca87f51..7b18143 100644 --- a/app/Node/CreateNodeDto.php +++ b/app/Node/CreateNodeDto.php @@ -9,5 +9,6 @@ class CreateNodeDto public function __construct( public Text $text, public string $title, + public ?Node $parentNode, ) {} } diff --git a/app/Node/Node.php b/app/Node/Node.php index c5cc050..a54ec19 100644 --- a/app/Node/Node.php +++ b/app/Node/Node.php @@ -7,10 +7,17 @@ use App\Text\Text; class Node { public function __construct( + private int $id, private string $title, private Text $text, + private ?Node $parentNode, ) {} + public function getId(): int + { + return $this->id; + } + public function getTitle(): string { return $this->title; @@ -20,4 +27,9 @@ class Node { return $this->text; } + + public function getParentNode(): ?Node + { + return $this->parentNode; + } } diff --git a/app/Node/UseCases/CreateNode.php b/app/Node/UseCases/CreateNode.php index f67b2de..ad2a7e6 100644 --- a/app/Node/UseCases/CreateNode.php +++ b/app/Node/UseCases/CreateNode.php @@ -22,10 +22,19 @@ class CreateNode if ($text === null) { throw new DomainException("Text with id: $id doesnt exist"); } + if ($request->parentNodeId === null) { + return $this->nodeRepo->create(new CreateNodeDto( + text: $text, + title: $request->title, + parentNode: null, + )); + } + $parentNode = $this->nodeRepo->find($request->parentNodeId); return $this->nodeRepo->create(new CreateNodeDto( text: $text, title: $request->title, + parentNode: $parentNode, )); } } diff --git a/app/Node/UseCases/CreateNodeRequest.php b/app/Node/UseCases/CreateNodeRequest.php index 4ea1d11..700a824 100644 --- a/app/Node/UseCases/CreateNodeRequest.php +++ b/app/Node/UseCases/CreateNodeRequest.php @@ -7,5 +7,6 @@ class CreateNodeRequest public function __construct( public int $textId, public string $title, + public ?int $parentNodeId, ) {} } diff --git a/tests/Fakes/FakeNodeRepository.php b/tests/Fakes/FakeNodeRepository.php index 994f4a5..fad7e4e 100644 --- a/tests/Fakes/FakeNodeRepository.php +++ b/tests/Fakes/FakeNodeRepository.php @@ -38,7 +38,7 @@ class FakeNodeRepository implements NodeRepository } ); if ($node === null) { - return nullj; + return null; } return new Node(