ekosistem dan framework
This commit is contained in:
@@ -69,6 +69,16 @@ class TargetController extends Controller
|
||||
'nullable',
|
||||
'boolean'
|
||||
],
|
||||
'tipe_realisasi' => [
|
||||
'nullable',
|
||||
'string',
|
||||
Rule::in(['manual', 'referensi'])
|
||||
],
|
||||
'value_query' => [
|
||||
Rule::requiredIf($request->tipe_realisasi === 'referensi'),
|
||||
'nullable',
|
||||
'string'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -77,9 +87,6 @@ class TargetController extends Controller
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request, string $frameworkId, string $transformasiId, string $aktivitasId): JsonResponse
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
@@ -109,12 +116,32 @@ class TargetController extends Controller
|
||||
], 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
public function show(string $frameworkId, string $transformasiId, string $aktivitasId, string $id)
|
||||
{
|
||||
//
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$target = Target::with('realisasi', 'latestRealisasi')
|
||||
->whereHas('aktivitas.transformasi', function ($query) use ($frameworkId) {
|
||||
$query->where('framework_id', $frameworkId);
|
||||
})
|
||||
->whereHas('aktivitas', function ($query) use ($transformasiId) {
|
||||
$query->where('transformasi_id', $transformasiId);
|
||||
})
|
||||
->where('aktivitas_id', $aktivitasId)->find($id);
|
||||
|
||||
if (!$target) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data target tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $target
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,16 +155,67 @@ class TargetController extends Controller
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
public function update(Request $request, string $frameworkId, string $transformasiId, string $aktivitasId, string $id)
|
||||
{
|
||||
//
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$target = Target::whereHas('aktivitas.transformasi', function ($query) use ($frameworkId) {
|
||||
$query->where('framework_id', $frameworkId);
|
||||
})
|
||||
->whereHas('aktivitas', function ($query) use ($transformasiId) {
|
||||
$query->where('transformasi_id', $transformasiId);
|
||||
})
|
||||
->where('aktivitas_id', $aktivitasId)->find($id);
|
||||
|
||||
if (!$target) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data target tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validated = $this->validated($request);
|
||||
$target->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)
|
||||
public function destroy(string $frameworkId, string $transformasiId, string $aktivitasId, string $id)
|
||||
{
|
||||
//
|
||||
if (!Gate::any(['super_admin', 'admin'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$target = Target::whereHas('aktivitas.transformasi', function ($query) use ($frameworkId) {
|
||||
$query->where('framework_id', $frameworkId);
|
||||
})
|
||||
->whereHas('aktivitas', function ($query) use ($transformasiId) {
|
||||
$query->where('transformasi_id', $transformasiId);
|
||||
})
|
||||
->where('aktivitas_id', $aktivitasId)->find($id);
|
||||
|
||||
if (!$target) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data target tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$target->update([
|
||||
'deleted_by' => auth()->id(),
|
||||
]);
|
||||
$target->delete();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Target berhasil dihapus.'
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user