wip: finalize implementation
This commit is contained in:
@@ -65,7 +65,7 @@ class Step1Controller extends AbstractController
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||
if ($this->bookingService->hasRoomSelectionChanged($oldRoomSelectionSnapshot, $bookingCreateDto)) {
|
||||
$this->bookingService->resetParticipantAssignments($bookingCreateDto);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class Step1Controller extends AbstractController
|
||||
* without validation and returning freshly rendered blocks.
|
||||
*/
|
||||
#[Route('/bookings/create/refresh', name: 'app_booking_create_step_1_refresh', methods: ['POST'])]
|
||||
public function refreshRoomSelection(Request $request): Response
|
||||
public function refresh(Request $request): Response
|
||||
{
|
||||
$result = $this->getOrCreateBookingCreateDtoForHtmx($this->bookingService, $request);
|
||||
if ($result instanceof Response) {
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Controller\Booking\Traits\ParticipantValidationTrait;
|
||||
use App\Form\BookingCreateStep2Type;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\ParticipantFieldOptionsProvider;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
use App\Service\BookingService;
|
||||
@@ -42,6 +43,7 @@ class Step2Controller extends AbstractController
|
||||
private readonly TravelDataService $travelDataService,
|
||||
private readonly RoomAssignmentService $roomAssignmentService,
|
||||
private readonly ParticipantCardDataService $participantCardService,
|
||||
private readonly ParticipantFieldOptionsProvider $fieldOptionsProvider,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -58,14 +60,14 @@ class Step2Controller extends AbstractController
|
||||
}
|
||||
$bookingCreateDto = $result;
|
||||
|
||||
// Enrich with fresh availability data
|
||||
$this->enrichWithFreshAvailabilities($bookingCreateDto);
|
||||
|
||||
// Validate step access
|
||||
if ($redirect = $this->validateStepAccess($bookingCreateDto, 2)) {
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
// Enrich with fresh availability data
|
||||
$this->enrichWithFreshAvailabilities($bookingCreateDto);
|
||||
|
||||
// Ensure correct number of participants
|
||||
$this->ensureCorrectNumberOfParticipants($bookingCreateDto);
|
||||
|
||||
@@ -84,8 +86,8 @@ class Step2Controller extends AbstractController
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Handle form submission (clicking "Weiter")
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// Handle form submission
|
||||
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||
// All participants validated successfully, update current step
|
||||
$bookingCreateDto->currentStep = 3;
|
||||
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
|
||||
@@ -96,7 +98,7 @@ class Step2Controller extends AbstractController
|
||||
|
||||
// Extract participant indices with validation errors
|
||||
$participantErrors = [];
|
||||
if ($form->isSubmitted() && false === $form->isValid()) {
|
||||
if (true === $form->isSubmitted() && false === $form->isValid()) {
|
||||
$participantErrors = $this->extractParticipantErrorIndices($form);
|
||||
}
|
||||
|
||||
@@ -118,7 +120,7 @@ class Step2Controller extends AbstractController
|
||||
'participantErrors' => $participantErrors,
|
||||
];
|
||||
|
||||
// If HTMX request, render only blocks to avoid layout duplication
|
||||
// HTMX request: render blocks only
|
||||
if ($this->isHxRequest($request)) {
|
||||
return $this->htmxOobResponse(
|
||||
'booking/create/step_2.html.twig',
|
||||
@@ -148,6 +150,9 @@ class Step2Controller extends AbstractController
|
||||
throw $this->createNotFoundException(sprintf('Participant at index %d does not exist', $index));
|
||||
}
|
||||
|
||||
// Enrich with fresh availability data
|
||||
$this->enrichWithFreshAvailabilities($bookingDto);
|
||||
|
||||
// Create form with booking_context option
|
||||
$form = $this->createParticipantForm($bookingDto, $index, [
|
||||
'validation_groups' => ['booking_create_step_2'],
|
||||
@@ -155,7 +160,7 @@ class Step2Controller extends AbstractController
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||
// Save BookingDto to session
|
||||
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_CREATE);
|
||||
|
||||
@@ -199,14 +204,14 @@ class Step2Controller extends AbstractController
|
||||
{
|
||||
$bookingDto = $this->loadBookingDtoOrFail($request, BookingDto::MODE_CREATE);
|
||||
|
||||
// Enrich with fresh availability data
|
||||
$this->enrichWithFreshAvailabilities($bookingDto);
|
||||
|
||||
// Validate participant index
|
||||
if (false === isset($bookingDto->participants[$index])) {
|
||||
throw $this->createNotFoundException(sprintf('Participant at index %d does not exist', $index));
|
||||
}
|
||||
|
||||
// Enrich with fresh availability data
|
||||
$this->enrichWithFreshAvailabilities($bookingDto);
|
||||
|
||||
// Use trait method for refresh handling
|
||||
return $this->handleParticipantRefresh(
|
||||
$request,
|
||||
|
||||
@@ -64,13 +64,14 @@ class Step3Controller extends AbstractController
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||
try {
|
||||
// Validate booking data with API (inquiry)
|
||||
$bookingCreateDto->bookingStatus = 'A';
|
||||
$inquiryResponse = $this->apiClient->createBookingInquiry($bookingCreateDto);
|
||||
|
||||
if ($inquiryResponse instanceof Notification) {
|
||||
return $this->handleInquiryError(
|
||||
return $this->handleApiError(
|
||||
'Booking inquiry failed',
|
||||
['message' => $inquiryResponse->message],
|
||||
'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.',
|
||||
@@ -80,7 +81,7 @@ class Step3Controller extends AbstractController
|
||||
}
|
||||
|
||||
if (false === $inquiryResponse->isInquiryValid()) {
|
||||
return $this->handleInquiryError(
|
||||
return $this->handleApiError(
|
||||
'Booking inquiry validation failed',
|
||||
['status' => $inquiryResponse->status],
|
||||
'Buchung konnte nicht validiert werden.',
|
||||
@@ -94,7 +95,7 @@ class Step3Controller extends AbstractController
|
||||
$calculatedTotal = $this->priceCalculator->calculateGrandTotal($bookingCreateDto);
|
||||
|
||||
if ($apiTotal !== $calculatedTotal) {
|
||||
return $this->handleInquiryError(
|
||||
return $this->handleApiError(
|
||||
'Price mismatch detected - payload incomplete',
|
||||
[
|
||||
'apiTotal' => $apiTotal,
|
||||
@@ -111,9 +112,13 @@ class Step3Controller extends AbstractController
|
||||
$bookingCreateDto->currentStep = 4;
|
||||
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||
|
||||
if ($inquiryResponse->message) {
|
||||
$this->addFlash('info', $inquiryResponse->message);
|
||||
}
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_create_step_4'));
|
||||
} catch (\Exception $e) {
|
||||
return $this->handleInquiryError(
|
||||
return $this->handleApiError(
|
||||
'Booking inquiry exception',
|
||||
[
|
||||
'exception' => $e->getMessage(),
|
||||
@@ -151,22 +156,6 @@ class Step3Controller extends AbstractController
|
||||
return $this->renderStepForm($bookingCreateDto, $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles inquiry errors by logging, adding flash message, and rendering the form.
|
||||
*/
|
||||
private function handleInquiryError(
|
||||
string $logMessage,
|
||||
array $context,
|
||||
string $flashMessage,
|
||||
BookingDto $bookingCreateDto,
|
||||
FormInterface $form,
|
||||
): Response {
|
||||
$this->logger->error($logMessage, $context);
|
||||
$this->addFlash('error', $flashMessage);
|
||||
|
||||
return $this->renderStepForm($bookingCreateDto, $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the step 3 form with standard template variables.
|
||||
*/
|
||||
|
||||
@@ -62,13 +62,13 @@ class Step4Controller extends AbstractController
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||
try {
|
||||
// Submit final booking (already validated in Step 3)
|
||||
$bookingResponse = $this->apiClient->createBooking($bookingCreateDto);
|
||||
|
||||
if ($bookingResponse instanceof Notification) {
|
||||
return $this->handleBookingError(
|
||||
return $this->handleApiError(
|
||||
'Booking creation failed - API notification',
|
||||
['message' => $bookingResponse->message],
|
||||
$bookingResponse->message,
|
||||
@@ -78,7 +78,7 @@ class Step4Controller extends AbstractController
|
||||
}
|
||||
|
||||
if (false === $bookingResponse->isBookingSuccessful()) {
|
||||
return $this->handleBookingError(
|
||||
return $this->handleApiError(
|
||||
'Booking creation unsuccessful',
|
||||
['status' => $bookingResponse->status],
|
||||
'Buchung konnte nicht erstellt werden.',
|
||||
@@ -93,7 +93,7 @@ class Step4Controller extends AbstractController
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_create_success'));
|
||||
} catch (\Exception $e) {
|
||||
return $this->handleBookingError(
|
||||
return $this->handleApiError(
|
||||
'Booking creation exception',
|
||||
[
|
||||
'exception' => $e->getMessage(),
|
||||
@@ -109,22 +109,6 @@ class Step4Controller extends AbstractController
|
||||
return $this->renderStepForm($bookingCreateDto, $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles booking errors by logging, adding flash message, and rendering the form.
|
||||
*/
|
||||
private function handleBookingError(
|
||||
string $logMessage,
|
||||
array $context,
|
||||
string $flashMessage,
|
||||
BookingDto $bookingCreateDto,
|
||||
FormInterface $form,
|
||||
): Response {
|
||||
$this->logger->error($logMessage, $context);
|
||||
$this->addFlash('error', $flashMessage);
|
||||
|
||||
return $this->renderStepForm($bookingCreateDto, $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the step 4 form with standard template variables.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,9 @@ declare(strict_types=1);
|
||||
namespace App\Controller\Booking\Traits;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Provides common functionality for booking creation controllers.
|
||||
@@ -78,4 +80,20 @@ trait BookingCreateTrait
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles API errors by logging, adding flash message, and rendering the form.
|
||||
*/
|
||||
private function handleApiError(
|
||||
string $logMessage,
|
||||
array $context,
|
||||
string $flashMessage,
|
||||
BookingDto $bookingCreateDto,
|
||||
FormInterface $form,
|
||||
): Response {
|
||||
$this->logger->error($logMessage, $context);
|
||||
$this->addFlash('error', $flashMessage);
|
||||
|
||||
return $this->renderStepForm($bookingCreateDto, $form);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@ trait ParticipantCardFlowTrait
|
||||
// Merge default options with provided options
|
||||
$formOptions = array_merge([
|
||||
'booking_context' => $bookingDto,
|
||||
'edit_mode' => BookingDto::MODE_EDIT === $bookingDto->getMode(),
|
||||
], $options);
|
||||
|
||||
return $this->createForm(BookingParticipantType::class, $participant, $formOptions);
|
||||
|
||||
Reference in New Issue
Block a user