41 lines
1.1 KiB
PHP
41 lines
1.1 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\Services\MapUrlService;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Query<\App\Queries\Orders\GetFoCustomerOrderDetailQueryInput, \App\Queries\Orders\GetFoCustomerOrderDetailQueryOutput>
|
|
*/
|
|
final readonly class GetFoCustomerOrderDetailQuery implements Query
|
|
{
|
|
public function __construct(
|
|
private MapUrlService $mapUrlService,
|
|
) {
|
|
}
|
|
|
|
#[\Override]
|
|
public function __invoke(QueryInput $input): GetFoCustomerOrderDetailQueryOutput
|
|
{
|
|
Assert::isInstanceOf($input, GetFoCustomerOrderDetailQueryInput::class);
|
|
|
|
$order = $input->order;
|
|
$order->load(['lines']);
|
|
|
|
$orderDto = OrderDto::fromModel($order);
|
|
$mapUrl = $order->delivery_address !== null
|
|
? $this->mapUrlService->generateUrl($order->delivery_address)
|
|
: null;
|
|
|
|
return new GetFoCustomerOrderDetailQueryOutput(
|
|
order: $orderDto,
|
|
mapUrl: $mapUrl,
|
|
);
|
|
}
|
|
}
|