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.
126 lines
4 KiB
PHP
126 lines
4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Contracts\Executor;
|
|
use App\Cqs\Actions\Discounts\CreateDiscount;
|
|
use App\Cqs\Actions\Discounts\DeleteDiscount;
|
|
use App\Cqs\Actions\Discounts\DeleteDiscountInput;
|
|
use App\Cqs\Actions\Discounts\UpdateDiscount;
|
|
use App\Cqs\Queries\Discounts\GetDiscountFormDataQuery;
|
|
use App\Cqs\Queries\Discounts\GetDiscountFormDataQueryInput;
|
|
use App\Cqs\Queries\Discounts\GetPaginatedDiscountsQuery;
|
|
use App\Cqs\Queries\Discounts\GetPaginatedDiscountsQueryInput;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Discounts\StoreDiscountRequest;
|
|
use App\Http\Requests\Bo\Discounts\UpdateDiscountRequest;
|
|
use App\Lib\Helpers\RequestHelper;
|
|
use App\Models\Discount;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
|
|
class DiscountsController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly Executor $executor,
|
|
) {
|
|
}
|
|
|
|
public function index(Request $request, GetPaginatedDiscountsQuery $query): View
|
|
{
|
|
$this->authorize('viewAny', Discount::class);
|
|
|
|
$pagination = RequestHelper::pagination($request);
|
|
|
|
$discounts = $this->executor->execute(
|
|
$query,
|
|
new GetPaginatedDiscountsQueryInput(
|
|
pagination: $pagination,
|
|
)
|
|
);
|
|
|
|
return view('bo.discounts.index', compact('discounts'));
|
|
}
|
|
|
|
public function create(GetDiscountFormDataQuery $query): View
|
|
{
|
|
$this->authorize('create', Discount::class);
|
|
|
|
$formData = $this->executor->execute(
|
|
$query,
|
|
new GetDiscountFormDataQueryInput()
|
|
);
|
|
|
|
return view('bo.discounts.create', [
|
|
'discountTypes' => $formData->discountTypes,
|
|
'existingProds' => $formData->existingProds,
|
|
'selectedProds' => $formData->selectedProds,
|
|
]);
|
|
}
|
|
|
|
public function store(StoreDiscountRequest $request, CreateDiscount $action): RedirectResponse
|
|
{
|
|
$this->authorize('create', Discount::class);
|
|
|
|
$discount = $this->executor->execute(
|
|
$action,
|
|
$request->toCreateDiscountInput(),
|
|
);
|
|
|
|
return to_route('bo.discounts.edit', $discount)
|
|
->with('success', trans('crud.messages.has_been_created', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.discounts', 1)),
|
|
]));
|
|
}
|
|
|
|
public function edit(Discount $discount, GetDiscountFormDataQuery $query): View
|
|
{
|
|
$this->authorize('update', $discount);
|
|
|
|
$formData = $this->executor->execute(
|
|
$query,
|
|
new GetDiscountFormDataQueryInput($discount)
|
|
);
|
|
|
|
return view('bo.discounts.edit', [
|
|
'discount' => $formData->discount,
|
|
'discountTypes' => $formData->discountTypes,
|
|
'existingProds' => $formData->existingProds,
|
|
'selectedProds' => $formData->selectedProds,
|
|
]);
|
|
}
|
|
|
|
public function update(UpdateDiscountRequest $request, Discount $discount, UpdateDiscount $action): RedirectResponse
|
|
{
|
|
$this->authorize('update', $discount);
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
$request->toUpdateDiscountInput($discount),
|
|
);
|
|
|
|
return to_route('bo.discounts.edit', $discount)
|
|
->with('success', trans('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.discounts', 1)),
|
|
]));
|
|
}
|
|
|
|
public function destroy(Discount $discount, DeleteDiscount $action): RedirectResponse
|
|
{
|
|
$this->authorize('delete', $discount);
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
new DeleteDiscountInput(discount: $discount),
|
|
);
|
|
|
|
return to_route('bo.discounts.index')
|
|
->with('warning', trans('crud.messages.has_been_deleted', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.discounts', 1)),
|
|
]));
|
|
}
|
|
}
|