Added migration, model, policy, resource, importer, exporter, controller (Get API) with validation and functionality for Testing Line Visualization
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
This commit is contained in:
170
app/Http/Controllers/TestingLineVisualizationController.php
Normal file
170
app/Http/Controllers/TestingLineVisualizationController.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
// use App\Models\ItemCharacteristic;
|
||||
use App\Models\Plant;
|
||||
use App\Models\TestingLineVisualization;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Str;
|
||||
|
||||
class TestingLineVisualizationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function getTestingLineVisualization(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
|
||||
$headerAuth = $request->header('Authorization');
|
||||
$expectedToken = 'Bearer '.$expectedUser.':'.$expectedPw;
|
||||
|
||||
if ($headerAuth != $expectedToken) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!',
|
||||
], 401);
|
||||
}
|
||||
|
||||
$userName = $request->header('user-name');
|
||||
$plantCode = $request->header('plant-code');
|
||||
|
||||
Log::info('Testing Line Visualization GET API >>', ['user-name' => $userName, 'plant-code' => $plantCode]);
|
||||
|
||||
if (! $userName || $userName == null || $userName == '') {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "User name can't be empty!",
|
||||
], 404);
|
||||
} elseif ($userName == 'jothi') {
|
||||
$userName = 'Admin';
|
||||
}
|
||||
|
||||
if (! $plantCode || $plantCode == null || $plantCode == '') {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant code can't be empty!",
|
||||
], 404);
|
||||
} elseif (! is_numeric($plantCode)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant code '{$plantCode}' should contain only numeric values!",
|
||||
], 400);
|
||||
} elseif (Str::length($plantCode) < 4 || Str::length($plantCode) > 7) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant code '{$plantCode}' must be between 4 and 7 digits only!",
|
||||
], 400);
|
||||
} elseif (! preg_match('/^[1-9]\d{3,6}$/', $plantCode)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid plant code '{$plantCode}' found!",
|
||||
], 400);
|
||||
}
|
||||
|
||||
$plant = Plant::where('code', $plantCode)->first();
|
||||
if (! $plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant code '{$plantCode}' not found in plants table!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
$plantId = $plant->id;
|
||||
|
||||
$user = User::where('name', $userName)->first();
|
||||
|
||||
if (! $user) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "User name '{$userName}' not found in users table!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
$userPlant = User::where('name', $userName)->where('plant_id', $plantId)->first();
|
||||
|
||||
if (! $userPlant && ! $user->hasRole('Super Admin')) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "User name '{$userName}' not found for the plant code '{$plantCode}' in users table!",
|
||||
], 404);
|
||||
} elseif (! $user->hasRole(['Super Admin', 'Testing Line Visualization Manager', 'Testing Line Visualization Supervisor', 'Testing Line Visualization Employee'])) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "User '{$userName}' does not have rights!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
$jobAgaPlant = TestingLineVisualization::where('plant_id', $plantId)->first();
|
||||
if (! $jobAgaPlant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Reports not found for the plant code '{$plantCode}' in testing line visualization table!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
$records = TestingLineVisualization::where('plant_id', $plantId)->orderBy('id')->get();
|
||||
|
||||
$response = [];
|
||||
|
||||
foreach ($records as $row) {
|
||||
$response[] = [
|
||||
'test_bed_group' => $row->test_bed_group ?? '',
|
||||
'line_no' => $row->line_no ?? '',
|
||||
'pump_model' => $row->pump_model ?? '',
|
||||
'pump_type' => $row->pump_type ?? '',
|
||||
'motor_details' => $row->motor_details ?? '',
|
||||
'test_type' => $row->test_type ?? '',
|
||||
'flow' => $row->flow ?? '',
|
||||
'head' => $row->head ?? '',
|
||||
'run_time' => $row->run_time ?? '',
|
||||
'status' => $row->live_status ?? '',
|
||||
'observation_remarks' => $row->observation_remarks ?? '',
|
||||
'created_by' => ($row->created_by == 'Admin') ? 'jothi' : $row->created_by ?? '',
|
||||
'created_at' => $row->created_at ? $row->created_at->format('Y-m-d H:i:s') : '',
|
||||
'updated_by' => ($row->updated_by == 'Admin') ? 'jothi' : $row->updated_by ?? '',
|
||||
'updated_at' => $row->updated_at ? $row->updated_at->format('Y-m-d H:i:s') : '',
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'testing_line_visualizations' => $response,
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user