GWM : api test

This commit is contained in:
Gowtham M 2025-12-11 12:19:28 +05:30
parent 6a7e60393f
commit 93d642b270
3 changed files with 101 additions and 15 deletions

View File

@ -156,6 +156,14 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
$routes->get("api/policy/PolicyFilePath", "PolicyController::PolicyFilePath"); $routes->get("api/policy/PolicyFilePath", "PolicyController::PolicyFilePath");
$routes->group('test', [ ], function ($routes) {
$routes->get("policyCommissionCalculationAndGeminiPolicyRead", "PolicyController::policyCommissionCalculationAndGeminiPolicyRead");
});
// $routes->get("policy/searchThePolicies", "PolicyController::searchThePolicies"); // $routes->get("policy/searchThePolicies", "PolicyController::searchThePolicies");
// $routes->get("dashboard/businessDashboard", "DashboardController::businessDashboard"); // $routes->get("dashboard/businessDashboard", "DashboardController::businessDashboard");
// $routes->get("dashboard/partnerDashboard", "DashboardController::partnerDashboard"); // $routes->get("dashboard/partnerDashboard", "DashboardController::partnerDashboard");

View File

@ -700,6 +700,13 @@ class EnquiryController extends ResourceController
])->setStatusCode(400); ])->setStatusCode(400);
} }
if ($reg_no == 'New' || $reg_no == 'new' || $reg_no == 'NEW') {
return $this->response->setJSON([
"status" => "not exists",
"message" => "No active record found for this vehicle number in enquiries."
]);
}
// --- 2. Step 1: Check in partner_enquiry (Active/Latest Record) --- // --- 2. Step 1: Check in partner_enquiry (Active/Latest Record) ---
// Get the LATEST ACTIVE enquiry record for the registration number // Get the LATEST ACTIVE enquiry record for the registration number
$enquiry = $this->db->table("partner_enquiry") $enquiry = $this->db->table("partner_enquiry")

View File

