feat: decouple logic using events

This commit is contained in:
Björn Fromme
2024-07-18 11:09:49 +02:00
parent 174ae5e5e3
commit 3a77697d9d
13 changed files with 190 additions and 27 deletions
@@ -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(),
]);
}
}
}