throw exception if text doesnt exist
This commit is contained in:
parent
3b79417065
commit
b3453a4604
1 changed files with 7 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ use App\Node\Node;
|
||||||
use App\Node\CreateNodeDto;
|
use App\Node\CreateNodeDto;
|
||||||
use App\Node\NodeRepository;
|
use App\Node\NodeRepository;
|
||||||
use App\Text\TextRepository;
|
use App\Text\TextRepository;
|
||||||
|
use DomainException;
|
||||||
|
|
||||||
class CreateNode
|
class CreateNode
|
||||||
{
|
{
|
||||||
|
|
@ -16,7 +17,12 @@ class CreateNode
|
||||||
|
|
||||||
public function execute(CreateNodeRequest $request): Node
|
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(
|
return $this->nodeRepo->create(new CreateNodeDto(
|
||||||
text: $text,
|
text: $text,
|
||||||
title: $request->title,
|
title: $request->title,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue