- Introduced ApplyPickTimeSlotOutput class for structured output. - Updated ApplyPickTimeSlot action to return ApplyPickTimeSlotOutput. - Added ApplyPickTimeSlotStatus enum for status representation. - Modified TunnelController to handle new output structure. - Enhanced tests for ApplyPickTimeSlot to validate new behavior.
48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cqs\Actions\Orders;
|
|
|
|
use App\Contracts\Action;
|
|
use App\Contracts\ActionInput;
|
|
use Domain\Services\OrderTunnelService;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Action<
|
|
* \App\Cqs\Actions\Orders\ApplyPickTimeSlotInput,
|
|
* \App\Cqs\Actions\Orders\ApplyPickTimeSlotOutput
|
|
* >
|
|
*/
|
|
final class ApplyPickTimeSlot implements Action
|
|
{
|
|
public function __construct(
|
|
private readonly OrderTunnelService $orderTunnelService,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @param \App\Cqs\Actions\Orders\ApplyPickTimeSlotInput $input
|
|
*/
|
|
#[\Override]
|
|
public function __invoke(ActionInput $input): ApplyPickTimeSlotOutput
|
|
{
|
|
Assert::isInstanceOf($input, ApplyPickTimeSlotInput::class);
|
|
|
|
$builder = $this->orderTunnelService->getBuilderFromBasketOrFail();
|
|
$shop = $this->orderTunnelService->getShopForCustomer($input->shopperId);
|
|
$timeSlots = $this->orderTunnelService->getAvailableTimeSlots($shop);
|
|
|
|
$timeSlot = $this->orderTunnelService->applyTimeSlot(
|
|
$builder,
|
|
$shop,
|
|
$input->timeslot,
|
|
$timeSlots
|
|
);
|
|
|
|
return $timeSlot !== null
|
|
? ApplyPickTimeSlotOutput::matched($timeSlot)
|
|
: ApplyPickTimeSlotOutput::unavailable();
|
|
}
|
|
}
|