ldc-cocotte/app/Cqs/Queries/Timeslots/GetAvailableTimeslotsQuery.php
Jérémy Munsch 454695928b
refactor: format PHPDoc for query implementations
Improves readability of PHPDoc annotations across multiple query classes.
2026-11-10 18:17:04 +01:00

59 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Cqs\Queries\Timeslots;
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;
/**
* @implements \App\Contracts\Query<
* \App\Cqs\Queries\Timeslots\GetAvailableTimeslotsQueryInput,
* \App\Cqs\Queries\Timeslots\GetAvailableTimeslotsQueryOutput
* >
*/
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);
}
}