Merge pull request 'Added line get api function with validations and line controller' (#921) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 27s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 27s
Reviewed-on: #921
This commit was merged in pull request #921.
This commit is contained in:
130
app/Http/Controllers/LineController.php
Normal file
130
app/Http/Controllers/LineController.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LineController 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 get_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);
|
||||
}
|
||||
|
||||
$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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user