53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Queries\Orders;
|
|
|
|
use App\Contracts\Query;
|
|
use App\Contracts\QueryInput;
|
|
use App\Dto\ShopDto;
|
|
use Domain\Enums\OrderTunnelStep;
|
|
use Domain\Ports\Repositories\ShopRepository;
|
|
use Domain\Services\OrderTunnelService;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Query<\App\Queries\Orders\GetOrderConfirmationQueryInput, \App\Queries\Orders\GetOrderConfirmationQueryOutput>
|
|
*/
|
|
final readonly class GetOrderConfirmationQuery implements Query
|
|
{
|
|
public function __construct(
|
|
private OrderTunnelService $orderTunnelService,
|
|
private ShopRepository $shopRepository,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @param \App\Queries\Orders\GetOrderConfirmationQueryInput $input
|
|
*/
|
|
#[\Override]
|
|
public function __invoke(QueryInput $input): GetOrderConfirmationQueryOutput
|
|
{
|
|
Assert::isInstanceOf($input, GetOrderConfirmationQueryInput::class);
|
|
|
|
$builder = $this->orderTunnelService->getBuilderCompletedOrFail();
|
|
$basket = $builder->getBasket();
|
|
|
|
$shop = $this->shopRepository->find($builder->getShopId());
|
|
|
|
if (! $shop) {
|
|
throw new NotFoundHttpException('Shop not found');
|
|
}
|
|
|
|
$shopDto = ShopDto::fromDomain($shop);
|
|
|
|
return new GetOrderConfirmationQueryOutput(
|
|
step: OrderTunnelStep::CONFIRMATION,
|
|
basket: $basket,
|
|
builder: $builder,
|
|
shop: $shopDto,
|
|
);
|
|
}
|
|
}
|