Browse Source

Merge pull request 'staging upload 23-03-30' (#9) from staging into master

Reviewed-on: ordo/adw-backend#9
pull/3/head
ibnu 2 years ago
parent
commit
2d29d11dad
  1. 97
      app/Http/Controllers/HierarchyFtthController.php
  2. 17
      app/Models/HierarchyFtth.php
  3. 7
      routes/web.php

97
app/Http/Controllers/HierarchyFtthController.php

@ -0,0 +1,97 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\HierarchyFtth;
class HierarchyFtthController extends Controller
{
public function index()
{
try {
$hierarchyFtths = HierarchyFtth::all();
return response()->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);
}
}
}

17
app/Models/HierarchyFtth.php

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class HierarchyFtth extends Model
{
protected $table = "m_hierarchy_ftth";
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'parent_id', 'project_id', 'created_at', 'updated_at'
];
}

7
routes/web.php

@ -439,6 +439,13 @@ $router->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');
});

Loading…
Cancel
Save