feat: decouple logic using events
This commit is contained in:
@@ -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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user