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', [
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user