monev sampai target
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web\Program;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
use App\Models\Program\Framework;
|
||||
use App\Models\Program\Transformasi;
|
||||
use App\Models\Program\Aktivitas;
|
||||
|
||||
class AktivitasController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request, string $frameworkId, string $transformasiId): JsonResponse
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$transformasi = Transformasi::where('framework_id', $frameworkId)->find($transformasiId);
|
||||
if (!$transformasi) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data transformasi tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'kode' => ['required','string','max:255'],
|
||||
'nama' => ['required','string','max:255'],
|
||||
'jenis_aktivitas' => ['required','string','max:255', Rule::in(['tujuan', 'aktivitas']),],
|
||||
'indikator' => ['required','string'],
|
||||
'deskripsi' => ['required','string'],
|
||||
]);
|
||||
|
||||
Aktivitas::create([...$validated,
|
||||
'transformasi_id' => $transformasiId,
|
||||
'created_by' => auth()->id(),
|
||||
'updated_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Aktivitas berhasil ditambahkan.'
|
||||
], 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $frameworkId, string $transformasiId, string $id)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$aktivitas = Aktivitas::whereHas('transformasi', function ($query) use ($frameworkId) {
|
||||
$query->where('framework_id', $frameworkId);
|
||||
})->where('transformasi_id', $transformasiId)->find($id);
|
||||
|
||||
if (!$aktivitas) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data aktivitas tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json(['data' => $aktivitas, 'status' => 'success']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $frameworkId, string $transformasiId, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $frameworkId, string $transformasiId, string $id)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$aktivitas = Aktivitas::whereHas('transformasi', function ($query) use ($frameworkId) {
|
||||
$query->where('framework_id', $frameworkId);
|
||||
})->where('transformasi_id', $transformasiId)->find($id);
|
||||
|
||||
if (!$aktivitas) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data aktivitas tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'kode' => ['required','string','max:255'],
|
||||
'nama' => ['required','string','max:255'],
|
||||
'jenis_aktivitas' => ['required','string','max:255', Rule::in(['tujuan', 'aktivitas']),],
|
||||
'indikator' => ['required','string'],
|
||||
'deskripsi' => ['required','string'],
|
||||
]);
|
||||
|
||||
$aktivitas->update([...$validated,
|
||||
'updated_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Aktivitas berhasil diperbarui.'
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $frameworkId, string $transformasiId, string $id)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$aktivitas = Aktivitas::whereHas('transformasi', function ($query) use ($frameworkId) {
|
||||
$query->where('framework_id', $frameworkId);
|
||||
})->where('transformasi_id', $transformasiId)->find($id);
|
||||
|
||||
if (!$aktivitas) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data aktivitas tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$aktivitas->delete();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Aktivitas berhasil dihapus.'
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user