1
0
forked from poc/pds

Add EquipmentMasterController with authorization and equipment retrieval logic with relevant API

This commit is contained in:
dhanabalan
2025-09-21 15:32:18 +05:30
parent f670793ff5
commit 4da6e97e6e
3 changed files with 157 additions and 1 deletions

View File

@@ -0,0 +1,143 @@
<?php
namespace App\Http\Controllers;
use App\Models\EquipmentMaster;
use App\Models\Machine;
use App\Models\Plant;
use Illuminate\Http\Request;
class EquipmentMasterController extends Controller
{
/**
* Display a listing of the resource.
*/
public function equipmentMasterData(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');
$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)
{
//
}
}

View File

@@ -1,5 +1,6 @@
<?php
//use App\Http\Controllers\CharacteristicsController;
use App\Http\Controllers\EquipmentMasterController;
use App\Http\Controllers\InvoiceValidationController;
use App\Http\Controllers\MachineController;
@@ -141,9 +142,11 @@ Route::get('testing/item/get-master-data', [TestingPanelController::class, 'get_
Route::get('machine/get-all-data', [MachineController::class, 'get_all_data']);
// Route::get('testing/equipment/get-master-data', [EquipmentMasterController::class, 'equipmentMasterData']);
Route::get('testing/equipment/get-master-data', [EquipmentMasterController::class, 'equipmentMasterData']);
Route::post('testing/reading/store-data', [TestingPanelController::class, 'store']);
Route::get('/get-pdf', [PdfController::class, 'getPdf']);
//Route::get('/get-characteristics/master-data', [CharacteristicsController::class, 'getCharacteristicsMaster']);

View File

@@ -1,6 +1,7 @@
<?php
use App\Mail\test;
use App\Models\EquipmentMaster;
use App\Models\InvoiceValidation;
use App\Models\Plant;
use Illuminate\Support\Facades\Mail;
@@ -10,6 +11,15 @@ use Illuminate\Support\Facades\Route;
return redirect('/admin');
});
Route::get('/download/{equipmentNumber}', function ($equipmentNumber) {
$model = EquipmentMaster::where('equipment_number', $equipmentNumber)->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');
// });