ldc-cocotte/app/Cqs/Queries/Crm/GetCrmCustomerQuery.php

40 lines
1 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace App\Cqs\Queries\Crm;
use App\Contracts\Query;
use App\Contracts\QueryInput;
use App\Services\CrmService;
use Infrastructure\Adapters\Services\AppCustomerAuthService;
use Webmozart\Assert\Assert;
/**
* @implements \App\Contracts\Query<\App\Cqs\Queries\Crm\GetCrmCustomerQueryInput, \App\Cqs\Queries\Crm\GetCrmCustomerQueryOutput>
*/
final readonly class GetCrmCustomerQuery implements Query
{
public function __construct(
private CrmService $crmService,
private AppCustomerAuthService $authService,
) {
}
public function __invoke(QueryInput $input): GetCrmCustomerQueryOutput
{
Assert::isAOf(
$input,
GetCrmCustomerQueryInput::class,
);
$hashcode = $input->fromHashcodeOrAuthenticatedUserHashcode ?? $this->authService->getCustomerAsMandatory()->hashcode;
$crmCustomer = $this->crmService->getCustomerFromHashCode(
$hashcode
);
return new GetCrmCustomerQueryOutput($crmCustomer);
}
}