chore: complete update
This commit is contained in:
14
src/Application/Contact/ContactRequest.php
Normal file
14
src/Application/Contact/ContactRequest.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Application\Contact;
|
||||
|
||||
use App\Framework\Http\ControllerRequest;
|
||||
use App\Framework\Validation\Rules\Email;
|
||||
|
||||
class ContactRequest implements ControllerRequest
|
||||
{
|
||||
public string $name;
|
||||
#[Email]
|
||||
public string $email;
|
||||
public string $message;
|
||||
}
|
||||
47
src/Application/Contact/ShowContact.php
Normal file
47
src/Application/Contact/ShowContact.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Application\Contact;
|
||||
|
||||
use App\Framework\Attributes\Route;
|
||||
use App\Framework\CommandBus\CommandBus;
|
||||
use App\Framework\Http\Method;
|
||||
use App\Framework\Meta\Keywords;
|
||||
use App\Framework\Meta\StaticPageMetaResolver;
|
||||
use App\Framework\Router\ActionResult;
|
||||
use App\Framework\Router\Result\ContentNegotiationResult;
|
||||
use App\Framework\Router\Result\ViewResult;
|
||||
|
||||
final readonly class ShowContact
|
||||
{
|
||||
#[Route(path: '/kontakt', name: 'contact')]
|
||||
public function __invoke(): ViewResult
|
||||
{
|
||||
return new ViewResult('contact',
|
||||
new StaticPageMetaResolver(
|
||||
'Kontakt',
|
||||
'Kontaktseite!',
|
||||
Keywords::fromStrings('Kontakt', 'Welt')
|
||||
)(),);
|
||||
}
|
||||
|
||||
#[Route(path: '/kontakt', method: Method::POST)]
|
||||
public function senden(ContactRequest $request, CommandBus $commandBus): ActionResult
|
||||
{
|
||||
|
||||
$command = new StoreContact(
|
||||
$request->email,
|
||||
$request->name,
|
||||
$request->subject ?? 'Kein Betreff angegeben',
|
||||
$request->message,
|
||||
);
|
||||
|
||||
$commandBus->dispatch($command);
|
||||
|
||||
dd($request);
|
||||
|
||||
return new ContentNegotiationResult(
|
||||
|
||||
);
|
||||
#return new ViewResult('contact-senden');
|
||||
}
|
||||
}
|
||||
14
src/Application/Contact/StoreContact.php
Normal file
14
src/Application/Contact/StoreContact.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Application\Contact;
|
||||
|
||||
final class StoreContact
|
||||
{
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $email,
|
||||
public string $subject,
|
||||
public string $message,
|
||||
) {}
|
||||
}
|
||||
22
src/Application/Contact/StoreContactHandler.php
Normal file
22
src/Application/Contact/StoreContactHandler.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Application\Contact;
|
||||
|
||||
use App\Domain\Contact\ContactMessage;
|
||||
use App\Domain\Contact\ContactRepository;
|
||||
use App\Framework\CommandBus\CommandHandler;
|
||||
|
||||
final readonly class StoreContactHandler
|
||||
{
|
||||
public function __construct(
|
||||
private ContactRepository $contactRepository,
|
||||
) {}
|
||||
#[CommandHandler]
|
||||
public function __invoke(StoreContact $command): void
|
||||
{
|
||||
$message = new ContactMessage($command->name, $command->email, $command->message);
|
||||
|
||||
$this->contactRepository->save($message);
|
||||
}
|
||||
}
|
||||
74
src/Application/Contact/contact.view.php
Normal file
74
src/Application/Contact/contact.view.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<layout src="main"/>
|
||||
|
||||
<section>
|
||||
|
||||
<h1>Kontakt</h1>
|
||||
|
||||
|
||||
<form action="/kontakt" method="post">
|
||||
|
||||
<!-- Feld ist für Bots gedacht – normaler User sieht es nicht -->
|
||||
<div style="position: absolute; left: -10000px; top: auto;" aria-hidden="true">
|
||||
<label for="website">Ihre Website:</label>
|
||||
<input type="text" name="website" id="website" tabindex="-1" autocomplete="off">
|
||||
</div>
|
||||
|
||||
<div role="alert">
|
||||
Hallo Welt
|
||||
</div>
|
||||
|
||||
<label for="name">Name:</label>
|
||||
<input type="text" name="name" id="name">
|
||||
|
||||
<label for="email">E-Mail:</label>
|
||||
<input type="email" name="email" id="email">
|
||||
|
||||
<label for="subject">Betreff:</label>
|
||||
<select name="subject" id="subject">
|
||||
<option value="1">Anfrage</option>
|
||||
<option value="2">Beschwerde</option>
|
||||
<option value="3">Anregung</option>
|
||||
<option value="4">Sonstiges</option>
|
||||
</select>
|
||||
|
||||
<label for="message">Nachricht:</label>
|
||||
<textarea name="message" id="message"></textarea>
|
||||
|
||||
|
||||
<input type="submit" value="Senden">
|
||||
|
||||
</form>
|
||||
|
||||
</section>
|
||||
|
||||
<style>
|
||||
div.box {
|
||||
background: red;
|
||||
|
||||
}
|
||||
|
||||
div.outer {
|
||||
--outer-radius: 24px;
|
||||
--padding: 8px;
|
||||
--inner-radius: calc(var(--outer-radius) - var(--padding));
|
||||
|
||||
border-radius: var(--outer-radius);
|
||||
padding: var(--padding);
|
||||
|
||||
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
|
||||
|
||||
box-sizing: border-box;
|
||||
|
||||
}
|
||||
|
||||
.inner {
|
||||
border-radius: var(--inner-radius);
|
||||
--padding: 1rem;
|
||||
padding:inherit;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="box outer" style="background: grey;">
|
||||
Testbox
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user