feat: decouple logic using events
This commit is contained in:
@@ -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', [
|
||||
|
||||
Reference in New Issue
Block a user