diff --git a/app/Http/Controllers/LineController.php b/app/Http/Controllers/LineController.php new file mode 100644 index 0000000..bc552b7 --- /dev/null +++ b/app/Http/Controllers/LineController.php @@ -0,0 +1,130 @@ +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 ($plantCode == null || $plantCode == '') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant code can't be empty!", + ], 400); + } elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid plant code found!', + ], 400); + } + + $plant = Plant::where('code', $plantCode)->first(); + if (! $plant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant Code '{$plantCode}' not found!", + ], 400); + } + + $plantId = $plant->id; + + $lines = Line::where('plant_id', $plantId)->get(); + $linesData = $lines->map(function ($line) { + return [ + 'name' => $line->name, + 'type' => $line->type, + 'no_of_operations' => (string) $line->no_of_operation, + ]; + }); + + return response()->json([ + 'lines' => $linesData, + ]); + } + + /** + * Display the all resource. + */ + public function get_all_data(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); + } + + $lines = Line::with('plant')->orderBy('plant_id')->get(); + $linesData = $lines->map(function ($line) { + return [ + 'plant' => $line->plant ? $line->plant->name : '', // Get plant name + 'name' => $line->name, + 'type' => $line->type, + 'no_of_operations' => (string) $line->no_of_operation, + ]; + }); + + return response()->json([ + 'lines' => $linesData, + ]); + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } +} diff --git a/routes/api.php b/routes/api.php index b8b529f..7daf149 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,6 +3,7 @@ use App\Http\Controllers\CharacteristicsController; use App\Http\Controllers\EquipmentMasterController; use App\Http\Controllers\InvoiceValidationController; +use App\Http\Controllers\LineController; use App\Http\Controllers\MachineController; use App\Http\Controllers\MfmParameterController; use App\Http\Controllers\ModuleChartController; @@ -75,6 +76,12 @@ Route::post('obd/store-data', [ObdController::class, 'store_obd']); Route::get('plant/get-all-data', [PlantController::class, 'get_all_data']); +// Line + +Route::get('line/get-data', [LineController::class, 'get_data']); + +Route::get('line/get-all-data', [LineController::class, 'get_all_data']); + // Sticker Master Model Type Route::get('sticker/get-master-type-data', [StickerMasterController::class, 'get_master_type']); @@ -173,10 +180,6 @@ Route::get('get-pdf', [PdfController::class, 'getPdf']); // processorder/get-pdf Route::get('laser/item/get-quality-master-data', [StickerMasterController::class, 'get_quality_master']); -// ..Model Master - Laser - -// Route::get('laser/model-master/get', [StickerMasterController::class, 'get_master']); - // ..Part Validation Route::get('laser/item/get-master-data', [StickerMasterController::class, 'get_master']);