@ -568,8 +568,13 @@ class PolicyController extends ResourceController
// Check if the file exists // Check if the file exists
if (!file_exists($filePath)) { if (!file_exists($filePath)) {
log_message('info',"Error: File not found at {$filePath}"); log_message('info',"Error: File not found at {$filePath}");
if($return == true)
{
return $this->respond(['status'=>"failed", 'message'=> "File not found at {$filePath}"], 200);
}else{
return ['status'=>"failed", 'message'=> "File not found at {$filePath}"]; return ['status'=>"failed", 'message'=> "File not found at {$filePath}"];
} }
}
// Get the file's MIME type using the finfo extension // Get the file's MIME type using the finfo extension
$finfo = finfo_open(FILEINFO_MIME_TYPE); $finfo = finfo_open(FILEINFO_MIME_TYPE);
@ -665,8 +670,13 @@ class PolicyController extends ResourceController
if (curl_errno($ch)) { if (curl_errno($ch)) {
$curl_error = curl_error($ch); $curl_error = curl_error($ch);
log_message('info',"cURL Error: " . $curl_error); log_message('info',"cURL Error: " . $curl_error);
if($return == true)
{
return $this->respond(['status'=>"failed", 'message'=> "cURL Error: " . $curl_error], 200);
}else{
return ['status'=>"failed", 'message'=> "cURL Error: " . $curl_error]; return ['status'=>"failed", 'message'=> "cURL Error: " . $curl_error];
} }
}
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close the cURL handle // Close the cURL handle
@ -675,8 +685,13 @@ class PolicyController extends ResourceController
// Check for non-successful HTTP status codes // Check for non-successful HTTP status codes
if ($http_code < 200 || $http_code >= 300) { if ($http_code < 200 || $http_code >= 300) {
log_message('info',"API returned non-successful HTTP status code: $http_code. Response: " . substr($response, 0, 200)); log_message('info',"API returned non-successful HTTP status code: $http_code. Response: " . substr($response, 0, 200));
if($return == true)
{
return $this->respond(['status'=>"failed", 'message'=> "API returned non-successful HTTP status code: $http_code. Response: " . substr($response, 0, 200)], 200);
}else{
return ['status'=>"failed", 'message'=> "API returned non-successful HTTP status code: $http_code. Response: " . substr($response, 0, 200)]; return ['status'=>"failed", 'message'=> "API returned non-successful HTTP status code: $http_code. Response: " . substr($response, 0, 200)];
} }
}
// Decode the JSON response // Decode the JSON response
$responseData = json_decode($response, true, 512, JSON_THROW_ON_ERROR); $responseData = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
@ -704,20 +719,38 @@ class PolicyController extends ResourceController
if (empty($json_string)) { if (empty($json_string)) {
log_message('info',"Could not extract a valid JSON string from the generated text."); log_message('info',"Could not extract a valid JSON string from the generated text.");
if($return == true)
{
return $this->respond(['status'=>"failed", 'message'=> "Could not extract a valid JSON string from the generated text."], 200);
}else{
return ['status'=>"failed", 'message'=> "Could not extract a valid JSON string from the generated text."]; return ['status'=>"failed", 'message'=> "Could not extract a valid JSON string from the generated text."];
} }
}
// Decode the extracted JSON string // Decode the extracted JSON string
$final_data = json_decode($json_string, true, 512, JSON_THROW_ON_ERROR); $final_data = json_decode($json_string, true, 512, JSON_THROW_ON_ERROR);
log_message('info', "Extracted and decoded final JSON data successfully."); log_message('info', "Extracted and decoded final JSON data successfully.");
if($return == true)
{
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $final_data ], 200);
}else
{
return ['status'=>"success", 'message'=> "Doc read sucess" , 'data'=>$final_data]; return ['status'=>"success", 'message'=> "Doc read sucess" , 'data'=>$final_data];
}
} else { } else {
log_message('info',"Response structure invalid or no generated text candidate found."); log_message('info',"Response structure invalid or no generated text candidate found.");
if($return == true)
{
return $this->respond(['status'=>"failed", 'message'=> "Response structure invalid or no generated text candidate found"], 200);
}else{
return ['status'=>"failed", 'message'=> "Response structure invalid or no generated text candidate found"]; return ['status'=>"failed", 'message'=> "Response structure invalid or no generated text candidate found"];
} }
}
} catch (\Exception $e) { } catch (\Exception $e) {
@ -725,12 +758,17 @@ class PolicyController extends ResourceController
// curl_close($ch); // curl_close($ch);
// } // }
log_message('error', "Fatal Error: " . $e->getMessage()); log_message('error', "Fatal Error: " . $e->getMessage());
if($return == true)
{
return $this->respond(['status'=>"failed", 'message'=> "Error: " . $e->getMessage()], 200);
}else{
return ['status'=>"failed", 'message'=> "Error: " . $e->getMessage()]; return ['status'=>"failed", 'message'=> "Error: " . $e->getMessage()];
} }
}
} }
public function calculateCommission($policyId = null) public function calculateCommission($policyId = null , $return = null)
{ {
log_message('debug', 'calculateCommission() started with policyId: ' . $policyId); log_message('debug', 'calculateCommission() started with policyId: ' . $policyId);
@ -799,7 +837,13 @@ class PolicyController extends ResourceController
if ($error) if ($error)
{ {
log_message('error', 'cURL Error: ' . $error); log_message('error', 'cURL Error: ' . $error);
if($return == true)
{
return $this->respond( ['status'=>"failed", 'message'=> 'cURL Error: ' . $error], 200);
}else{
return ['status'=>"failed", 'message'=> 'cURL Error: ' . $error]; return ['status'=>"failed", 'message'=> 'cURL Error: ' . $error];
}
} else { } else {
log_message('debug', 'API Response: ' . $response); log_message('debug', 'API Response: ' . $response);
@ -819,20 +863,47 @@ class PolicyController extends ResourceController
log_message('debug', 'Updating Policy (ID=75) With: ' . json_encode($policyData)); log_message('debug', 'Updating Policy (ID=75) With: ' . json_encode($policyData));
if($return == true)
{
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $policyData ], 200);
}else{
// Update record // Update record
$this->PolicyModel->update($policyId, $policyData); $this->PolicyModel->update($policyId, $policyData);
log_message('debug', 'Policy update successful!'); log_message('debug', 'Policy update successful!');
return ['status'=>"success", 'message'=> "Commission Updated!"]; return ['status'=>"success", 'message'=> "Commission Updated!"];
}
} else { } else {
log_message('debug', 'calculateCommission() - Invalid API Response'); log_message('debug', 'calculateCommission() - Invalid API Response');
if($return == true)
{
return $this->respond( ['status'=>"failed", 'message'=> "Invalid API Response!"], 200);
}else{
return ['status'=>"failed", 'message'=> "Invalid API Response!"]; return ['status'=>"failed", 'message'=> "Invalid API Response!"];
} }
} }
} }
}
public function policyCommissionCalculationAndGeminiPolicyRead()
{
$type = $this->request->getGet('type');
$policyId = $this->request->getGet('policy_id');
if($type == 'commission')
{
return $this->calculateCommission($policyId , true);
}else if($type == 'read')
{
return $this->checkPolicyDoc($policyId , true);
}
}
public function searchThePolicies() { public function searchThePolicies() {