Add some documentation to code, reformat things.
This commit is contained in:
parent
3824522ff5
commit
b8034b6a0a
@ -32,20 +32,18 @@ class CreateChannelAction extends Controller
|
|||||||
|
|
||||||
$formData['explicit'] = $formData['explicit'] === "yes" ? true : false;
|
$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 {
|
try {
|
||||||
|
$user = $this->userInterface->get($userData['id']);
|
||||||
|
$channel = Channel::fromArray($formData);
|
||||||
|
|
||||||
$channel = $this->channelRepository->create($channel, $user);
|
$channel = $this->channelRepository->create($channel, $user);
|
||||||
$this->session->getFlash()->add("success", "Created new channel.");
|
$this->session->getFlash()->add("success", "Created new channel.");
|
||||||
|
|
||||||
return $this->redirect("/dashboard", 302);
|
return $this->redirect("/dashboard", 302);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->error($e->getMessage());
|
$this->logger->error($e->getMessage());
|
||||||
$this->session->getFlash()->add("error", "Unable to create new channel.");
|
$this->session->getFlash()->add("error", "Unable to create new channel.");
|
||||||
|
|
||||||
return $this->render('channe/create.twig')->withStatus(500);
|
return $this->render('channe/create.twig')->withStatus(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Slovocast\Controller\Channel;
|
namespace Slovocast\Controller\Channel;
|
||||||
|
|
||||||
use Odan\Session\SessionInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use Slovocast\Controller\Controller;
|
use Slovocast\Controller\Controller;
|
||||||
|
|
||||||
|
@ -16,7 +16,10 @@ abstract class Controller
|
|||||||
protected Twig $view;
|
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 Request $request
|
||||||
* @param Response $response
|
* @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
|
* @return Response
|
||||||
*/
|
*/
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
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;
|
||||||
@ -18,11 +17,9 @@ class DashboardPage extends Controller
|
|||||||
|
|
||||||
public function handle(): Response
|
public function handle(): Response
|
||||||
{
|
{
|
||||||
// get the user details
|
|
||||||
// get the channels
|
|
||||||
$userData = $this->session->get("user");
|
$userData = $this->session->get("user");
|
||||||
$user = User::fromArray($userData);
|
$user = $this->userRepository->get($userData['id']);
|
||||||
$channels = $this->channelRepository->getFromUser($user);
|
$channel = $this->channelRepository->getFromUser($user);
|
||||||
return $this->render('dashboard.twig', [ 'channel' => $channels ]);
|
return $this->render('dashboard.twig', [ 'channel' => $channel ]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class LogoutUserAction extends Controller
|
|||||||
$this->session->delete('user');
|
$this->session->delete('user');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->session->getFlash()->add('notice', "Successfully logged out.");
|
$this->session->getFlash()->add("notice", "Successfully logged out.");
|
||||||
return $this->redirect('/', 302);
|
return $this->redirect('/', 302);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user