2026-09-30 10:54:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
namespace App\Cqs\Queries\Timeslots;
|
2026-09-30 10:54:23 +02:00
|
|
|
|
|
|
|
|
use App\Contracts\Query;
|
|
|
|
|
use App\Contracts\QueryInput;
|
|
|
|
|
use Carbon\CarbonImmutable;
|
|
|
|
|
use Carbon\CarbonInterface;
|
|
|
|
|
use Domain\Ports\Repositories\ShopRepository;
|
|
|
|
|
use Domain\Services\PickupSchedulingService;
|
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-11-10 18:17:04 +01:00
|
|
|
* @implements \App\Contracts\Query<
|
|
|
|
|
* \App\Cqs\Queries\Timeslots\GetAvailableTimeslotsQueryInput,
|
|
|
|
|
* \App\Cqs\Queries\Timeslots\GetAvailableTimeslotsQueryOutput
|
|
|
|
|
* >
|
2026-09-30 10:54:23 +02:00
|
|
|
*/
|
|
|
|
|
final readonly class GetAvailableTimeslotsQuery implements Query
|
|
|
|
|
{
|
|
|
|
|
private const int TIMESLOTS_DAY_TARGET = 28;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly PickupSchedulingService $pickupService,
|
|
|
|
|
private readonly ShopRepository $shopRepository
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __invoke(QueryInput $input): GetAvailableTimeslotsQueryOutput
|
|
|
|
|
{
|
|
|
|
|
Assert::isAOf(
|
|
|
|
|
$input,
|
|
|
|
|
GetAvailableTimeslotsQueryInput::class,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$domainShop = $this->shopRepository->find($input->forShop);
|
|
|
|
|
|
|
|
|
|
/** @var \Domain\Models\ValueObjects\PickupTimeSlot[] */
|
|
|
|
|
$timeslotList = [];
|
|
|
|
|
|
|
|
|
|
if ($domainShop !== null) {
|
|
|
|
|
$timeslotList = $this->pickupService->getTimeSlotsFor(
|
|
|
|
|
$domainShop,
|
|
|
|
|
$this->getUntil()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new GetAvailableTimeslotsQueryOutput(
|
|
|
|
|
timeslotList: $timeslotList
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getUntil(): CarbonInterface
|
|
|
|
|
{
|
|
|
|
|
return CarbonImmutable::now()->addDays(self::TIMESLOTS_DAY_TARGET);
|
|
|
|
|
}
|
|
|
|
|
}
|