Flesh out the add channel handler.

This commit is contained in:
Dave Smith-Hayes 2024-12-14 09:32:00 -05:00
parent bc9997a817
commit b9db0d97dc

View File

@ -6,12 +6,16 @@ use Odan\Session\SessionInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Slovocast\Controller\Controller; use Slovocast\Controller\Controller;
use Psr\Http\Message\ResponseInterface as Response; 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 class CreateChannelAction extends Controller
{ {
public function __construct( public function __construct(
protected SessionInterface $session, protected SessionInterface $session,
protected LoggerInterface $logger, protected LoggerInterface $logger,
protected ChannelRepositoryInterface $channelRepository
) { } ) { }
public function handle(): Response 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."); $this->logger->error("Session User ID and Form User ID do no match.");
return $this->render('channel/create.twig')->withStatus(400); 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.");
} }
} }