ldc-cocotte/app/Cqs/Queries/Timeslots/GetAvailableTimeslotsQuery.php
Jérémy Munsch d0efb0f527
refactor: update namespaces for actions and queries
Refactored the codebase to change the namespaces of various actions and queries from `App\Actions` to `App\Cqs\Actions` and `App\Queries` to `App\Cqs\Queries`. This restructuring improves organization and clarity in the codebase.
2026-11-10 15:13:26 +01:00

56 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);
}
}