Added module controller and api logic
This commit is contained in:
99
app/Http/Controllers/ModuleController.php
Normal file
99
app/Http/Controllers/ModuleController.php
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\ModuleList;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class ModuleController 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 show(string $id)
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// }
|
||||||
|
|
||||||
|
public function get_module(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
$moduleName = $request->header('module-name');
|
||||||
|
|
||||||
|
if (empty($moduleName))
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Module Name can't be empty!"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$headerValue = $request->header('module-name');
|
||||||
|
|
||||||
|
if ($headerValue != 'Module List') {
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Invalid value for 'module-name' header!"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqueModules = ModuleList::select('module_name', 'created_at')
|
||||||
|
->orderBy('created_at', 'asc')
|
||||||
|
->get()
|
||||||
|
->unique('module_name')
|
||||||
|
->pluck('module_name')
|
||||||
|
->values(); // reset array keys
|
||||||
|
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'SUCCESS',
|
||||||
|
'modules' => $uniqueModules
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*/
|
||||||
|
public function update(Request $request, string $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*/
|
||||||
|
public function destroy(string $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\MachineController;
|
use App\Http\Controllers\MachineController;
|
||||||
|
use App\Http\Controllers\ModuleController;
|
||||||
use App\Http\Controllers\ObdController;
|
use App\Http\Controllers\ObdController;
|
||||||
use App\Http\Controllers\PalletController;
|
use App\Http\Controllers\PalletController;
|
||||||
use App\Http\Controllers\PlantController;
|
use App\Http\Controllers\PlantController;
|
||||||
@@ -62,3 +63,5 @@ Route::get('laser/item/get-master-data', [StickerMasterController::class, 'get_m
|
|||||||
|
|
||||||
Route::get('/download-qr-pdf/{palletNo}', [PalletController::class, 'downloadQrPdf'])->name('download-qr-pdf');
|
Route::get('/download-qr-pdf/{palletNo}', [PalletController::class, 'downloadQrPdf'])->name('download-qr-pdf');
|
||||||
|
|
||||||
|
Route::get('get/module-name/data', [ModuleController::class, 'get_module']);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user