From b9db0d97dc3b2ff9c1eec2eea97c50d9430e8ca1 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Sat, 14 Dec 2024 09:32:00 -0500 Subject: [PATCH] Flesh out the add channel handler. --- .../Controller/Channel/CreateChannelAction.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/Controller/Channel/CreateChannelAction.php b/app/src/Controller/Channel/CreateChannelAction.php index 21888f2..d6b5a8e 100644 --- a/app/src/Controller/Channel/CreateChannelAction.php +++ b/app/src/Controller/Channel/CreateChannelAction.php @@ -6,12 +6,16 @@ use Odan\Session\SessionInterface; use Psr\Log\LoggerInterface; use Slovocast\Controller\Controller; use Psr\Http\Message\ResponseInterface as Response; +use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface; +use Slovocast\Domain\Entity\Channel; +use Slovocast\Domain\Entity\User; class CreateChannelAction extends Controller { public function __construct( protected SessionInterface $session, protected LoggerInterface $logger, + protected ChannelRepositoryInterface $channelRepository ) { } public function handle(): Response @@ -24,5 +28,19 @@ class CreateChannelAction extends Controller $this->logger->error("Session User ID and Form User ID do no match."); return $this->render('channel/create.twig')->withStatus(400); } + + $formData['explicit'] = $formData['explicit'] === "yes" ? true : false; + + $user = User::fromArray($userData); + $channel = Channel::fromArray($formData); + + /** + * Should wrap this in a try/catch probably + */ + if (!$this->channelRepository->create($channel, $user)) { + return $this->render('channel/create.twig')->withStatus(500); + } + + $this->session->getFlash()->add("success", "Successfully created new channel."); } }