This commit refactors the import statements in various controllers and jobs to improve code organization and readability. Unused imports were removed, and necessary imports were added to ensure proper functionality.
73 lines
2.2 KiB
PHP
73 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Fo\Customers;
|
|
|
|
use App\Contracts\Executor;
|
|
use App\Cqs\Actions\Crm\UpdateCustomer;
|
|
use App\Cqs\Queries\Crm\GetCrmCustomerQuery;
|
|
use App\Cqs\Queries\Crm\GetCrmCustomerQueryInput;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Fo\Customer\UpdateInfosRequest;
|
|
use App\Models\Customer;
|
|
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.')),
|
|
};
|
|
}
|
|
}
|