From 881e2fa6d946f0406280b91447eed55139a938d1 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 11 May 2026 15:36:12 +0530 Subject: [PATCH] removed exit time as mandatory --- app/Http/Controllers/VehicleController.php | 68 ++++++++++++++-------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/VehicleController.php b/app/Http/Controllers/VehicleController.php index aefd5f2..a3f37de 100644 --- a/app/Http/Controllers/VehicleController.php +++ b/app/Http/Controllers/VehicleController.php @@ -41,12 +41,11 @@ class VehicleController extends Controller if (!ctype_digit((string) $plantCode)) { return response()->json([ - 'status' => 'error', + 'status' => 'ERROR', 'status_description' => "plant code must be $plantCode a numeric value", ], 404); } - $plantCod = Plant::where('code', $plantCode)->first(); if(!$plantCod){ @@ -56,6 +55,20 @@ class VehicleController extends Controller ], 404); } + // $expectedKeys = ['vehicle_number','entry_time','exit_time','duration','type']; + + // $requestKeys = array_keys($request->all()); + + // sort($expectedKeys); + // sort($requestKeys); + + // if ($expectedKeys != $requestKeys) { + // return response()->json([ + // 'status' => 'ERROR', + // 'status_description' => 'Send proper valid JSON structure' + // ], 400); + // } + $plantId = $plantCod->id; $data = $request->all(); @@ -86,20 +99,20 @@ class VehicleController extends Controller 'status_description' => "Entry time cant't be empty!", ], 404); } - else if(!$exitTimeRaw) - { - return response()->json([ - 'status' => 'ERROR', - 'status_description' => "Exit time cant't be empty!", - ], 404); - } - else if(!$duration) - { - return response()->json([ - 'status' => 'ERROR', - 'status_description' => "Duration cant't be empty!", - ], 404); - } + // else if(!$exitTimeRaw) + // { + // return response()->json([ + // 'status' => 'ERROR', + // 'status_description' => "Exit time cant't be empty!", + // ], 404); + // } + // else if(!$duration) + // { + // return response()->json([ + // 'status' => 'ERROR', + // 'status_description' => "Duration cant't be empty!", + // ], 404); + // } else if(!$type) { return response()->json([ @@ -108,7 +121,6 @@ class VehicleController extends Controller ], 404); } - if ($entryTimeRaw && !Carbon::hasFormat($entryTimeRaw, 'd/m/Y h:i:s A')) { return response()->json([ 'status' => 'ERROR', @@ -123,7 +135,7 @@ class VehicleController extends Controller } else if ($duration && !preg_match('/^\d{2}:\d{2}:\d{2}$/', $duration)) { return response()->json([ - 'status' => 'error', + 'status' => 'ERROR', 'status_description' => "Invalid duration format $duration. Expected HH:MM:SS", ], 404); } @@ -136,7 +148,7 @@ class VehicleController extends Controller ? Carbon::createFromFormat('d/m/Y h:i:s A', $exitTimeRaw) : null; - VehicleEntry::insert([ + $record = VehicleEntry::insert([ 'plant_id' => $plantId, 'vehicle_number' => $vehicleNo, 'entry_time' => $entryTime, @@ -147,11 +159,19 @@ class VehicleController extends Controller 'updated_at' => now(), ]); - return response()->json([ - 'status' => 'success', - 'status_description' => 'Vehicle entry inserted successfully' - ], 200); - + if($record){ + return response()->json([ + 'status' => 'SUCCESS', + 'status_description' => 'Vehicle entry inserted successfully' + ], 200); + } + else + { + return response()->json([ + 'status' => 'ERROR', + 'status_description' => 'Failed to insert record in the table vehicle entry' + ], 404); + } } /** -- 2.49.1