ekosistem dan framework
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web\Program;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
use App\Models\Program\Framework;
|
||||
use App\Models\Program\Realisasi;
|
||||
|
||||
class RealisasiController extends Controller
|
||||
{
|
||||
public function index(Request $request): View
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$framework = Framework::when($request->has('frameworkid'), function ($query) use ($request) {
|
||||
$query->where('id', $request->frameworkid);
|
||||
})->latest()->first();
|
||||
if ($framework == null) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return view('program.realisasi.index', compact('framework'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'target_id' => ['required', 'integer', 'exists:program_target,id'],
|
||||
'realisasi_integer' => ['nullable', 'integer'],
|
||||
'realisasi_float' => ['nullable', 'numeric'],
|
||||
'realisasi_boolean' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$realisasi = Realisasi::create([...$validated,
|
||||
'created_by' => auth()->id(),
|
||||
'updated_by' => auth()->id()
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Target berhasil ditambahkan.'
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function show(string $id)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$realisasi = Realisasi::with('target', 'target.aktivitas', 'target.aktivitas.transformasi')
|
||||
->find($id);
|
||||
if (!$realisasi) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data realisasi tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $realisasi
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function update(Request $request, string $id): JsonResponse
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$realisasi = Realisasi::find($id);
|
||||
if (!$realisasi) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data realisasi tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'target_id' => ['required', 'integer', 'exists:program_target,id'],
|
||||
'realisasi_integer' => ['nullable', 'integer'],
|
||||
'realisasi_float' => ['nullable', 'numeric'],
|
||||
'realisasi_boolean' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$realisasi->update([...$validated,
|
||||
'updated_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Target berhasil diperbarui.'
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user