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
@@ -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', [