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(),
@@ -4,6 +4,7 @@ namespace App\Controller\Administrative\Document;
use App\Controller\Traits\ReturnUrlTrait;
use App\Entity\Upload;
use App\Event\DocumentConfirmedEvent;
use App\Event\DocumentRejectedEvent;
use App\Form\DocumentCheckType;
use App\Htmx\HxRedirectResponse;
@@ -46,16 +47,20 @@ class CheckController extends AbstractController
switch ($formData->getStatus()) {
case Upload::STATUS_CHECKED:
$this->confirmDocument($document, 'confirm_contract', Upload::STATUS_CHECKED, $formData);
// Contract confirmed: Update staffing status of related assignment
$document->getDisposition()->getAssignment()->updateStaffingStatus();
$this->entityManager->flush();
$this->eventDispatcher->dispatch(
new DocumentConfirmedEvent($document),
DocumentConfirmedEvent::NAME
);
break;
case Upload::STATUS_PAID:
$this->confirmDocument($document, 'confirm_invoice', Upload::STATUS_PAID, $formData);
break;
case Upload::STATUS_REJECTED:
$this->rejectDocument($document, $formData->getComment());
$this->eventDispatcher->dispatch(new DocumentRejectedEvent($formData), DocumentRejectedEvent::NAME);
$this->eventDispatcher->dispatch(
new DocumentRejectedEvent($formData),
DocumentRejectedEvent::NAME
);
break;
default:
$document
@@ -5,6 +5,7 @@ namespace App\Controller\Teamer\Application;
use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\User;
use App\Event\ApplicationCreatedEvent;
use App\Form\TeamerApplicationType;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
@@ -13,11 +14,13 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class CreateController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly LoggerInterface $logger
) {
}
@@ -39,9 +42,10 @@ class CreateController extends AbstractController
$this->entityManager->persist($application);
$this->entityManager->flush();
// Update staffing status of related assignment
$assignment->updateStaffingStatus();
$this->entityManager->flush();
$this->eventDispatcher->dispatch(
new ApplicationCreatedEvent($application),
ApplicationCreatedEvent::NAME
);
$this->addFlash('success', 'Deine Bewerbung wurde entgegengenommen');
$this->logger->info('Create application', [
@@ -5,6 +5,7 @@ namespace App\Controller\Teamer\Application;
use App\Controller\Traits\ReturnUrlTrait;
use App\Entity\Application;
use App\Entity\User;
use App\Event\ApplicationDeletedEvent;
use App\Htmx\HxRedirectResponse;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
@@ -13,6 +14,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class WithdrawController extends AbstractController
{
@@ -20,6 +22,7 @@ class WithdrawController extends AbstractController
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly LoggerInterface $logger
) {
}
@@ -37,9 +40,10 @@ class WithdrawController extends AbstractController
$this->entityManager->remove($application);
$this->entityManager->flush();
// Update staffing status of related assignment
$assignment->updateStaffingStatus();
$this->entityManager->flush();
$this->eventDispatcher->dispatch(
new ApplicationDeletedEvent($application),
ApplicationDeletedEvent::NAME
);
$this->logger->info('Withdraw application', [
'teamer_id' => $teamer->getId(),