feat: decouple logic using events

This commit is contained in:
Björn Fromme committed 2024-07-18 11:09:49 +02:00
1 parent 174ae5e5e3
commit 3a77697d9d
13 files changed
+190 -27

No files matched your search

@@ -3,17 +3,20 @@
namespace App\Controller\Admin\Application;
use App\Entity\Application;
use App\Event\ApplicationDeletedEvent;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class DeleteController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly LoggerInterface $logger
) {
}
@@ -26,10 +29,13 @@ class DeleteController extends AbstractController
$this->entityManager->remove($application);
$this->entityManager->flush();
$application->getAssignment()->updateStaffingStatus();
$this->entityManager->flush();
$this->eventDispatcher->dispatch(
new ApplicationDeletedEvent($application),
ApplicationDeletedEvent::NAME
);
$this->addFlash('success', 'Die Bewerbung wurde gelöscht');
$this->logger->info('Delete application', [
'destination' => (string) $application->getAssignment()->getDestination(),
'teamer' => (string) $application->getTeamer(),
@@ -39,4 +45,4 @@ class DeleteController extends AbstractController
'uuid' => $application->getAssignment()->getUuid(),
]);
}
}
}
@@ -39,11 +39,10 @@ class DisposeController extends AbstractController
$this->entityManager->remove($application);
$this->entityManager->flush();
// Update staffing status of related assignment
$disposition->getAssignment()->updateStaffingStatus();
$this->entityManager->flush();
$this->eventDispatcher->dispatch(new DispositionCreatedEvent($disposition), DispositionCreatedEvent::NAME);
$this->eventDispatcher->dispatch(
new DispositionCreatedEvent($disposition),
DispositionCreatedEvent::NAME
);
$this->addFlash('success', 'Teamer:in wurde eingeteilt');
$this->logger->info('Create disposition', [
@@ -36,7 +36,6 @@ class StatusController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->eventDispatcher->dispatch(new ApplicationStatusEvent($statusDto), ApplicationStatusEvent::NAME);
$application
->setStatus($statusDto->getStatus())
->setComment($statusDto->getComment())
@@ -44,6 +43,11 @@ class StatusController extends AbstractController
;
$this->entityManager->flush();
$this->eventDispatcher->dispatch(
new ApplicationStatusEvent($statusDto),
ApplicationStatusEvent::NAME
);
$this->addFlash('success', 'Der Status der Bewerbung wurde aktualisiert');
$this->logger->info('Update application status', [
'application_id' => $application->getId(),
@@ -43,8 +43,6 @@ class DeleteController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->eventDispatcher->dispatch(new DispositionDeletedEvent($disposition), DispositionDeletedEvent::NAME);
$this->addFlash('success', 'Die Einteilung wurde gelöscht');
$this->logger->info('Delete disposition', [
'disposition_id' => $disposition->getId(),
@@ -54,9 +52,10 @@ class DeleteController extends AbstractController
$this->entityManager->remove($disposition);
$this->entityManager->flush();
// Update staffing status of related assignment
$disposition->getAssignment()->updateStaffingStatus();
$this->entityManager->flush();
$this->eventDispatcher->dispatch(
new DispositionDeletedEvent($disposition),
DispositionDeletedEvent::NAME
);
return new HxRedirectResponse($this->generateUrl('app_administrative_assignment_detail', [
'uuid' => $disposition->getAssignment()->getUuid(),