From e78c2a2612536b55dc4015c871faace1b76a83df Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 30 Mar 2023 12:36:10 +0700 Subject: [PATCH] Task #860qcx5ep API hierarchy --- .../Controllers/HierarchyFtthController.php | 97 +++++++++++++++++++ app/Models/HierarchyFtth.php | 17 ++++ routes/web.php | 7 ++ 3 files changed, 121 insertions(+) create mode 100644 app/Http/Controllers/HierarchyFtthController.php create mode 100644 app/Models/HierarchyFtth.php diff --git a/app/Http/Controllers/HierarchyFtthController.php b/app/Http/Controllers/HierarchyFtthController.php new file mode 100644 index 0000000..e172ddc --- /dev/null +++ b/app/Http/Controllers/HierarchyFtthController.php @@ -0,0 +1,97 @@ +json($hierarchyFtths); + } catch (\Exception $e) { + return response()->json([ + 'message' => 'Failed to retrieve hierarchy FTTHs.', + 'error' => $e->getMessage() + ], 500); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_hierarchy_ftth'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function store(Request $request) + { + try { + $attributes = $request->only(['name', 'parent_id', 'project_id']); + $hierarchyFtth = HierarchyFtth::create($attributes); + + return response()->json([ + 'message' => 'Hierarchy FTTH created successfully.', + 'data' => $hierarchyFtth + ]); + } catch (\Exception $e) { + return response()->json([ + 'message' => 'Failed to create hierarchy FTTH.', + 'error' => $e->getMessage() + ], 500); + } + } + + public function show(HierarchyFtth $hierarchyFtth) + { + try { + return response()->json($hierarchyFtth); + } catch (\Exception $e) { + return response()->json([ + 'message' => 'Failed to retrieve hierarchy FTTH.', + 'error' => $e->getMessage() + ], 500); + } + } + + public function update(Request $request, HierarchyFtth $hierarchyFtth) + { + try { + $hierarchyFtth->update($request->all()); + + return response()->json([ + 'message' => 'Hierarchy FTTH updated successfully.', + 'data' => $hierarchyFtth + ]); + } catch (\Exception $e) { + return response()->json([ + 'message' => 'Failed to update hierarchy FTTH.', + 'error' => $e->getMessage() + ], 500); + } + } + + public function destroy(HierarchyFtth $hierarchyFtth) + { + try { + $hierarchyFtth->delete(); + + return response()->json([ + 'message' => 'Hierarchy FTTH deleted successfully.', + 'data' => $hierarchyFtth + ]); + } catch (\Exception $e) { + return response()->json([ + 'message' => 'Failed to delete hierarchy FTTH.', + 'error' => $e->getMessage() + ], 500); + } + } +} diff --git a/app/Models/HierarchyFtth.php b/app/Models/HierarchyFtth.php new file mode 100644 index 0000000..649f1e5 --- /dev/null +++ b/app/Models/HierarchyFtth.php @@ -0,0 +1,17 @@ +group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->put('/project-comment/update/{id}', 'ProjectCommentController@update'); $router->post('/project-comment/search', 'ProjectCommentController@search'); + $router->get('/hierarchy-ftths', 'HierarchyFtthController@index'); + $router->post('/hierarchy-ftths', 'HierarchyFtthController@store'); + $router->post('/hierarchy-ftths/search', 'HierarchyFtthController@search'); + $router->get('/hierarchy-ftths/{hierarchyFtth}', 'HierarchyFtthController@show'); + $router->put('/hierarchy-ftths/{hierarchyFtth}', 'HierarchyFtthController@update'); + $router->delete('/hierarchy-ftths/{hierarchyFtth}', 'HierarchyFtthController@destroy'); + $router->post('/map-monitoring/search', 'MapMonitoringController@search'); });