wip: refactor
This commit is contained in:
@@ -5,7 +5,7 @@ namespace App\Form\Model;
|
|||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
class BookingCreateDto
|
class BookingCreateDto implements BookingDtoInterface
|
||||||
{
|
{
|
||||||
public int $currentStep = 1;
|
public int $currentStep = 1;
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ class BookingCreateDto
|
|||||||
#[Assert\Valid]
|
#[Assert\Valid]
|
||||||
public array $participants = [];
|
public array $participants = [];
|
||||||
|
|
||||||
public function __construct(public Travel $travelData, public int $hotelId)
|
public function __construct(public Travel $travel, public int $hotelId)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,4 +34,24 @@ class BookingCreateDto
|
|||||||
return 0 < $roomSelection->quantity;
|
return 0 < $roomSelection->quantity;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getParticipants(): array
|
||||||
|
{
|
||||||
|
return $this->participants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTravel(): Travel
|
||||||
|
{
|
||||||
|
return $this->travel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasParticipant(int $index): bool
|
||||||
|
{
|
||||||
|
return isset($this->participants[$index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getParticipant(int $index): ?ParticipantDto
|
||||||
|
{
|
||||||
|
return $this->participants[$index] ?? null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Form\Model;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\Travel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for unified access to booking data across create and edit workflows.
|
||||||
|
*
|
||||||
|
* This interface provides a consistent API for accessing common booking data
|
||||||
|
* regardless of whether the data comes from a creation workflow (BookingCreateDto)
|
||||||
|
* or an edit workflow (BookingEditDto). This enables code reuse and simplifies
|
||||||
|
* form field handlers and state management systems.
|
||||||
|
*/
|
||||||
|
interface BookingDtoInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Gets all participants in the booking.
|
||||||
|
*
|
||||||
|
* @return array<int, ParticipantDto> Array of participant DTOs indexed by participant index
|
||||||
|
*/
|
||||||
|
public function getParticipants(): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the travel data for the booking.
|
||||||
|
*
|
||||||
|
* @return Travel The travel data containing services, hotels, and other booking options
|
||||||
|
*/
|
||||||
|
public function getTravel(): Travel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a participant exists at the given index.
|
||||||
|
*
|
||||||
|
* @param int $index The participant index to check
|
||||||
|
*
|
||||||
|
* @return bool True if a participant exists at the given index
|
||||||
|
*/
|
||||||
|
public function hasParticipant(int $index): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a participant by index.
|
||||||
|
*
|
||||||
|
* @param int $index The participant index
|
||||||
|
*
|
||||||
|
* @return ParticipantDto|null The participant DTO or null if not found
|
||||||
|
*/
|
||||||
|
public function getParticipant(int $index): ?ParticipantDto;
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ use App\BusProNet\Model\PersonalData;
|
|||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
class BookingEditDto
|
class BookingEditDto implements BookingDtoInterface
|
||||||
{
|
{
|
||||||
public ?Booking $booking = null;
|
public ?Booking $booking = null;
|
||||||
public ?Travel $travel = null;
|
public ?Travel $travel = null;
|
||||||
@@ -63,4 +63,24 @@ class BookingEditDto
|
|||||||
{
|
{
|
||||||
return 'O' === $this->booking->status;
|
return 'O' === $this->booking->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getParticipants(): array
|
||||||
|
{
|
||||||
|
return $this->participants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTravel(): Travel
|
||||||
|
{
|
||||||
|
return $this->travel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasParticipant(int $index): bool
|
||||||
|
{
|
||||||
|
return isset($this->participants[$index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getParticipant(int $index): ?ParticipantDto
|
||||||
|
{
|
||||||
|
return $this->participants[$index] ?? null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user