Refactor Controller class

This commit is contained in:
2024-07-28 00:35:36 -04:00
parent e538b82bf5
commit e0d6563583

View File

@@ -14,24 +14,24 @@ use Twig\Environment;
class ConferenceController extends AbstractController class ConferenceController extends AbstractController
{ {
#[Route('/', name: 'homepage')] #[Route('/', name: 'homepage')]
public function index(Environment $twig, ConferenceRepository $conferenceRepository): Response public function index(ConferenceRepository $conferenceRepository): Response
{ {
return new Response($twig->render('conference/index.html.twig', [ return $this->render('conference/index.html.twig', [
'conferences' => $conferenceRepository->findAll(), 'conferences' => $conferenceRepository->findAll(),
])); ]);
} }
#[Route('/conference/{id}', name: 'conference')] #[Route('/conference/{id}', name: 'conference')]
public function show(Request $request, Environment $twig, Conference $conference, CommentRepository $commentRepository): Response public function show(Request $request, Conference $conference, CommentRepository $commentRepository): Response
{ {
$offset = max(0, $request->query->getInt('offset', 0)); $offset = max(0, $request->query->getInt('offset', 0));
$paginator = $commentRepository->getCommentPaginator($conference, $offset); $paginator = $commentRepository->getCommentPaginator($conference, $offset);
return new Response($twig->render('conference/show.html.twig', [ return $this->render('conference/show.html.twig', [
'conference' => $conference, 'conference' => $conference,
'comments' => $paginator, 'comments' => $paginator,
'previous' => $offset - CommentRepository::COMMENTS_PER_PAGE, 'previous' => $offset - CommentRepository::COMMENTS_PER_PAGE,
'next' => min(count($paginator), $offset + CommentRepository::COMMENTS_PER_PAGE) 'next' => min(count($paginator), $offset + CommentRepository::COMMENTS_PER_PAGE)
])); ]);
} }
} }