feat: replace edit participant facade with context factory

This commit is contained in:
Björn Fromme
2026-04-11 18:28:32 +02:00
parent 95d50e9833
commit f903f17ebd
7 changed files with 169 additions and 190 deletions
@@ -4,11 +4,15 @@ declare(strict_types=1);
namespace App\Controller\Booking\Edit;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\Notification;
use App\Entity\User;
use App\Form\BookingParticipantType;
use App\Form\Model\BookingDto;
use App\Htmx\HxTrait;
use App\Service\BookingEditParticipantFormService;
use App\Service\BookingEditDataLoaderService;
use App\Service\BookingEditDraftService;
use App\Service\BookingEditParticipantContextFactory;
use App\Service\BookingSessionService;
use App\Service\ParticipantFormSupportService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -25,9 +29,11 @@ class ParticipantController extends AbstractController
use HxTrait;
public function __construct(
private readonly ParticipantFormSupportService $participantFormSupportService,
private readonly BookingEditParticipantFormService $participantFormService,
private readonly BookingEditDataLoaderService $dataLoader,
private readonly BookingEditDraftService $draftService,
private readonly BookingEditParticipantContextFactory $participantContextFactory,
private readonly BookingSessionService $bookingSessionService,
private readonly ParticipantFormSupportService $participantFormSupportService,
) {
}
@@ -45,7 +51,7 @@ class ParticipantController extends AbstractController
/** @var User $user */
$user = $this->getUser();
$bookingDto = $this->participantFormService->loadBookingDto($request);
$bookingDto = $this->bookingSessionService->getBookingDto($request, BookingDto::MODE_EDIT);
if (null === $bookingDto) {
$this->addFlash('error', 'Sitzung abgelaufen. Bitte neu laden.');
@@ -55,20 +61,20 @@ class ParticipantController extends AbstractController
$this->participantFormSupportService->ensureParticipantExists($bookingDto, $index);
$bookingData = $this->participantFormService->fetchBookingData($id, $user);
$bookingData = $this->dataLoader->fetchBookingData($id, $user);
if (null === $bookingData || $bookingData instanceof Notification) {
$this->addFlash('error', 'Buchungsdaten nicht (mehr) verfügbar');
return $this->redirectToRoute('app_bookings');
}
if ($this->participantFormService->isParticipantCanceled($bookingData, $index)) {
if ($this->isParticipantCanceled($bookingData, $index)) {
$this->addFlash('warning', 'Stornierte Teilnehmer können nicht bearbeitet werden');
return $this->redirectToRoute('app_booking_edit', ['id' => $id]);
}
$this->participantFormService->enrichTravelData($bookingDto);
$this->participantContextFactory->prepareBookingDto($bookingDto);
$wrapper = $this->participantFormSupportService->createParticipantEditDto($bookingDto, $index);
@@ -83,23 +89,22 @@ class ParticipantController extends AbstractController
$notifications = $this->participantFormSupportService->collectAndClearNotifications($bookingDto);
if ($form->isSubmitted() && $form->isValid()) {
$this->participantFormService->saveBookingDto($request, $bookingDto);
$this->participantFormService->saveDraft($user, $id, $bookingDto);
$this->bookingSessionService->saveBookingDto($request, $bookingDto, BookingDto::MODE_EDIT);
$this->draftService->saveDraft($user, $id, $bookingDto);
$this->addNotificationsAsFlashMessages($notifications);
return $this->redirectToRoute('app_booking_edit', ['id' => $id]);
}
$summaryData = $this->participantFormService->getSummaryData($bookingDto);
$mutableData = $this->participantFormService->getMutableData($bookingData->dateId);
$context = $this->participantContextFactory->create($bookingDto, $bookingData);
return $this->render('booking/edit/participant.html', [
'form' => $form->createView(),
'participantIndex' => $index,
'bookingDto' => $bookingDto,
'bookingData' => $bookingData,
'mutableData' => $mutableData,
'summaryData' => $summaryData,
'bookingDto' => $context->bookingDto,
'bookingData' => $context->bookingData,
'mutableData' => $context->mutableData,
'summaryData' => $context->summaryData,
'refreshRouteName' => 'app_booking_edit_participant_refresh',
'refreshRouteParams' => ['id' => $id, 'index' => $index],
'cancelRouteName' => 'app_booking_edit',
@@ -122,19 +127,16 @@ class ParticipantController extends AbstractController
/** @var User $user */
$user = $this->getUser();
$bookingDto = $this->participantFormService->loadBookingDto($request);
$bookingDto = $this->bookingSessionService->getBookingDto($request, BookingDto::MODE_EDIT);
if (null === $bookingDto) {
return new Response('Session expired. Please reload page.', Response::HTTP_BAD_REQUEST);
}
$this->participantFormSupportService->ensureParticipantExists($bookingDto, $index);
$this->participantFormService->enrichTravelData($bookingDto);
$this->participantContextFactory->prepareBookingDto($bookingDto);
$bookingData = $this->participantFormService->fetchBookingData($id, $user);
$mutableData = null !== $bookingData && !($bookingData instanceof Notification)
? $this->participantFormService->getMutableData($bookingData->dateId)
: null;
$bookingData = $this->dataLoader->fetchBookingData($id, $user);
$wrapper = $this->participantFormSupportService->createParticipantEditDto($bookingDto, $index);
@@ -147,7 +149,9 @@ class ParticipantController extends AbstractController
$form->handleRequest($request);
$notifications = $this->participantFormSupportService->collectAndClearNotifications($bookingDto);
$summaryData = $this->participantFormService->getSummaryData($bookingDto);
$context = null !== $bookingData && !($bookingData instanceof Notification)
? $this->participantContextFactory->create($bookingDto, $bookingData)
: null;
$response = $this->htmxOobResponse(
'booking/_participant_form.html.twig',
@@ -157,8 +161,8 @@ class ParticipantController extends AbstractController
'participantIndex' => $index,
'bookingDto' => $bookingDto,
'bookingData' => $bookingData,
'mutableData' => $mutableData,
'summaryData' => $summaryData,
'mutableData' => $context?->mutableData,
'summaryData' => $context?->summaryData,
'refreshRouteName' => 'app_booking_edit_participant_refresh',
'refreshRouteParams' => ['id' => $id, 'index' => $index],
'cancelRouteName' => 'app_booking_edit',
@@ -184,4 +188,9 @@ class ParticipantController extends AbstractController
$this->addFlash($notification['type'], $notification['message']);
}
}
private function isParticipantCanceled(Booking $bookingData, int $index): bool
{
return 'S' === ($bookingData->participantsStatus[$index] ?? null);
}
}