ldc-boutique-cnc-sable/app/Queries/Orders/GetTunnelOrderConfirmedQuery.php

52 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Queries\Orders;
use App\Contracts\Query;
use App\Contracts\QueryInput;
use App\Dto\OrderDto;
use App\Dto\ShopDto;
use App\Services\MapUrlService;
use Domain\Enums\OrderTunnelStep;
use Webmozart\Assert\Assert;
/**
* @implements \App\Contracts\Query<\App\Queries\Orders\GetTunnelOrderConfirmedQueryInput, \App\Queries\Orders\GetTunnelOrderConfirmedQueryOutput>
*/
final readonly class GetTunnelOrderConfirmedQuery implements Query
{
public function __construct(
private MapUrlService $mapUrlService,
) {
}
/**
* @param \App\Queries\Orders\GetTunnelOrderConfirmedQueryInput $input
*/
#[\Override]
public function __invoke(QueryInput $input): GetTunnelOrderConfirmedQueryOutput
{
Assert::isInstanceOf($input, GetTunnelOrderConfirmedQueryInput::class);
$order = $input->order;
$order->loadMissing(['shop', 'lines']);
$shop = $order->shop;
if (! $shop) {
throw new \UnexpectedValueException('Shop not found for order ' . $order->getId());
}
$shopDto = ShopDto::fromModel($shop);
$mapUrl = $this->mapUrlService->generateUrl($shopDto);
$orderDto = OrderDto::fromModel($order);
return new GetTunnelOrderConfirmedQueryOutput(
step: OrderTunnelStep::CONFIRMATION,
order: $orderDto,
shop: $shopDto,
mapUrl: $mapUrl,
);
}
}