147 lines
4.4 KiB
PHP
147 lines
4.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Actions\Shops\CreateShop;
|
|
use App\Actions\Shops\DeleteShop;
|
|
use App\Actions\Shops\DeleteShopInput;
|
|
use App\Actions\Shops\UpdateShop;
|
|
use App\Actions\Shops\UpdateShopPickupExceptions;
|
|
use App\Contracts\Executor;
|
|
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\Models\Shop;
|
|
use App\Queries\Shops\GetPaginatedShopsQuery;
|
|
use App\Queries\Shops\GetPaginatedShopsQueryInput;
|
|
use App\Queries\Shops\GetShopPickupExceptionsQuery;
|
|
use App\Queries\Shops\GetShopPickupExceptionsQueryInput;
|
|
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: $request->pagination(),
|
|
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)),
|
|
]));
|
|
}
|
|
}
|