Typed controller route

This commit is contained in:
Charles 2025-10-27 13:54:26 +01:00
parent 2418e43703
commit c54df8a327
1 changed files with 34 additions and 28 deletions

View File

@ -9,6 +9,7 @@ use App\Entity\User;
use App\Entity\UserOrganizatonApp; use App\Entity\UserOrganizatonApp;
use App\Entity\UsersOrganizations; use App\Entity\UsersOrganizations;
use App\Form\OrganizationForm; use App\Form\OrganizationForm;
use App\Repository\OrganizationsRepository;
use App\Service\ActionService; use App\Service\ActionService;
use App\Service\OrganizationsService; use App\Service\OrganizationsService;
use App\Service\UserOrganizationService; use App\Service\UserOrganizationService;
@ -31,7 +32,10 @@ class OrganizationController extends AbstractController
public function __construct(private readonly EntityManagerInterface $entityManager, public function __construct(private readonly EntityManagerInterface $entityManager,
private readonly UserService $userService, private readonly UserService $userService,
private readonly OrganizationsService $organizationsService, private readonly ActionService $actionService, private readonly UserOrganizationService $userOrganizationService) private readonly OrganizationsService $organizationsService,
private readonly ActionService $actionService,
private readonly UserOrganizationService $userOrganizationService,
private readonly OrganizationsRepository $organizationsRepository,)
{ {
} }
@ -42,7 +46,7 @@ class OrganizationController extends AbstractController
$user = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $user = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
if ($this->isGranted("ROLE_SUPER_ADMIN")) { if ($this->isGranted("ROLE_SUPER_ADMIN")) {
$organizations = $this->entityManager->getRepository(Organizations::class)->findBy(['isDeleted' => false]); $organizations = $this->organizationsRepository->findBy(['isDeleted' => false]);
} else { } else {
@ -67,7 +71,7 @@ class OrganizationController extends AbstractController
'id' => $org->getId(), 'id' => $org->getId(),
'name' => $org->getName(), 'name' => $org->getName(),
'email' => $org->getEmail(), 'email' => $org->getEmail(),
'logoUrl' => $org->getLogoUrl() ? $org->getLogoUrl() : null, // or prepend base URL if needed 'logoUrl' => $org->getLogoUrl() ? $org->getLogoUrl() : null,
'active' => $org->isActive(), 'active' => $org->isActive(),
'showUrl' => $this->generateUrl('organization_show', ['id' => $org->getId()]), 'showUrl' => $this->generateUrl('organization_show', ['id' => $org->getId()]),
]; ];
@ -89,7 +93,7 @@ class OrganizationController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$logoFile = $form->get('logoUrl')->getData(); $logoFile = $form->get('logoUrl')->getData();
if ($logoFile) { if ($logoFile) {
$this->organizationService->handleLogo($organization, $logoFile); $this->organizationsService->handleLogo($organization, $logoFile);
} }
try { try {
$this->entityManager->persist($organization); $this->entityManager->persist($organization);
@ -116,7 +120,7 @@ class OrganizationController extends AbstractController
{ {
$this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->denyAccessUnlessGranted('ROLE_ADMIN');
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
$organization = $this->entityManager->getRepository(Organizations::class)->find($id); $organization = $this->organizationsRepository->find($id);
if (!$organization) { if (!$organization) {
$this->addFlash('error', self::NOT_FOUND); $this->addFlash('error', self::NOT_FOUND);
return $this->redirectToRoute('organization_index'); return $this->redirectToRoute('organization_index');
@ -162,7 +166,7 @@ class OrganizationController extends AbstractController
public function view($id): Response public function view($id): Response
{ {
$this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->denyAccessUnlessGranted('ROLE_ADMIN');
$organization = $this->entityManager->getRepository(Organizations::class)->find($id); $organization = $this->organizationsRepository->find($id);
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
if (!$organization) { if (!$organization) {
$this->addFlash('error', self::NOT_FOUND); $this->addFlash('error', self::NOT_FOUND);
@ -212,7 +216,7 @@ class OrganizationController extends AbstractController
{ {
$this->denyAccessUnlessGranted("ROLE_ADMIN"); $this->denyAccessUnlessGranted("ROLE_ADMIN");
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
$organization = $this->entityManager->getRepository(Organizations::class)->find($id); $organization = $this->organizationsRepository->find($id);
if (!$organization) { if (!$organization) {
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
@ -227,10 +231,11 @@ class OrganizationController extends AbstractController
} }
#[Route(path: '/deactivate/{id}', name: 'deactivate', methods: ['POST'])] #[Route(path: '/deactivate/{id}', name: 'deactivate', methods: ['POST'])]
public function deactivate($id): Response{ public function deactivate($id): Response
{
$this->denyAccessUnlessGranted("ROLE_SUPER_ADMIN"); $this->denyAccessUnlessGranted("ROLE_SUPER_ADMIN");
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
$organization = $this->entityManager->getRepository(Organizations::class)->find($id); $organization = $this->organizationsRepository->find($id);
if (!$organization) { if (!$organization) {
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
@ -242,10 +247,11 @@ class OrganizationController extends AbstractController
} }
#[Route(path: '/activate/{id}', name: 'activate', methods: ['POST'])] #[Route(path: '/activate/{id}', name: 'activate', methods: ['POST'])]
public function activate($id): Response{ public function activate($id): Response
{
$this->denyAccessUnlessGranted("ROLE_SUPER_ADMIN"); $this->denyAccessUnlessGranted("ROLE_SUPER_ADMIN");
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
$organization = $this->entityManager->getRepository(Organizations::class)->find($id); $organization = $this->organizationsRepository->find($id);
if (!$organization) { if (!$organization) {
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
@ -271,7 +277,7 @@ class OrganizationController extends AbstractController
$user = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $user = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
$qb = $this->entityManager->getRepository(Organizations::class)->createQueryBuilder('o') $qb = $this->organizationsRepository->createQueryBuilder('o')
->where('o.isDeleted = :del')->setParameter('del', false); ->where('o.isDeleted = :del')->setParameter('del', false);
// // Example: apply filters (basic equals/like) // // Example: apply filters (basic equals/like)