chore: further cleanup and refactor
This commit is contained in:
@@ -5,11 +5,11 @@ declare(strict_types=1);
|
||||
namespace App\Controller\Booking\Edit;
|
||||
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Controller\Booking\Traits\BookingExceptionHandlerTrait;
|
||||
use App\Entity\User;
|
||||
use App\Exception\TravelNotFoundException;
|
||||
use App\Form\BookingEditType;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Model\BookingEditSubmissionResult;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Service\BookingChangeTracker;
|
||||
use App\Service\BookingEditContextFactory;
|
||||
@@ -34,7 +34,6 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
*/
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
use BookingExceptionHandlerTrait;
|
||||
use HxTrait;
|
||||
|
||||
public function __construct(
|
||||
@@ -43,7 +42,7 @@ class IndexController extends AbstractController
|
||||
private readonly BookingSessionManager $bookingSessionService,
|
||||
private readonly BookingChangeTracker $fingerprintService,
|
||||
private readonly BookingEditContextFactory $editContextFactory,
|
||||
private readonly BookingEditSubmitter $submitService,
|
||||
private readonly BookingEditSubmitter $formSubmitter,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -53,32 +52,32 @@ class IndexController extends AbstractController
|
||||
* Clears any existing session data and API cache to ensure fresh data
|
||||
* is loaded, then redirects to the main edit page.
|
||||
*/
|
||||
#[Route('/bookings/{id}/edit/start', name: 'app_booking_edit_start', requirements: ['id' => '\d+'])]
|
||||
#[Route('/bookings/{bookingId}/edit/start', name: 'app_booking_edit_start', requirements: ['bookingId' => '\d+'])]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function start(int $id, Request $request): Response
|
||||
public function start(int $bookingId, Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
$this->bookingSessionService->clearBookingDto($request, BookingDto::MODE_EDIT);
|
||||
$this->dataLoader->invalidateBookingCache($id, $user);
|
||||
$this->dataLoader->invalidateBookingCache($bookingId, $user);
|
||||
|
||||
return $this->redirectToRoute('app_booking_edit', ['id' => $id]);
|
||||
return $this->redirectToRoute('app_booking_edit', ['bookingId' => $bookingId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display participant cards overview.
|
||||
*/
|
||||
#[Route('/bookings/{id}/edit', name: 'app_booking_edit', requirements: ['id' => '\d+'])]
|
||||
#[Route('/bookings/{bookingId}/edit', name: 'app_booking_edit', requirements: ['bookingId' => '\d+'])]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function index(int $id, Request $request): Response
|
||||
public function index(int $bookingId, Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
// Load form data from session (or API on first load)
|
||||
try {
|
||||
$bookingDto = $this->dataLoader->loadFormData($request, $id, $user);
|
||||
$bookingDto = $this->dataLoader->loadFormData($request, $bookingId, $user);
|
||||
} catch (TravelNotFoundException) {
|
||||
$this->addFlash('error', 'Reisedaten sind nicht (mehr) verfügbar');
|
||||
|
||||
@@ -92,12 +91,12 @@ class IndexController extends AbstractController
|
||||
}
|
||||
|
||||
// Show flash message if draft was restored
|
||||
if (true === $this->dataLoader->wasDraftRestored()) {
|
||||
if (true === $this->dataLoader->isDraftRestored()) {
|
||||
$this->addFlash('info', 'Dein zuvor gespeicherter Entwurf wurde wiederhergestellt.');
|
||||
}
|
||||
|
||||
// Fetch booking data for display (surcharges, canceled status, etc.)
|
||||
$bookingData = $this->dataLoader->fetchBookingData($id, $user);
|
||||
$bookingData = $this->dataLoader->fetchBookingData($bookingId, $user);
|
||||
if (null === $bookingData || $bookingData instanceof Notification) {
|
||||
$this->addFlash('error', 'Buchungsdaten nicht (mehr) verfügbar');
|
||||
|
||||
@@ -110,7 +109,10 @@ class IndexController extends AbstractController
|
||||
|
||||
// Handle form submission (clicking "Buchung aktualisieren")
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
return $this->submitService->handleSubmission($request, $bookingDto, $id, $user);
|
||||
$submissionResult = $this->formSubmitter->handleSubmission($request, $bookingDto, $bookingId, $user);
|
||||
$this->applySubmissionResultFlashes($submissionResult);
|
||||
|
||||
return $this->redirectToRoute('app_booking_edit', ['bookingId' => $bookingId]);
|
||||
}
|
||||
|
||||
$bookingEditContext = $this->editContextFactory->createOverviewContext(
|
||||
@@ -129,6 +131,39 @@ class IndexController extends AbstractController
|
||||
return $this->render('booking/edit/index.html.twig', $templateData);
|
||||
}
|
||||
|
||||
private function applySubmissionResultFlashes(BookingEditSubmissionResult $result): void
|
||||
{
|
||||
if (true === $result->immutableChangesReverted) {
|
||||
$this->addFlash('info', 'Einige Änderungen wurden verworfen, da sie aktuell nicht mehr änderbar sind.');
|
||||
}
|
||||
|
||||
switch ($result->status) {
|
||||
case BookingEditSubmissionResult::STATUS_BOOKING_DATA_RELOAD_FAILED:
|
||||
$this->addFlash('error', 'Buchungsdaten konnten vor dem Speichern nicht neu geladen werden');
|
||||
break;
|
||||
case BookingEditSubmissionResult::STATUS_NOTIFICATION_ERROR:
|
||||
$this->addFlash('error', $result->message ?? 'Es ist ein Fehler in der Kommunikation mit dem Buchungssystem aufgetreten');
|
||||
break;
|
||||
case BookingEditSubmissionResult::STATUS_NOTIFICATION_INFO:
|
||||
if (null !== $result->message && '' !== trim($result->message)) {
|
||||
$this->addFlash('info', $result->message);
|
||||
}
|
||||
break;
|
||||
case BookingEditSubmissionResult::STATUS_SUCCESS:
|
||||
$this->addFlash('success', 'Buchung erfolgreich aktualisiert');
|
||||
break;
|
||||
case BookingEditSubmissionResult::STATUS_UNSUCCESSFUL:
|
||||
$this->addFlash('error', $result->message ?? 'Buchung konnte nicht aktualisiert werden');
|
||||
break;
|
||||
case BookingEditSubmissionResult::STATUS_TIMEOUT:
|
||||
$this->addFlash('error', 'Die Anfrage hat zu lange gedauert. Bitte versuche es erneut.');
|
||||
break;
|
||||
case BookingEditSubmissionResult::STATUS_API_CLIENT_ERROR:
|
||||
$this->addFlash('error', 'Es ist ein Fehler in der Kommunikation mit dem Buchungssystem aufgetreten');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads booking data from API, discarding all session changes.
|
||||
*
|
||||
@@ -136,12 +171,12 @@ class IndexController extends AbstractController
|
||||
* POST: Clears session and redirects to reload the booking
|
||||
*/
|
||||
#[Route(
|
||||
path: '/bookings/{id}/edit/reload',
|
||||
path: '/bookings/{bookingId}/edit/reload',
|
||||
name: 'app_booking_edit_reload',
|
||||
requirements: ['id' => '\d+']
|
||||
requirements: ['bookingId' => '\d+']
|
||||
)]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function reloadFromApi(int $id, Request $request): Response
|
||||
public function reloadFromApi(int $bookingId, Request $request): Response
|
||||
{
|
||||
if (Request::METHOD_POST === $request->getMethod()) {
|
||||
// Clear session to discard all changes
|
||||
@@ -150,15 +185,15 @@ class IndexController extends AbstractController
|
||||
// Delete draft since user explicitly chose to discard changes
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$this->draftService->deleteDraft($user, $id);
|
||||
$this->draftService->deleteDraft($user, $bookingId);
|
||||
|
||||
$this->addFlash('success', 'Änderungen verworfen, Daten neu geladen');
|
||||
|
||||
return $this->redirectToRoute('app_booking_edit', ['id' => $id]);
|
||||
return $this->redirectToRoute('app_booking_edit', ['bookingId' => $bookingId]);
|
||||
}
|
||||
|
||||
return $this->render('booking/edit/modal_reload.html.twig', [
|
||||
'bookingId' => $id,
|
||||
'bookingId' => $bookingId,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -169,12 +204,12 @@ class IndexController extends AbstractController
|
||||
* Shows a flash message informing about the saved draft.
|
||||
*/
|
||||
#[Route(
|
||||
path: '/bookings/{id}/edit/cancel',
|
||||
path: '/bookings/{bookingId}/edit/cancel',
|
||||
name: 'app_booking_edit_cancel',
|
||||
requirements: ['id' => '\d+']
|
||||
requirements: ['bookingId' => '\d+']
|
||||
)]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function cancelEdit(int $id, Request $request): Response
|
||||
public function cancelEdit(int $bookingId, Request $request): Response
|
||||
{
|
||||
// Clear session state
|
||||
$this->bookingSessionService->clearBookingDto($request, BookingDto::MODE_EDIT);
|
||||
@@ -182,7 +217,7 @@ class IndexController extends AbstractController
|
||||
// Check if a draft exists to show appropriate message
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$draft = $this->draftService->findDraft($user, $id);
|
||||
$draft = $this->draftService->findDraft($user, $bookingId);
|
||||
|
||||
if (null !== $draft) {
|
||||
$this->addFlash('info', 'Deine Änderungen wurden als Entwurf gespeichert.');
|
||||
|
||||
Reference in New Issue
Block a user