ldc-cocotte/app/Actions/Crm/UpdateCustomer.php
Jérémy Munsch 5037154108
feat(crm): implement customer update functionality
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.
2026-10-27 09:58:34 +01:00

53 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Actions\Crm;
use App\Contracts\Action;
use App\Contracts\ActionInput;
use App\Services\CrmService;
use Infrastructure\Adapters\Services\AppCustomerAuthService;
use Webmozart\Assert\Assert;
/**
* @implements \App\Contracts\Action<\App\Actions\Crm\UpdateCustomerInput, \App\Actions\Crm\UpdateCustomerOutput>
*/
final class UpdateCustomer implements Action
{
public function __construct(
private readonly AppCustomerAuthService $authService,
private readonly CrmService $crmService
) {
}
#[\Override]
public function __invoke(ActionInput $input): UpdateCustomerOutput
{
Assert::isInstanceOf($input, UnsubscribeFromNewsletterInput::class);
$customer = $this->authService->getCustomerAsMandatory();
try {
$result = $this->crmService->updateCustomerInfos(
$customer,
[
'firstname' => $input->firstname,
'lastname' => $input->lastname,
'birth_date' => $input->birthDate,
'phone' => $input->phone,
'address' => $input->address,
'postcode' => $input->postcode,
'city' => $input->city,
'opt_in' => $input->optIn,
]
);
return new UpdateCustomerOutput($result);
} catch (\Throwable $e) {
report($e);
return new UpdateCustomerOutput(false);
}
}
}