74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Manage;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\Manage\RestockRequest;
|
|
use App\Http\Requests\PaginatedRequest;
|
|
use App\Models\Restock;
|
|
use App\Services\Admin\Manage\RestockService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class RestockController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly RestockService $service,
|
|
) {}
|
|
|
|
public function index(PaginatedRequest $request): Response
|
|
{
|
|
return Inertia::render('admin/manage/restock/index', [
|
|
'restocks' => $this->service->paginated(
|
|
...$request->validatedWithDefaults(),
|
|
),
|
|
]);
|
|
}
|
|
|
|
public function create(): Response
|
|
{
|
|
return Inertia::render('admin/manage/restock/create', [
|
|
'data' => $this->service->getForCreate(),
|
|
]);
|
|
}
|
|
|
|
public function store(RestockRequest $request): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->create($request->validated()),
|
|
'Restock berhasil ditambahkan.',
|
|
'admin.manage.restocks.index',
|
|
'admin.manage.restocks.create'
|
|
);
|
|
}
|
|
|
|
public function edit(Restock $restock): Response
|
|
{
|
|
return Inertia::render('admin/manage/restock/edit', [
|
|
'restock' => $this->service->getForEdit($restock),
|
|
'data' => $this->service->getForCreate(),
|
|
]);
|
|
}
|
|
|
|
public function update(RestockRequest $request, Restock $restock): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->update($restock, $request->validated()),
|
|
'Restock berhasil diperbarui.',
|
|
'admin.manage.restocks.index',
|
|
'admin.manage.restocks.edit',
|
|
['restock' => $restock]
|
|
);
|
|
}
|
|
|
|
public function destroy(Restock $restock): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->delete($restock),
|
|
'Restock berhasil dihapus.',
|
|
'admin.manage.restocks.index'
|
|
);
|
|
}
|
|
}
|