Added all modules with fg count logic

This commit is contained in:
dhanabalan
2025-07-12 11:04:31 +05:30
parent 642053653c
commit 1465734acd
6 changed files with 553 additions and 168 deletions

View File

@@ -16,6 +16,62 @@ class ModulePlantLineController extends Controller
//
}
// public function get_modulePlantLine(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);
// }
// $plantName = $request->header('plant-name');
// if (empty($plantName))
// {
// return response()->json([
// 'status_code' => 'ERROR',
// 'status_description' => "Plant Name can't be empty!"
// ], 404);
// }
// $plant = Plant::where('name', $plantName)->first();
// if (!$plant) {
// return response()->json([
// 'status_code' => 'ERROR',
// 'status_description' => "Plant '{$plantName}' not found!"
// ], 404);
// }
// $lineNames = Line::where('plant_id', $plant->id)
// ->orderBy('created_at', 'asc')
// ->pluck('name');
// if ($lineNames->isEmpty()) {
// return response()->json([
// 'status_code' => 'ERROR',
// 'status_description' => "No lines found for plant '{$plantName}'"
// ], 404);
// }
// // Prepend 'All Lines'
// $lineNames->prepend('All Lines')->values();
// return response()->json([
// 'status_code' => 'SUCCESS',
// 'status_description' => $lineNames,
// ], 200);
// }
public function get_modulePlantLine(Request $request)
{
$expectedUser = env('API_AUTH_USER');
@@ -24,8 +80,7 @@ class ModulePlantLineController extends Controller
$header_auth = $request->header('Authorization');
$expectedToken = $expectedUser . ':' . $expectedPw;
if ("Bearer " . $expectedToken != $header_auth)
{
if ("Bearer " . $expectedToken != $header_auth) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!'
@@ -34,8 +89,7 @@ class ModulePlantLineController extends Controller
$plantName = $request->header('plant-name');
if (empty($plantName))
{
if (empty($plantName)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant Name can't be empty!"
@@ -51,39 +105,31 @@ class ModulePlantLineController extends Controller
], 404);
}
// // Get line names for the plant
// $lineNames = Line::where('plant_id', $plant->id)
// ->orderBy('created_at', 'asc')
// ->pluck('name')
// ->prepend('All Lines')
// ->values();
// return response()->json([
// 'status_code' => 'SUCCESS',
// 'status_description' => $lineNames,
// ], 200);
$lineNames = Line::where('plant_id', $plant->id)
// Load only lines NOT equal to FG Line
$nonFgLines = Line::where('plant_id', $plant->id)
->where('type', '!=', 'FG Line')
->orderBy('created_at', 'asc')
->pluck('name');
->pluck('name')
->toArray();
if ($lineNames->isEmpty()) {
if (empty($nonFgLines)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "No lines found for plant '{$plantName}'"
'status_description' => "No non-FG lines found for plant '{$plantName}'"
], 404);
}
// Prepend 'All Lines'
$lineNames->prepend('All Lines')->values();
// Add "All Lines" to beginning and "FG Lines" at the end
array_unshift($nonFgLines, 'All Lines');
$nonFgLines[] = 'FG Lines';
return response()->json([
'status_code' => 'SUCCESS',
'status_description' => $lineNames,
'status_description' => $nonFgLines,
], 200);
}
/**
* Store a newly created resource in storage.
*/