add parent node to node, fix type of null
This commit is contained in:
parent
483110f773
commit
021a2a6f15
5 changed files with 24 additions and 1 deletions
|
|
@ -9,5 +9,6 @@ class CreateNodeDto
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public Text $text,
|
public Text $text,
|
||||||
public string $title,
|
public string $title,
|
||||||
|
public ?Node $parentNode,
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,17 @@ use App\Text\Text;
|
||||||
class Node
|
class Node
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
private int $id,
|
||||||
private string $title,
|
private string $title,
|
||||||
private Text $text,
|
private Text $text,
|
||||||
|
private ?Node $parentNode,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
public function getId(): int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
{
|
{
|
||||||
return $this->title;
|
return $this->title;
|
||||||
|
|
@ -20,4 +27,9 @@ class Node
|
||||||
{
|
{
|
||||||
return $this->text;
|
return $this->text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getParentNode(): ?Node
|
||||||
|
{
|
||||||
|
return $this->parentNode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,19 @@ class CreateNode
|
||||||
if ($text === null) {
|
if ($text === null) {
|
||||||
throw new DomainException("Text with id: $id doesnt exist");
|
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(
|
return $this->nodeRepo->create(new CreateNodeDto(
|
||||||
text: $text,
|
text: $text,
|
||||||
title: $request->title,
|
title: $request->title,
|
||||||
|
parentNode: $parentNode,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,6 @@ class CreateNodeRequest
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public int $textId,
|
public int $textId,
|
||||||
public string $title,
|
public string $title,
|
||||||
|
public ?int $parentNodeId,
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ class FakeNodeRepository implements NodeRepository
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ($node === null) {
|
if ($node === null) {
|
||||||
return nullj;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Node(
|
return new Node(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue