54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Queries\Shops;
|
|
|
|
use App\Contracts\Query;
|
|
use App\Contracts\QueryInput;
|
|
use App\Dto\ShopDto;
|
|
use Domain\Ports\Repositories\ShopRepository;
|
|
use Domain\Services\PickupSchedulingService;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Query<\App\Queries\Shops\GetShopPickupExceptionsQueryInput, \App\Queries\Shops\GetShopPickupExceptionsQueryOutput>
|
|
*/
|
|
final readonly class GetShopPickupExceptionsQuery implements Query
|
|
{
|
|
public function __construct(
|
|
private ShopRepository $shopRepository,
|
|
private PickupSchedulingService $pickupService,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @param \App\Queries\Shops\GetShopPickupExceptionsQueryInput $input
|
|
*/
|
|
#[\Override]
|
|
public function __invoke(QueryInput $input): GetShopPickupExceptionsQueryOutput
|
|
{
|
|
Assert::isInstanceOf($input, GetShopPickupExceptionsQueryInput::class);
|
|
|
|
$shop = $input->shop;
|
|
$shop->load('pickupExceptions');
|
|
|
|
$domainShop = $this->shopRepository->find($shop->getId());
|
|
|
|
if ($domainShop === null) {
|
|
throw new NotFoundHttpException('Shop not found in domain');
|
|
}
|
|
|
|
$pickupExceptions = $this->pickupService->getEditablePickupExceptionsFor($domainShop);
|
|
$pickupDay = $this->pickupService->getPickupDay();
|
|
$pickupPeriod = $this->pickupService->getPeriodFromPickUpDay();
|
|
|
|
return new GetShopPickupExceptionsQueryOutput(
|
|
shop: ShopDto::fromModel($shop),
|
|
pickupExceptions: $pickupExceptions,
|
|
pickupDay: $pickupDay,
|
|
pickupPeriod: $pickupPeriod,
|
|
);
|
|
}
|
|
}
|