Added method for 'obd/get-test-datas' GET API
This commit is contained in:
@@ -337,6 +337,59 @@ class ObdController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Route::get('obd/get-test-datas', [ObdController::class, 'get_test']);
|
||||||
|
public function get_test(Request $request)
|
||||||
|
{
|
||||||
|
$expectedUser = env('API_AUTH_USER');
|
||||||
|
$expectedPw = env('API_AUTH_PW');
|
||||||
|
|
||||||
|
$header_auth = $request->header('Authorization');
|
||||||
|
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||||
|
|
||||||
|
if ("Bearer " . $expectedToken !== $header_auth)
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => 'Invalid authorization token'
|
||||||
|
], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$plantCode = $request->header('plant-code');
|
||||||
|
if (empty($plantCode))
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Plant code can't be empty"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
else if(Str::length($plantCode) < 4 || !is_numeric($plantCode))
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Plant code should contain minimum 4 digits numeric values only!"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$plantId = Plant::where('code', $plantCode)->value('id');
|
||||||
|
|
||||||
|
if (!$plantId)
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Plant code not found"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return response("Successfully GET request Received", 200)->header('Content-Type', 'text/plain');
|
||||||
|
}
|
||||||
|
catch (\Exception $e)
|
||||||
|
{
|
||||||
|
return response("ERROR: GET test data server error", 500)->header('Content-Type', 'text/plain');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Route::post('obd/store-test-data', [ObdController::class, 'test'])
|
//Route::post('obd/store-test-data', [ObdController::class, 'test'])
|
||||||
public function test(Request $request)
|
public function test(Request $request)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user