Compare commits

...

2 Commits

2 changed files with 27 additions and 1 deletions

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,23 @@ 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
*/
try {
$channel = $this->channelRepository->create($channel, $user);
$this->session->getFlash()->add("success", "Created new channel.");
return $this->redirect("/dashboard", 302);
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
$this->session->getFlash()->add("error", "Unable to create new channel.");
return $this->render('channe/create.twig')->withStatus(500);
}
} }
} }

View File

@ -3,6 +3,7 @@
namespace Slovocast\Controller; namespace Slovocast\Controller;
use Odan\Session\SessionInterface; use Odan\Session\SessionInterface;
use Slovocast\Domain\Entity\User;
use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface; use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface;
use Slovocast\Domain\Repository\User\UserRepositoryInterface; use Slovocast\Domain\Repository\User\UserRepositoryInterface;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
@ -19,6 +20,9 @@ class DashboardPage extends Controller
{ {
// get the user details // get the user details
// get the channels // get the channels
return $this->render('dashboard.twig'); $userData = $this->session->get("user");
$user = User::fromArray($userData);
$channels = $this->channelRepository->getFromUser($user);
return $this->render('dashboard.twig', [ 'channel' => $channels ]);
} }
} }