WIP: Refactor application rejecting process

This commit is contained in:
Björn Fromme
2023-10-18 19:04:06 +02:00
parent 40d4edbf96
commit d42da03a8f
5 changed files with 75 additions and 2 deletions
@@ -24,7 +24,7 @@ class IndexController extends AbstractController
{
$query = $this
->applicationRepository
->getListQuery()
->getPendingQuery()
;
$pagination = $this->paginator->paginate(
@@ -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();
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Event;
use App\Entity\Application;
use App\Model\ApplicationCheckDto;
use Symfony\Contracts\EventDispatcher\Event;
class ApplicationRejectedEvent extends Event
{
public const NAME = 'application.rejected';
private Application $application;
private ?string $comment;
public function __construct(ApplicationCheckDto $applicationCheckDto)
{
$this->application = $applicationCheckDto->getApplication();
$this->comment = $applicationCheckDto->getComment();
}
public function getApplication(): Application
{
return $this->application;
}
public function getComment(): ?string
{
return $this->comment;
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Model;
use App\Entity\Application;
class ApplicationCheckDto
{
private Application $application;
private ?string $comment = null;
public function __construct(Application $application)
{
$this->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;
}
}
+3 -1
View File
@@ -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()
;
}