Updated validation functionality and failure messages in controller files
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\MotorTestingMaster;
|
||||
use App\Models\Plant;
|
||||
use App\Models\StickerMaster;
|
||||
use Illuminate\Http\Request;
|
||||
use Str;
|
||||
|
||||
class StickerMasterController extends Controller
|
||||
{
|
||||
@@ -36,19 +37,11 @@ class StickerMasterController extends Controller
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
|
||||
// if ("Bearer " . $expectedToken !== $header_auth)
|
||||
// {
|
||||
// return response("Unauthorized", 403)
|
||||
// ->header('Content-Type', 'text/plain');
|
||||
// }
|
||||
|
||||
//$data = $request->all();
|
||||
|
||||
if ("Bearer " . $expectedToken !== $header_auth)
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token'
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
@@ -59,14 +52,28 @@ class StickerMasterController extends Controller
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant name cannot be empty"
|
||||
'status_description' => "Plant code can't be empty!"
|
||||
], 400);
|
||||
}
|
||||
else if (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);
|
||||
}
|
||||
else if ($itemCode == null || $itemCode == '')
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Item code cannot be empty"
|
||||
'status_description' => "Item Code can't be empty!"
|
||||
], 400);
|
||||
}
|
||||
else if (Str::length($itemCode) < 6 || !ctype_alnum($itemCode))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid item code found!"
|
||||
], 400);
|
||||
}
|
||||
|
||||
@@ -75,48 +82,56 @@ class StickerMasterController extends Controller
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant not found"
|
||||
'status_description' => "Plant not found!"
|
||||
], 400);
|
||||
}
|
||||
|
||||
$plantId = $plant->id;
|
||||
|
||||
$item = Item::where('plant_id', $plantId)->where('code', $itemCode)->first();
|
||||
|
||||
$description = $item ? $item->description : '';
|
||||
|
||||
$uom = $item ? $item->uom : '';
|
||||
|
||||
$category = $item ? $item->category : '';
|
||||
|
||||
$item = Item::where('code', $itemCode)->first();
|
||||
|
||||
if (!$item)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Item Code not found in item table for the plant : $plant->name"
|
||||
'status_description' => "Item Code not found in item table!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$stickerMaster = StickerMaster::where('plant_id', $plant->id)->where('item_id', $item->id)->first();
|
||||
$item = Item::where('plant_id', $plantId)->where('code', $itemCode)->first();
|
||||
|
||||
if (!$item)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Item Code not found in item table for the plant : '$plant->name'!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$description = $item ? $item->description : '';
|
||||
|
||||
$uom = $item ? $item->uom : '';
|
||||
|
||||
$category = $item ? $item->category : '';
|
||||
|
||||
$stickerMaster = StickerMaster::where('plant_id', $plantId)->where('item_id', $item->id)->first();
|
||||
|
||||
if (!$stickerMaster)
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Item Code not found in master table for the plant : $plant->name"
|
||||
'status_description' => "Item Code not found in sticker master table for the plant : '$plant->name'!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$output = [
|
||||
"item_description" => $description ?? "",
|
||||
"uom" => $uom ?? "",
|
||||
"Part_Validation_1" => $stickerMaster->laser_part_validation1 ?? "",
|
||||
"Part_Validation_2" => $stickerMaster->laser_part_validation2 ?? "",
|
||||
"Part_Validation_3" => "",
|
||||
"Part_Validation_4" => "",
|
||||
"Part_Validation_5" => ""
|
||||
"Part_Validation_1" => $stickerMaster?->laser_part_validation1 ?? "",
|
||||
"Part_Validation_2" => $stickerMaster?->laser_part_validation2 ?? "",
|
||||
"Part_Validation_3" => $stickerMaster?->laser_part_validation3 ?? "",
|
||||
"Part_Validation_4" => $stickerMaster?->laser_part_validation4 ?? "",
|
||||
"Part_Validation_5" => $stickerMaster?->laser_part_validation5 ?? "",
|
||||
];
|
||||
|
||||
return response()->json($output, 200);
|
||||
|
||||
Reference in New Issue
Block a user