diff --git a/app/Http/Controllers/EquipmentMasterController.php b/app/Http/Controllers/EquipmentMasterController.php new file mode 100644 index 0000000..8a1087c --- /dev/null +++ b/app/Http/Controllers/EquipmentMasterController.php @@ -0,0 +1,143 @@ +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'); + + $workCenter = $request->header('work-center'); + + if (!$plantCode) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant Code value can't be empty" + ], 404); + } + else if (!$workCenter) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Work Center value can't be empty" + ], 404); + } + + $plant = Plant::where('code', $plantCode)->first(); + + if (!$plant) + { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant Code '{$plantCode}' not found!" + ], 404); + } + + $plantId = $plant->id; + + $machine = Machine::where('work_center', $workCenter)->first(); + + $machinePlant = Machine::where('work_center', $workCenter) + ->where('plant_id', $plantId) + ->first(); + + if (!$machine) + { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "work center '{$workCenter}' not found!" + ], 404); + } + + if (!$machinePlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Work center '{$workCenter}' not found for the plant code '{$plant->code}'!" + ], 404); + } + + $machineId = $machine->id; + + $machineExists = EquipmentMaster::where('plant_id', $plantId) + ->where('machine_id', $machineId) + ->first(); + + if (!$machineExists) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Work center '{$machine->work_center}' not found for the plant code '{$plant->code}' in Equipment Master!" + ], 404); + } + + $equipments = EquipmentMaster::where('plant_id', $plant->id) + ->where('machine_id', $machineId) + ->get([ + // 'name', + 'make', + 'model', + 'equipment_number', + 'calibrated_on', + 'next_calibration_date', + 'calibrated_by', + ]); + + + return response()->json([ + 'equipments' => $equipments + ], 200); + + + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + // + } + + /** + * Display the specified resource. + */ + public function show(string $id) + { + // + } + + /** + * 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 b7e1324..f375ee0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,5 +1,6 @@ firstOrFail(); + + if (! $model->attachment || ! Storage::disk('local')->exists($model->attachment)) { + abort(404, 'File not found.'); + } + return Storage::disk('local')->download($model->attachment); + })->name('download.attachment'); + // Route::get('/scheduler', function() { // Artisan::call('schedule:run'); // });