diff --git a/app/src/Controller/Channel/CreateChannelAction.php b/app/src/Controller/Channel/CreateChannelAction.php index 20db8ad..8f02f40 100644 --- a/app/src/Controller/Channel/CreateChannelAction.php +++ b/app/src/Controller/Channel/CreateChannelAction.php @@ -32,20 +32,18 @@ class CreateChannelAction extends Controller $formData['explicit'] = $formData['explicit'] === "yes" ? true : false; - /** Do we need to get the user object from MySQL here? */ - $user = $this->userInterface->get($userData['id']); - $channel = Channel::fromArray($formData); - - /** - * Should wrap this in a try/catch probably - */ try { + $user = $this->userInterface->get($userData['id']); + $channel = Channel::fromArray($formData); + $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); } } diff --git a/app/src/Controller/Channel/CreateChannelPage.php b/app/src/Controller/Channel/CreateChannelPage.php index 393f8f2..037124e 100644 --- a/app/src/Controller/Channel/CreateChannelPage.php +++ b/app/src/Controller/Channel/CreateChannelPage.php @@ -2,7 +2,6 @@ namespace Slovocast\Controller\Channel; -use Odan\Session\SessionInterface; use Psr\Http\Message\ResponseInterface as Response; use Slovocast\Controller\Controller; diff --git a/app/src/Controller/Controller.php b/app/src/Controller/Controller.php index 9db6937..cb5b07f 100644 --- a/app/src/Controller/Controller.php +++ b/app/src/Controller/Controller.php @@ -16,7 +16,10 @@ abstract class Controller protected Twig $view; /** - * Make the Class invokable and pass it into a route as its handler. + * Make the Class invokable and pass it into a route as its handler. Here + * we can bootstrap some commonly used properties for handling Requests, + * such as the Request and Response themselves, the view, the route + * context and more. * * @param Request $request * @param Response $response @@ -38,7 +41,7 @@ abstract class Controller } /** - * Implement this method for handling the request. + * Implement this method for actually handling the request. * * @return Response */ diff --git a/app/src/Controller/DashboardPage.php b/app/src/Controller/DashboardPage.php index 6019a65..c802d1b 100644 --- a/app/src/Controller/DashboardPage.php +++ b/app/src/Controller/DashboardPage.php @@ -3,7 +3,6 @@ namespace Slovocast\Controller; use Odan\Session\SessionInterface; -use Slovocast\Domain\Entity\User; use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface; use Slovocast\Domain\Repository\User\UserRepositoryInterface; use Psr\Http\Message\ResponseInterface as Response; @@ -18,11 +17,9 @@ class DashboardPage extends Controller public function handle(): Response { - // get the user details - // get the channels $userData = $this->session->get("user"); - $user = User::fromArray($userData); - $channels = $this->channelRepository->getFromUser($user); - return $this->render('dashboard.twig', [ 'channel' => $channels ]); + $user = $this->userRepository->get($userData['id']); + $channel = $this->channelRepository->getFromUser($user); + return $this->render('dashboard.twig', [ 'channel' => $channel ]); } } diff --git a/app/src/Controller/User/LogoutUserAction.php b/app/src/Controller/User/LogoutUserAction.php index f2b7487..7f2f1ad 100644 --- a/app/src/Controller/User/LogoutUserAction.php +++ b/app/src/Controller/User/LogoutUserAction.php @@ -24,7 +24,7 @@ class LogoutUserAction extends Controller $this->session->delete('user'); } - $this->session->getFlash()->add('notice', "Successfully logged out."); + $this->session->getFlash()->add("notice", "Successfully logged out."); return $this->redirect('/', 302); } }