ldc-cocotte/app/Cqs/Actions/Crm/UpdateCustomerPassword.php
Jérémy Munsch d0efb0f527
refactor: update namespaces for actions and queries
Refactored the codebase to change the namespaces of various actions and queries from `App\Actions` to `App\Cqs\Actions` and `App\Queries` to `App\Cqs\Queries`. This restructuring improves organization and clarity in the codebase.
2026-11-10 15:13:26 +01:00

54 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Cqs\Actions\Crm;
use App\Contracts\Action;
use App\Contracts\ActionInput;
use App\Services\CrmService;
use Domain\Models\ValueObjects\CrmCustomer;
use Infrastructure\Adapters\Services\AppCustomerAuthService;
use Webmozart\Assert\Assert;
/**
* @implements \App\Contracts\Action<\App\Cqs\Actions\Crm\UpdateCustomerPasswordInput, \App\Cqs\Actions\Crm\UpdateCustomerPasswordOutput>
*/
final class UpdateCustomerPassword implements Action
{
public function __construct(
private readonly AppCustomerAuthService $authService,
private readonly CrmService $crmService
) {
}
#[\Override]
public function __invoke(ActionInput $input): UpdateCustomerPasswordOutput
{
Assert::isInstanceOf($input, UpdateCustomerPasswordInput::class);
$hashcode = $this->authService->getCustomerAsMandatory()->hashcode;
$crmCustomer = $this->crmService->getCustomerFromHashCode(
$hashcode
);
if ($crmCustomer instanceof CrmCustomer === false) {
return new UpdateCustomerPasswordOutput(false);
}
try {
$result = $this->crmService->changePassword(
$crmCustomer,
$input->currentPassword,
$input->newPassword,
);
return new UpdateCustomerPasswordOutput($result);
} catch (\Throwable $e) {
report($e);
return new UpdateCustomerPasswordOutput(false);
}
}
}