monev sampai target
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
<?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;
|
||||
use App\Models\Program\Target;
|
||||
|
||||
class TargetController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
private function validated(Request $request) {
|
||||
return $request->validate([
|
||||
'variabel' => ['required','string','max:255'],
|
||||
'tipe' => ['required','string','max:255', Rule::in(['integer', 'float', 'boolean']),],
|
||||
'target_integer' => [
|
||||
Rule::requiredIf($request->tipe === 'integer'),
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'target_float' => [
|
||||
Rule::requiredIf($request->tipe === 'float'),
|
||||
'nullable',
|
||||
'numeric'
|
||||
],
|
||||
'target_boolean' => [
|
||||
Rule::requiredIf($request->tipe === 'boolean'),
|
||||
'nullable',
|
||||
'boolean'
|
||||
],
|
||||
'baseline_integer' => [
|
||||
Rule::requiredIf($request->tipe === 'integer'),
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'baseline_float' => [
|
||||
Rule::requiredIf($request->tipe === 'float'),
|
||||
'nullable',
|
||||
'numeric'
|
||||
],
|
||||
'baseline_boolean' => [
|
||||
Rule::requiredIf($request->tipe === 'boolean'),
|
||||
'nullable',
|
||||
'boolean'
|
||||
],
|
||||
'realisasi_integer' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'realisasi_float' => [
|
||||
'nullable',
|
||||
'numeric'
|
||||
],
|
||||
'realisasi_boolean' => [
|
||||
'nullable',
|
||||
'boolean'
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(string $frameworkId, string $transformasiId, string $aktivitasId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$aktivitas = Aktivitas::whereHas('transformasi', function ($query) use ($frameworkId) {
|
||||
$query->where('framework_id', $frameworkId);
|
||||
})->where('transformasi_id', $transformasiId)->find($aktivitasId);
|
||||
if (!$aktivitas) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data aktivitas tidak ditemukan.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validated = $this->validated($request);
|
||||
Target::create([...$validated,
|
||||
'aktivitas_id' => $aktivitasId,
|
||||
'created_by' => auth()->id(),
|
||||
'updated_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Target berhasil ditambahkan.'
|
||||
], 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user