Compare commits
5 commits
d4e31baed0
...
d5bc01f6bd
| Author | SHA1 | Date | |
|---|---|---|---|
| d5bc01f6bd | |||
| 210b77b10b | |||
| 72d92debab | |||
| 854771eaa9 | |||
| 3594f9c147 |
5 changed files with 28 additions and 4 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
vendor/
|
||||
node_modules/
|
||||
node_modules/
|
||||
data/
|
||||
|
|
@ -2,8 +2,12 @@
|
|||
|
||||
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
|
||||
{
|
||||
|
|
@ -34,4 +38,21 @@ class ViewController
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,5 +13,6 @@ $app->addErrorMiddleware(true, true, true);
|
|||
|
||||
$app->get('/admin', [ViewController::class, 'admin']);
|
||||
$app->get('/admin/texts', [ViewController::class, 'texts']);
|
||||
$app->post('/admin/texts', [ViewController::class, 'createText']);
|
||||
|
||||
return $app;
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
[]
|
||||
|
|
@ -9,7 +9,9 @@
|
|||
<ul id="texts-list">
|
||||
{{texts}}
|
||||
</ul>
|
||||
<input id="newTextName"/>
|
||||
<button id="submit">submit</button>
|
||||
<form action="/admin/texts" method="POST">
|
||||
<input id="newTextName" name="name"/>
|
||||
<button id="submit">submit</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue