From d42da03a8f2557eb84111fcf2ff0cbfb4d0b5100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 18 Oct 2023 19:04:06 +0200 Subject: [PATCH] WIP: Refactor application rejecting process --- .../Admin/Application/IndexController.php | 2 +- .../Admin/Application/RejectController.php | 7 ++++ src/Event/ApplicationRejectedEvent.php | 31 +++++++++++++++++ src/Model/ApplicationCheckDto.php | 33 +++++++++++++++++++ src/Repository/ApplicationRepository.php | 4 ++- 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/Event/ApplicationRejectedEvent.php create mode 100644 src/Model/ApplicationCheckDto.php diff --git a/src/Controller/Admin/Application/IndexController.php b/src/Controller/Admin/Application/IndexController.php index a95f1ee..e521ed7 100644 --- a/src/Controller/Admin/Application/IndexController.php +++ b/src/Controller/Admin/Application/IndexController.php @@ -24,7 +24,7 @@ class IndexController extends AbstractController { $query = $this ->applicationRepository - ->getListQuery() + ->getPendingQuery() ; $pagination = $this->paginator->paginate( diff --git a/src/Controller/Admin/Application/RejectController.php b/src/Controller/Admin/Application/RejectController.php index 4af7454..5062c7f 100644 --- a/src/Controller/Admin/Application/RejectController.php +++ b/src/Controller/Admin/Application/RejectController.php @@ -3,17 +3,21 @@ namespace App\Controller\Admin\Application; use App\Entity\Application; +use App\Event\ApplicationRejectedEvent; +use App\Model\ApplicationCheckDto; use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class RejectController extends AbstractController { public function __construct( private readonly EntityManagerInterface $entityManager, + private readonly EventDispatcherInterface $eventDispatcher, private readonly LoggerInterface $logger ) { } @@ -23,6 +27,9 @@ class RejectController extends AbstractController #[IsGranted('REJECT', subject: 'application')] public function index(Application $application): Response { + $applicationCheckDto = new ApplicationCheckDto($application); + $this->eventDispatcher->dispatch(new ApplicationRejectedEvent($applicationCheckDto), ApplicationRejectedEvent::NAME); + $application->setStatus(Application::STATUS_REJECTED); $this->entityManager->flush(); diff --git a/src/Event/ApplicationRejectedEvent.php b/src/Event/ApplicationRejectedEvent.php new file mode 100644 index 0000000..a701e94 --- /dev/null +++ b/src/Event/ApplicationRejectedEvent.php @@ -0,0 +1,31 @@ +application = $applicationCheckDto->getApplication(); + $this->comment = $applicationCheckDto->getComment(); + } + + public function getApplication(): Application + { + return $this->application; + } + + public function getComment(): ?string + { + return $this->comment; + } +} \ No newline at end of file diff --git a/src/Model/ApplicationCheckDto.php b/src/Model/ApplicationCheckDto.php new file mode 100644 index 0000000..fa0173e --- /dev/null +++ b/src/Model/ApplicationCheckDto.php @@ -0,0 +1,33 @@ +application = $application; + } + + public function getApplication(): Application + { + return $this->application; + } + + public function getComment(): ?string + { + return $this->comment; + } + + public function setComment(?string $comment): static + { + $this->comment = $comment; + + return $this; + } +} \ No newline at end of file diff --git a/src/Repository/ApplicationRepository.php b/src/Repository/ApplicationRepository.php index 2841f50..d47e372 100644 --- a/src/Repository/ApplicationRepository.php +++ b/src/Repository/ApplicationRepository.php @@ -23,7 +23,7 @@ class ApplicationRepository extends ServiceEntityRepository parent::__construct($registry, Application::class); } - public function getListQuery(): Query + public function getPendingQuery(): Query { $qb = $this->createQueryBuilder('application'); @@ -33,6 +33,8 @@ class ApplicationRepository extends ServiceEntityRepository ->innerJoin('assignment.destination', 'destination') ->innerJoin('assignment.jobProfile', 'job_profile') ->innerJoin('application.teamer', 'teamer') + ->where($qb->expr()->neq('application.status', ':status')) + ->setParameter('status', Application::STATUS_REJECTED) ->getQuery() ; }