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

73 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Fo\Customers;
use App\Cqs\Actions\Crm\UpdateCustomer;
use App\Contracts\Executor;
use App\Http\Controllers\Controller;
use App\Http\Requests\Fo\Customer\UpdateInfosRequest;
use App\Models\Customer;
use App\Cqs\Queries\Crm\GetCrmCustomerQuery;
use App\Cqs\Queries\Crm\GetCrmCustomerQueryInput;
use Domain\Models\ValueObjects\CrmCustomer;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Validation\ValidationException;
class CustomerController extends Controller
{
public function __construct(
private readonly Executor $executor,
) {
}
public function dashboard(): View
{
$this->authorize('manageOwnProfile', Customer::class);
return view('fo.customer.dashboard');
}
public function editInfos(GetCrmCustomerQuery $getCrmCustomerQuery): View
{
$this->authorize('manageOwnProfile', Customer::class);
$output = $this->executor->execute(
$getCrmCustomerQuery,
new GetCrmCustomerQueryInput()
);
abort_unless(
$output->customer instanceof CrmCustomer,
503,
trans('An error occurred, please try again later.')
);
return view('fo.customer.edit.infos', [
'crmCustomer' => $output->customer,
]);
}
public function editInfosSubmit(UpdateInfosRequest $request, UpdateCustomer $updateCustomer): RedirectResponse
{
$this->authorize('manageOwnProfile', Customer::class);
$output = $this->executor->execute(
$updateCustomer,
$request->toUpdateCustomerInput()
);
return match (true) {
$output->result instanceof CrmCustomer => back()
->with('success', trans('Your information has been saved.')),
$output->result instanceof ValidationException => back()
->withInput()
->withErrors($output->result->getMessage()),
default => back()
->withInput()
->withErrors(trans('An error occurred, please try again later.')),
};
}
}