feat: improved error handling in controllers, cleanup

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 4f02529b15
commit ede37d5d0f
11 changed files with 261 additions and 119 deletions
+8 -10
View File
@@ -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);
}
}