-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor controllers using ADR pattern (#272)
This will: - title - change router and security annotations to attributes
- Loading branch information
Showing
62 changed files
with
1,211 additions
and
865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Dlc; | ||
|
||
use App\Form\DataTransformerRegistry; | ||
use App\Form\Dlc\DlcFormType; | ||
use App\Form\Dlc\Dto\DlcFormDto; | ||
use App\Security\Enum\PermissionsEnum; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class CreateAction extends AbstractController | ||
{ | ||
public function __construct( | ||
private EntityManagerInterface $entityManager, | ||
private DataTransformerRegistry $dataTransformerRegistry | ||
) { | ||
} | ||
|
||
#[Route('/dlc/create', name: 'app_dlc_create')] | ||
#[IsGranted(PermissionsEnum::DLC_CREATE)] | ||
public function __invoke(Request $request): Response | ||
{ | ||
$dlcFormDto = new DlcFormDto(); | ||
$form = $this->createForm(DlcFormType::class, $dlcFormDto); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$dlc = $this->dataTransformerRegistry->transformToEntity($dlcFormDto); | ||
|
||
$this->entityManager->persist($dlc); | ||
$this->entityManager->flush(); | ||
|
||
return $this->redirectToRoute('app_dlc_list'); | ||
} | ||
|
||
return $this->render('dlc/form.html.twig', [ | ||
'form' => $form->createView(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Dlc; | ||
|
||
use App\Entity\Dlc\Dlc; | ||
use App\Security\Enum\PermissionsEnum; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class DeleteAction extends AbstractController | ||
{ | ||
public function __construct( | ||
private EntityManagerInterface $entityManager, | ||
) { | ||
} | ||
|
||
#[Route('/dlc/{id}/delete', name: 'app_dlc_delete')] | ||
#[IsGranted(PermissionsEnum::DLC_DELETE, 'dlc')] | ||
public function __invoke(Dlc $dlc): Response | ||
{ | ||
$this->entityManager->remove($dlc); | ||
$this->entityManager->flush(); | ||
|
||
return $this->redirectToRoute('app_dlc_list'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Dlc; | ||
|
||
use App\Repository\Dlc\DlcRepository; | ||
use App\Security\Enum\PermissionsEnum; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class ListAction extends AbstractController | ||
{ | ||
public function __construct( | ||
private DlcRepository $dlcRepository | ||
) { | ||
} | ||
|
||
#[Route('/dlc/list', name: 'app_dlc_list')] | ||
#[IsGranted(PermissionsEnum::DLC_LIST)] | ||
public function __invoke(): Response | ||
{ | ||
$dlcs = $this->dlcRepository->findBy([], ['name' => 'ASC']); | ||
|
||
return $this->render('dlc/list.html.twig', [ | ||
'dlcs' => $dlcs, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Dlc; | ||
|
||
use App\Entity\Dlc\Dlc; | ||
use App\Form\DataTransformerRegistry; | ||
use App\Form\Dlc\DlcFormType; | ||
use App\Form\Dlc\Dto\DlcFormDto; | ||
use App\Security\Enum\PermissionsEnum; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class UpdateAction extends AbstractController | ||
{ | ||
public function __construct( | ||
private EntityManagerInterface $entityManager, | ||
private DataTransformerRegistry $dataTransformerRegistry | ||
) { | ||
} | ||
|
||
#[Route('/dlc/{id}/update', name: 'app_dlc_update')] | ||
#[IsGranted(PermissionsEnum::DLC_UPDATE, 'dlc')] | ||
public function __invoke(Request $request, Dlc $dlc): Response | ||
{ | ||
$dlcFormDto = $this->dataTransformerRegistry->transformFromEntity(new DlcFormDto(), $dlc); | ||
$form = $this->createForm(DlcFormType::class, $dlcFormDto); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$this->dataTransformerRegistry->transformToEntity($dlcFormDto, $dlc); | ||
|
||
$this->entityManager->flush(); | ||
|
||
return $this->redirectToRoute('app_dlc_list'); | ||
} | ||
|
||
return $this->render('dlc/form.html.twig', [ | ||
'form' => $form->createView(), | ||
]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Home; | ||
|
||
use App\Service\Mission\MissionClientInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class IndexAction extends AbstractController | ||
{ | ||
public function __construct( | ||
private MissionClientInterface $missionClient, | ||
private LoggerInterface $logger | ||
) { | ||
} | ||
|
||
#[Route('/', name: 'app_home_index')] | ||
public function __invoke(): Response | ||
{ | ||
try { | ||
$nearestMission = $this->missionClient->getNextUpcomingMission(); | ||
} catch (\Exception $ex) { | ||
$this->logger->warning('Could not fetch nearest mission', ['ex' => $ex]); | ||
$nearestMission = null; | ||
} | ||
|
||
return $this->render('home/index/index.html.twig', [ | ||
'nearestMission' => $nearestMission, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Home; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class JoinUsAction extends AbstractController | ||
{ | ||
#[Route('/join-us', name: 'app_home_join_us')] | ||
public function __invoke(): Response | ||
{ | ||
return $this->render('home/join_us/join_us.html.twig'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.