feat: replace edit participant facade with context factory
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\BookingEditParticipantContext;
|
||||
|
||||
/**
|
||||
* Prepares the shared edit-participant page context.
|
||||
*/
|
||||
class BookingEditParticipantContextFactory
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BookingSummaryDataService $summaryDataService,
|
||||
private readonly TravelDataService $travelDataService,
|
||||
) {
|
||||
}
|
||||
|
||||
public function prepareBookingDto(BookingDto $bookingDto): void
|
||||
{
|
||||
$this->travelDataService->enrichWithFreshAvailabilities($bookingDto->travel);
|
||||
}
|
||||
|
||||
public function create(BookingDto $bookingDto, Booking $bookingData): BookingEditParticipantContext
|
||||
{
|
||||
return new BookingEditParticipantContext(
|
||||
bookingDto: $bookingDto,
|
||||
bookingData: $bookingData,
|
||||
mutableData: $this->travelDataService->getMutabilityData($bookingData->dateId),
|
||||
summaryData: $this->summaryDataService->getSummaryData($bookingDto),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Entity\User;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\BookingSummaryDto;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Coordinates the edit-side participant form workflow.
|
||||
*
|
||||
* This service keeps the edit participant controller focused on HTTP concerns
|
||||
* while centralizing the session lookup, API data loading, form options, and
|
||||
* bookkeeping needed for participant edits and HTMX refreshes.
|
||||
*/
|
||||
class BookingEditParticipantFormService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BookingEditDataLoaderService $dataLoader,
|
||||
private readonly BookingEditDraftService $draftService,
|
||||
private readonly BookingSessionService $bookingSessionService,
|
||||
private readonly BookingSummaryDataService $summaryDataService,
|
||||
private readonly TravelDataService $travelDataService,
|
||||
) {
|
||||
}
|
||||
|
||||
public function loadBookingDto(Request $request): ?BookingDto
|
||||
{
|
||||
return $this->bookingSessionService->getBookingDto($request, BookingDto::MODE_EDIT);
|
||||
}
|
||||
|
||||
public function fetchBookingData(int $bookingId, User $user): Booking|Notification|null
|
||||
{
|
||||
return $this->dataLoader->fetchBookingData($bookingId, $user);
|
||||
}
|
||||
|
||||
public function isParticipantCanceled(Booking $bookingData, int $index): bool
|
||||
{
|
||||
return 'S' === ($bookingData->participantsStatus[$index] ?? null);
|
||||
}
|
||||
|
||||
public function enrichTravelData(BookingDto $bookingDto): void
|
||||
{
|
||||
$this->travelDataService->enrichWithFreshAvailabilities($bookingDto->travel);
|
||||
}
|
||||
|
||||
public function saveBookingDto(Request $request, BookingDto $bookingDto): void
|
||||
{
|
||||
$this->bookingSessionService->saveBookingDto($request, $bookingDto, BookingDto::MODE_EDIT);
|
||||
}
|
||||
|
||||
public function saveDraft(User $user, int $bookingId, BookingDto $bookingDto): void
|
||||
{
|
||||
$this->draftService->saveDraft($user, $bookingId, $bookingDto);
|
||||
}
|
||||
|
||||
public function getSummaryData(BookingDto $bookingDto): BookingSummaryDto
|
||||
{
|
||||
return $this->summaryDataService->getSummaryData($bookingDto);
|
||||
}
|
||||
|
||||
public function getMutableData(int $dateId): ?BaseData
|
||||
{
|
||||
return $this->travelDataService->getMutabilityData($dateId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user