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

71 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Fo\Customers;
use App\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\Queries\Crm\GetCrmCustomerQuery;
use App\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);
$crmCustomer = $this->executor->execute(
$getCrmCustomerQuery,
new GetCrmCustomerQueryInput()
);
abort_unless(
$crmCustomer->customer instanceof CrmCustomer,
503,
trans('An error occurred, please try again later.')
);
return view('fo.customer.edit.infos', compact('crmCustomer'));
}
public function editInfosSubmit(UpdateInfosRequest $request, UpdateCustomer $updateCustomer): RedirectResponse
{
$this->authorize('manageOwnProfile', Customer::class);
$result = $this->executor->execute(
$updateCustomer,
$request->toUpdateCustomerInput()
);
return match ($result) {
$result instanceof CrmCustomer => back()
->with('success', trans('Your information has been saved.')),
$result instanceof ValidationException => back()
->withInput()
->withErrors($result->getMessage()),
default => back()
->withInput()
->withErrors(trans('An error occurred, please try again later.')),
};
}
}