add use case and request

This commit is contained in:
Yisroel Baum 2026-04-18 23:04:56 +03:00
parent 5c2b6c9edd
commit ce56e460ff
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,45 @@
<?php
namespace App\Node\UseCases;
use App\Node\CreateNodeDto;
use App\Node\Node;
use App\Node\NodeRepository;
use App\Text\TextRepository;
use DomainException;
class BulkCreateNodes
{
public function __construct(
private NodeRepository $nodeRepo,
private TextRepository $textRepo,
) {}
/**
* @return Node[]
* @throws DomainException
*/
public function execute(BulkCreateNodesRequest $request): array
{
$text = $this->textRepo->find($request->textId);
if ($text === null) {
throw new DomainException("Text with id: {$request->textId} doesnt exist");
}
$parentNode = $this->nodeRepo->find($request->parentNodeId);
if ($parentNode === null) {
throw new DomainException("Node with id: {$request->parentNodeId} doesnt exist");
}
$created = [];
for ($i = 1; $i <= $request->count; $i++) {
$created[] = $this->nodeRepo->create(new CreateNodeDto(
text: $text,
title: "{$request->titlePrefix} {$i}",
parentNode: $parentNode,
));
}
return $created;
}
}