feat: improved error handling in controllers, cleanup
This commit is contained in:
@@ -17,16 +17,20 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
trait BookingCreateTrait
|
||||
{
|
||||
/**
|
||||
* Validates step access and redirects if necessary.
|
||||
* Validates step access and returns redirect response if necessary.
|
||||
*
|
||||
* @return RedirectResponse|null Returns redirect response if validation fails, null if access is allowed
|
||||
*/
|
||||
private function validateStepAccess(BookingCreateDto $bookingCreateDto, int $expectedStep): void
|
||||
private function validateStepAccess(BookingCreateDto $bookingCreateDto, int $expectedStep): ?RedirectResponse
|
||||
{
|
||||
// Allow access to current step or any previous step
|
||||
if ($expectedStep > $bookingCreateDto->currentStep) {
|
||||
$this->addFlash('error', 'Bitte erst die vorherigen Schritte abschließen.');
|
||||
|
||||
$this->redirectToCurrentStep($bookingCreateDto);
|
||||
return $this->redirectToCurrentStep($bookingCreateDto);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,18 +38,12 @@ trait BookingCreateTrait
|
||||
*/
|
||||
private function redirectToCurrentStep(BookingCreateDto $bookingCreateDto): RedirectResponse
|
||||
{
|
||||
$routeParams = [
|
||||
'date_id' => $bookingCreateDto->travel->id,
|
||||
'hotel_id' => $bookingCreateDto->travel->hotelId,
|
||||
];
|
||||
|
||||
$route = match ($bookingCreateDto->currentStep) {
|
||||
1 => 'app_booking_create_step_1',
|
||||
2 => 'app_booking_create_step_2',
|
||||
3 => 'app_booking_create_step_3',
|
||||
default => 'app_booking_create_step_1',
|
||||
};
|
||||
|
||||
return $this->redirectToRoute($route, $routeParams);
|
||||
return $this->redirectToRoute($route);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user