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.
148 lines
4.5 KiB
PHP
148 lines
4.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Contracts\Executor;
|
|
use App\Cqs\Actions\Shops\CreateShop;
|
|
use App\Cqs\Actions\Shops\DeleteShop;
|
|
use App\Cqs\Actions\Shops\DeleteShopInput;
|
|
use App\Cqs\Actions\Shops\UpdateShop;
|
|
use App\Cqs\Actions\Shops\UpdateShopPickupExceptions;
|
|
use App\Cqs\Queries\Shops\GetPaginatedShopsQuery;
|
|
use App\Cqs\Queries\Shops\GetPaginatedShopsQueryInput;
|
|
use App\Cqs\Queries\Shops\GetShopPickupExceptionsQuery;
|
|
use App\Cqs\Queries\Shops\GetShopPickupExceptionsQueryInput;
|
|
use App\Dto\ShopDto;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Shops\IndexShopRequest;
|
|
use App\Http\Requests\Bo\Shops\StoreShopRequest;
|
|
use App\Http\Requests\Bo\Shops\UpdateShopPickupExceptionsRequest;
|
|
use App\Http\Requests\Bo\Shops\UpdateShopRequest;
|
|
use App\Lib\Helpers\RequestHelper;
|
|
use App\Models\Shop;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ShopsController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly Executor $executor,
|
|
) {
|
|
}
|
|
|
|
public function index(IndexShopRequest $request, GetPaginatedShopsQuery $query): View
|
|
{
|
|
$this->authorize('viewAny', Shop::class);
|
|
|
|
$output = $this->executor->execute(
|
|
$query,
|
|
new GetPaginatedShopsQueryInput(
|
|
pagination: RequestHelper::pagination($request),
|
|
pickupExceptionId: $request->toPickupExceptionId(),
|
|
),
|
|
);
|
|
|
|
return view('bo.shops.index', [
|
|
'shops' => $output->shops,
|
|
'pickupExceptions' => $output->pickupExceptions,
|
|
]);
|
|
}
|
|
|
|
public function create(): View
|
|
{
|
|
$this->authorize('create', Shop::class);
|
|
|
|
return view('bo.shops.create');
|
|
}
|
|
|
|
public function store(StoreShopRequest $request, CreateShop $action): RedirectResponse
|
|
{
|
|
$this->authorize('create', Shop::class);
|
|
|
|
$shop = $this->executor->execute(
|
|
$action,
|
|
$request->toCreateShopInput(),
|
|
);
|
|
|
|
return to_route('bo.shops.edit', $shop)
|
|
->with('success', trans('crud.messages.has_been_created', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.shops', 1)),
|
|
]));
|
|
}
|
|
|
|
public function edit(Shop $shop): View
|
|
{
|
|
$this->authorize('update', $shop);
|
|
|
|
$shop = ShopDto::fromModel($shop);
|
|
|
|
return view('bo.shops.edit', compact('shop'));
|
|
}
|
|
|
|
public function update(UpdateShopRequest $request, Shop $shop, UpdateShop $action): RedirectResponse
|
|
{
|
|
$this->authorize('update', $shop);
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
$request->toUpdateShopInput($shop),
|
|
);
|
|
|
|
return to_route('bo.shops.edit', $shop)
|
|
->with('success', trans('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.shops', 1)),
|
|
]));
|
|
}
|
|
|
|
public function destroy(Shop $shop, DeleteShop $action): RedirectResponse
|
|
{
|
|
$this->authorize('delete', $shop);
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
new DeleteShopInput(shop: $shop),
|
|
);
|
|
|
|
return to_route('bo.shops.index')
|
|
->with('warning', trans('crud.messages.has_been_deleted', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.shops', 1)),
|
|
]));
|
|
}
|
|
|
|
public function pickupExceptionsEdit(Shop $shop, GetShopPickupExceptionsQuery $query): View
|
|
{
|
|
$this->authorize('pickupExceptionUpdate', $shop);
|
|
|
|
$output = $this->executor->execute(
|
|
$query,
|
|
new GetShopPickupExceptionsQueryInput(shop: $shop),
|
|
);
|
|
|
|
return view('bo.shops.pickup-exceptions', [
|
|
'shop' => $output->shop,
|
|
'pickupExceptions' => $output->pickupExceptions,
|
|
'pickupDay' => $output->pickupDay,
|
|
'pickupPeriod' => $output->pickupPeriod,
|
|
]);
|
|
}
|
|
|
|
public function pickupExceptionsUpdate(
|
|
UpdateShopPickupExceptionsRequest $request,
|
|
Shop $shop,
|
|
UpdateShopPickupExceptions $action
|
|
): RedirectResponse {
|
|
$this->authorize('pickupExceptionUpdate', $shop);
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
$request->toUpdateShopPickupExceptionsInput($shop),
|
|
);
|
|
|
|
return back()->with('success', trans('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.shops', 1)),
|
|
]));
|
|
}
|
|
}
|