118 lines
4.2 KiB
PHP
118 lines
4.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Actions\PickupExceptions\CreatePickupException;
|
|
use App\Actions\PickupExceptions\CreatePickupExceptionInput;
|
|
use App\Actions\PickupExceptions\DeletePickupException;
|
|
use App\Actions\PickupExceptions\DeletePickupExceptionInput;
|
|
use App\Actions\PickupExceptions\UpdatePickupException;
|
|
use App\Actions\PickupExceptions\UpdatePickupExceptionInput;
|
|
use App\Contracts\Executor;
|
|
use App\Dto\PickupExceptionDto;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\PickupExceptions\StorePickupExceptionRequest;
|
|
use App\Http\Requests\Bo\PickupExceptions\UpdatePickupExceptionRequest;
|
|
use App\Models\PickupException;
|
|
use App\Queries\PickupExceptions\GetPaginatedPickupExceptionsQuery;
|
|
use App\Queries\PickupExceptions\GetPaginatedPickupExceptionsQueryInput;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
|
|
class PickupExceptionsController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly Executor $executor,
|
|
) {
|
|
}
|
|
|
|
public function index(Request $request, GetPaginatedPickupExceptionsQuery $query): View
|
|
{
|
|
$this->authorize('viewAny', PickupException::class);
|
|
|
|
$pickupExceptions = $this->executor->execute(
|
|
$query,
|
|
new GetPaginatedPickupExceptionsQueryInput(
|
|
pagination: $request->pagination(),
|
|
),
|
|
);
|
|
|
|
return view('bo.pickup-exceptions.index', compact('pickupExceptions'));
|
|
}
|
|
|
|
public function create(): View
|
|
{
|
|
$this->authorize('create', PickupException::class);
|
|
|
|
return view('bo.pickup-exceptions.create');
|
|
}
|
|
|
|
public function store(StorePickupExceptionRequest $request, CreatePickupException $action): RedirectResponse
|
|
{
|
|
$this->authorize('create', PickupException::class);
|
|
|
|
$pickupException = $this->executor->execute(
|
|
$action,
|
|
new CreatePickupExceptionInput(
|
|
date: $request->string('date')->value(),
|
|
label: $request->string('label')->value(),
|
|
repeatable: $request->boolean('repeatable'),
|
|
repeat_frequency: $request->toRepeatFrequency(),
|
|
),
|
|
);
|
|
|
|
return to_route('bo.pickup-exceptions.edit', $pickupException)
|
|
->with('success', trans('crud.messages.has_been_created', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.pickup-exceptions', 1)),
|
|
]));
|
|
}
|
|
|
|
public function edit(PickupException $pickupException): View
|
|
{
|
|
$this->authorize('update', $pickupException);
|
|
|
|
$pickupException = PickupExceptionDto::fromModel($pickupException);
|
|
|
|
return view('bo.pickup-exceptions.edit', compact('pickupException'));
|
|
}
|
|
|
|
public function update(UpdatePickupExceptionRequest $request, PickupException $pickupException, UpdatePickupException $action): RedirectResponse
|
|
{
|
|
$this->authorize('update', $pickupException);
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
new UpdatePickupExceptionInput(
|
|
pickupException: $pickupException,
|
|
date: $request->string('date')->value(),
|
|
label: $request->string('label')->value(),
|
|
repeatable: $request->boolean('repeatable'),
|
|
repeat_frequency: $request->toRepeatFrequency(),
|
|
),
|
|
);
|
|
|
|
return to_route('bo.pickup-exceptions.edit', $pickupException)
|
|
->with('success', trans('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.pickup-exceptions', 1)),
|
|
]));
|
|
}
|
|
|
|
public function destroy(PickupException $pickupException, DeletePickupException $action): RedirectResponse
|
|
{
|
|
$this->authorize('delete', $pickupException);
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
new DeletePickupExceptionInput(pickupException: $pickupException),
|
|
);
|
|
|
|
return to_route('bo.pickup-exceptions.index')
|
|
->with('warning', trans('crud.messages.has_been_deleted', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.pickup-exceptions', 1)),
|
|
]));
|
|
}
|
|
}
|