feat: automatic saving of drafts when editing bookings
This commit is contained in:
@@ -10,8 +10,8 @@ use App\BusProNet\Exception\TimeoutException;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Controller\Booking\Traits;
|
||||
use App\Controller\Booking\Traits\BookingExceptionHandlerTrait;
|
||||
use App\Exception\TravelNotFoundException;
|
||||
use App\Entity\User;
|
||||
use App\Exception\TravelNotFoundException;
|
||||
use App\Form\BookingEditType;
|
||||
use App\Form\BookingParticipantType;
|
||||
use App\Form\Model\BookingDto;
|
||||
@@ -19,6 +19,7 @@ use App\Form\Model\ParticipantEditDto;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Security\Crypt;
|
||||
use App\Service\BookingEditDataLoaderService;
|
||||
use App\Service\BookingEditDraftService;
|
||||
use App\Service\BookingFingerprintService;
|
||||
use App\Service\BookingService;
|
||||
use App\Service\BookingSummaryDataService;
|
||||
@@ -49,6 +50,7 @@ class IndexController extends AbstractController
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly BookingEditDataLoaderService $dataLoader,
|
||||
private readonly BookingEditDraftService $draftService,
|
||||
private readonly TravelDataService $travelDataService,
|
||||
private readonly BookingService $bookingService,
|
||||
private readonly BookingFingerprintService $fingerprintService,
|
||||
@@ -73,7 +75,7 @@ class IndexController extends AbstractController
|
||||
|
||||
// Load form data from session (or API on first load)
|
||||
try {
|
||||
$bookingDto = $this->dataLoader->loadFormData($request, $id, $email, $password);
|
||||
$bookingDto = $this->dataLoader->loadFormData($request, $id, $email, $password, $user);
|
||||
} catch (TravelNotFoundException) {
|
||||
$this->addFlash('error', 'Reisedaten sind nicht (mehr) verfügbar');
|
||||
|
||||
@@ -86,6 +88,11 @@ class IndexController extends AbstractController
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
// Show flash message if draft was restored
|
||||
if (true === $this->dataLoader->wasDraftRestored()) {
|
||||
$this->addFlash('info', 'Dein zuvor gespeicherter Entwurf wurde wiederhergestellt.');
|
||||
}
|
||||
|
||||
// Fetch booking data for display (surcharges, canceled status, etc.)
|
||||
$bookingData = $this->dataLoader->fetchBookingData($email, $password, $id);
|
||||
if (null === $bookingData || $bookingData instanceof Notification) {
|
||||
@@ -103,7 +110,7 @@ class IndexController extends AbstractController
|
||||
|
||||
// Handle form submission (clicking "Buchung aktualisieren")
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
return $this->handleFormSubmission($request, $bookingDto, $id, $email);
|
||||
return $this->handleFormSubmission($request, $bookingDto, $id, $email, $user);
|
||||
}
|
||||
|
||||
// Always generate card data with validation state to show completeness
|
||||
@@ -202,6 +209,9 @@ class IndexController extends AbstractController
|
||||
// Save updated booking data to session
|
||||
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_EDIT);
|
||||
|
||||
// Auto-save draft to database for data persistence
|
||||
$this->draftService->saveDraft($user, $id, $bookingDto);
|
||||
|
||||
// Add notifications as flash messages (redirects destroy HTMX-triggered toasts)
|
||||
$this->addNotificationsAsFlashMessages($notifications);
|
||||
|
||||
@@ -376,7 +386,7 @@ class IndexController extends AbstractController
|
||||
/**
|
||||
* Handles form submission for booking update.
|
||||
*/
|
||||
private function handleFormSubmission(Request $request, BookingDto $bookingDto, int $id, string $email): Response
|
||||
private function handleFormSubmission(Request $request, BookingDto $bookingDto, int $id, string $email, User $user): Response
|
||||
{
|
||||
$this->logger->info('Initiated booking update', [
|
||||
'email' => $email,
|
||||
@@ -401,6 +411,9 @@ class IndexController extends AbstractController
|
||||
$this->dataLoader->invalidateBookingCache($id);
|
||||
$this->bookingService->clearBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
// Delete draft on successful submission
|
||||
$this->draftService->deleteDraft($user, $id);
|
||||
|
||||
$this->addFlash('success', 'Buchung erfolgreich aktualisiert');
|
||||
$this->logger->info('Booking update successful', [
|
||||
'email' => $email,
|
||||
|
||||
Reference in New Issue
Block a user