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