Adds UpdateCustomer action, input, and output classes to handle customer information updates. Integrates with existing services and updates the CustomerController to utilize the new action.
39 lines
1 KiB
PHP
39 lines
1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\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\Queries\Crm\GetCrmCustomerQueryInput, \App\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);
|
|
}
|
|
}
|