|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Models\ProjectCharter;
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
|
|
class ProjectCharterController extends Controller
|
|
|
|
{
|
|
|
|
public function add(Request $request)
|
|
|
|
{
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
|
'proyek_id' => 'required|integer',
|
|
|
|
'description' => 'nullable',
|
|
|
|
'objectives' => 'nullable',
|
|
|
|
'project_is_considered_successful' => 'nullable',
|
|
|
|
'participants' => 'nullable',
|
|
|
|
'available_resources' => 'nullable',
|
|
|
|
'milestones' => 'nullable',
|
|
|
|
'potential_risks' => 'nullable',
|
|
|
|
'approval' => 'nullable',
|
|
|
|
'created_by' => 'nullable|string|max:80',
|
|
|
|
'updated_by' => 'nullable|string|max:80',
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'add data project charter failed!', 'code' => 400], 400);
|
|
|
|
}
|
|
|
|
$validated = $validator->validated();
|
|
|
|
|
|
|
|
$validated['created_by'] = $this->currentName;
|
|
|
|
|
|
|
|
$result = ProjectCharter::create($validated);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'add data project charter successfully!', 'code' => 200], 200);
|
|
|
|
} else {
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'add data project charter failed!', 'code' => 400], 400);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
|
|
|
if (empty($id)) {
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = ProjectCharter::find($id);
|
|
|
|
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
|
'proyek_id' => 'required|integer',
|
|
|
|
'description' => 'nullable',
|
|
|
|
'objectives' => 'nullable',
|
|
|
|
'project_is_considered_successful' => 'nullable',
|
|
|
|
'participants' => 'nullable',
|
|
|
|
'available_resources' => 'nullable',
|
|
|
|
'milestones' => 'nullable',
|
|
|
|
'potential_risks' => 'nullable',
|
|
|
|
'approval' => 'nullable',
|
|
|
|
'created_by' => 'nullable|string|max:80',
|
|
|
|
'updated_by' => 'nullable|string|max:80',
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'data project failed updated!', 'code' => 400], 400);
|
|
|
|
}
|
|
|
|
$validated = $validator->validated();
|
|
|
|
|
|
|
|
if ($data) {
|
|
|
|
$result = $data->update($validated);
|
|
|
|
if ($result) {
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'data project successfully updated!', 'code' => 200], 200);
|
|
|
|
} else {
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'data project failed updated!', 'code' => 400], 400);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'data project not found!', 'code' => 400], 400);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function search(Request $request)
|
|
|
|
{
|
|
|
|
$payload = $request->all();
|
|
|
|
$dataBuilder = $this->setUpPayload($payload, 'project_charter');
|
|
|
|
$builder = $dataBuilder['builder'];
|
|
|
|
$countBuilder = $dataBuilder['count'];
|
|
|
|
$dataGet = $builder->get();
|
|
|
|
$totalRecord = $countBuilder->count();
|
|
|
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
|
|
|
|
}
|
|
|
|
}
|