Open
mtarld wants to merge 1 commit into main from team/view-team-page
feat: ship the /team page with the in-memory roster
…/Controller/ViewTeam.php
12
1
…/Controller/ViewTeam.php
src/Team/Infrastructure/Controller/ViewTeam.php
@@ -10,7 +10,7 @@ final readonly class ViewTeam10
added: use App\Team\Infrastructure\Repository\InMemoryMemberRepository;11
use Symfony\Component\HttpFoundation\Exception\NotFoundHttpException;12
use Symfony\Component\HttpFoundation\Request;13
use Symfony\Component\HttpFoundation\Response;14
use Symfony\Component\HttpKernel\Attribute\AsController;15
use Symfony\Component\Routing\Attribute\Route;16
added: use Twig\Environment;
Thread · 2 comments
Could we alias this import to Twig to make it a little more understandable?
What about extending AbstractController and use the render() method?
17
18
#[AsController]19
final readonly class ViewTeam20
{21
public function __construct(22
added: private Environment $twig,23
added: private InMemoryMemberRepository $memberRepository,
Thread · 3 comments
This should depend on an interface instead to avoid coupling to implementation details
👍 That Repository ((opens in a new tab)) contract belongs to the Domain layer IMHO.
To target a specific implementation, you can use the Autowire attribute ((opens in a new tab)).
24
) {25
}26
27
#[Route(name: 'app_team', path: '/team')]28
public function __invoke(Request $request): Response29
{30
removed: return new Response();30
added: if ('GET' !== $request->getMethod()) {31
added: throw new NotFoundHttpException();
Thread · 2 comments
While it works, #[Route(methods: ['GET'])] is a better way to achieve this.
Indeed, better leverage Symfony Routing capabilities so you can focus on the business logic.
32
added: }33
added: 34
added: return new Response($this->twig->render('pages/team/index.html.twig', [35
added: 'members' => $this->memberRepository->findAll(),
Thread · 2 comments
Should it return a paginated result instead?
AFAIK, baksla.sh isn't gonna have enough members to need pagination anytime soon 😉
36
added: ]));37
added:
Thread · 1 comment
Extra blank line 👀
38
}39
}