Add some documentation to code, reformat things.

This commit is contained in:
Dave Smith-Hayes 2024-12-16 03:39:21 +00:00
parent 3824522ff5
commit b8034b6a0a
5 changed files with 14 additions and 17 deletions

View File

@ -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? */
try {
$user = $this->userInterface->get($userData['id']);
$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

@ -2,7 +2,6 @@
namespace Slovocast\Controller\Channel;
use Odan\Session\SessionInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Slovocast\Controller\Controller;

View File

@ -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
*/

View File

@ -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 ]);
}
}

View File

@ -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);
}
}