refactor getNodes into a new NodeController and update refs

This commit is contained in:
Yisroel Baum 2026-04-17 11:29:55 +03:00
parent acdfc14442
commit 38d06fce43
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 40 additions and 27 deletions

View file

@ -5,7 +5,6 @@ namespace App\Text;
use App\Text\TextRepository;
use App\Text\UseCases\CreateText;
use App\Text\UseCases\CreateTextRequest;
use App\Node\NodeRepository;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
@ -13,7 +12,6 @@ class TextController
{
public function __construct(
private TextRepository $textRepository,
private NodeRepository $nodeRepository,
) {}
public function getTexts(Response $response): Response
@ -46,28 +44,6 @@ class TextController
return $response->withHeader('Content-Type', 'application/json');
}
public function getNodes(Response $response, int $textId): Response
{
$text = $this->textRepository->find($textId);
if ($text === null) {
return $response->withStatus(404);
}
$nodes = $this->nodeRepository->findByTextId($textId);
$data = array_map(function ($node) {
return [
'id' => $node->getId(),
'title' => $node->getTitle(),
'parentNodeId' => $node->getParentNode()?->getId(),
];
}, $nodes);
$response->getBody()->write(json_encode(array_values($data)));
return $response->withHeader('Content-Type', 'application/json');
}
public function createText(
Request $request,
Response $response,