ldc-cocotte/app/Http/Controllers/Fo/Customers/PasswordController.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

49 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Fo\Customers;
use App\Cqs\Actions\Crm\UpdateCustomerPassword;
use App\Contracts\Executor;
use App\Http\Controllers\Controller;
use App\Http\Requests\Fo\Customer\UpdatePasswordRequest;
use App\Models\Customer;
use Domain\Models\ValueObjects\CrmCustomer;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Validation\ValidationException;
class PasswordController extends Controller
{
public function __construct(
private readonly Executor $executor
) {
}
public function editPassword(): View
{
$this->authorize('manageOwnProfile', Customer::class);
return view('fo.customer.edit.password');
}
public function editPasswordSubmit(UpdatePasswordRequest $request, UpdateCustomerPassword $updateCustomerPassword): RedirectResponse
{
$this->authorize('manageOwnProfile', Customer::class);
$result = $this->executor->execute(
$updateCustomerPassword,
$request->toUpdateCustomerPasswordInput()
);
return match (true) {
$result->result instanceof CrmCustomer => back()
->with('success', trans('Password updated')),
$result->result instanceof ValidationException => back()
->withErrors($result->result->errors()),
$result->result === false => back()
->withErrors(trans('An error occurred, please try again later.')),
};
}
}