Remove TextRepository dependency and createText from ViewController
This commit is contained in:
parent
5c5f3f7118
commit
89c295e6d2
1 changed files with 0 additions and 34 deletions
|
|
@ -2,19 +2,10 @@
|
|||
|
||||
namespace App\View;
|
||||
|
||||
use App\Text\CreateTextDto;
|
||||
use App\Text\TextRepository;
|
||||
use App\Text\UseCases\CreateText;
|
||||
use App\Text\UseCases\CreateTextRequest;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
class ViewController
|
||||
{
|
||||
public function __construct(
|
||||
private TextRepository $textRepository,
|
||||
) {}
|
||||
|
||||
public function admin(Response $response): Response
|
||||
{
|
||||
$html = file_get_contents(__DIR__.'/../../views/templates/admin.php', true);
|
||||
|
|
@ -25,34 +16,9 @@ class ViewController
|
|||
|
||||
public function texts(Response $response): Response
|
||||
{
|
||||
$texts = $this->textRepository->getAll();
|
||||
|
||||
$textsList = '';
|
||||
foreach ($texts as $text) {
|
||||
$textsList .= '<li>' . htmlspecialchars($text->getName()) . '</li>';
|
||||
}
|
||||
|
||||
$html = file_get_contents(__DIR__.'/../../views/templates/texts.php', true);
|
||||
$html = str_replace('{{texts}}', $textsList, $html);
|
||||
$response->getBody()->write($html);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function createText(
|
||||
Request $request,
|
||||
Response $response,
|
||||
CreateText $createTextUseCase,
|
||||
): Response {
|
||||
$data = $request->getParsedBody();
|
||||
$name = $data['name'] ?? '';
|
||||
|
||||
if (!empty($name)) {
|
||||
$createTextUseCase->execute(new CreateTextRequest(
|
||||
name: $name,
|
||||
));
|
||||
}
|
||||
|
||||
return $response->withHeader('Location', '/admin/texts')->withStatus(302);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue