Browse Source

Minor fix

pull/3/head
Wahyu Ramadhan 2 years ago
parent
commit
3144508921
  1. 34
      app/Http/Controllers/HierarchyFtthController.php
  2. 7
      routes/web.php

34
app/Http/Controllers/HierarchyFtthController.php

@ -49,8 +49,9 @@ class HierarchyFtthController extends Controller
}
}
public function show(HierarchyFtth $hierarchyFtth)
public function show($id)
{
$hierarchyFtth = HierarchyFtth::where('id', $id)->first();
try {
return response()->json($hierarchyFtth);
} catch (\Exception $e) {
@ -61,8 +62,9 @@ class HierarchyFtthController extends Controller
}
}
public function update(Request $request, HierarchyFtth $hierarchyFtth)
public function update(Request $request, $id)
{
$hierarchyFtth = HierarchyFtth::where('id', $id)->first();
try {
$hierarchyFtth->update($request->all());
@ -78,8 +80,9 @@ class HierarchyFtthController extends Controller
}
}
public function destroy(HierarchyFtth $hierarchyFtth)
public function destroy($id)
{
$hierarchyFtth = HierarchyFtth::where('id', $id)->first();
try {
$hierarchyFtth->delete();
@ -94,4 +97,29 @@ class HierarchyFtthController extends Controller
], 500);
}
}
public function getTreeByProject($project_id)
{
$data = HierarchyFtth::where('project_id', $project_id)->whereNull('parent_id')->orderByRaw('id ASC')->get();
$finalData = [];
foreach($data as $objRow){
$objRow->children = $this->getChildren($project_id, $objRow->id);
$objRow->key = rand(1, 1000);
$finalData[] = $objRow;
}
return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200);
}
private function getChildren($project_id, $parent_id)
{
$finalData = [];
$data = HierarchyFtth::where('project_id', $project_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get();
foreach($data as $objRow){
$objRow->key = rand(1, 1000);
$objRow->children = $this->getChildren($project_id, $objRow->id);
$finalData[] = $objRow;
}
return $finalData;
}
}

7
routes/web.php

@ -442,9 +442,10 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$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->get('/hierarchy-ftths/{id}', 'HierarchyFtthController@show');
$router->put('/hierarchy-ftths/{id}', 'HierarchyFtthController@update');
$router->delete('/hierarchy-ftths/{id}', 'HierarchyFtthController@destroy');
$router->get('/hierarchy-ftths/tree/{project_id}', 'HierarchyFtthController@getTreeByProject');
$router->post('/map-monitoring/search', 'MapMonitoringController@search');
});

Loading…
Cancel
Save