From 50ed6ef9be0a2bda514bcae2541f0a77451e89a6 Mon Sep 17 00:00:00 2001 From: Dizho A Date: Mon, 17 Aug 2026 11:08:45 +0530 Subject: [PATCH] moditify the Dashboard and visit list at shelter inspection project --- .../configuration/DataSourceConfig.java | 5 +- .../ShelterInspectionController.java | 136 +++++++++++++- .../modules/shelterinspection/visitlist.html | 177 +++++++++++++++++- 3 files changed, 306 insertions(+), 12 deletions(-) diff --git a/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java b/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java index acabf76..daa4be0 100644 --- a/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java +++ b/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java @@ -30,9 +30,8 @@ public class DataSourceConfig { // private static String dbpassword = "gccroot"; // AWS - // private static String host = - // "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; - // private static String dbpassword = "gcc-facial-password"; +// private static String host = "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; +// private static String dbpassword = "gcc-facial-password"; ////////////////////////////// (For GCC APP) //////////////////////// @Configuration diff --git a/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java b/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java index 2101370..2ce6dd9 100644 --- a/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java +++ b/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java @@ -5,11 +5,15 @@ import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; +import org.springframework.web.client.ResourceAccessException; import org.springframework.web.client.RestTemplate; import in.gov.chennaicorporation.gccoffice.configuration.AppConfig; @@ -143,14 +147,134 @@ public class ShelterInspectionController { } - @GetMapping("/questions") - public ResponseEntity getquestionsDetails(@RequestParam("cid") String cid){ - String apiUrl = appConfig.shelterurl + "/questions?cid=" + cid; - return restTemplate.getForEntity(apiUrl, String.class); - - } + public ResponseEntity getquestionsDetails( + @RequestParam("cid") String cid) { + + try { + + String apiUrl = + appConfig.shelterurl + "/questions?cid=" + cid; + + System.out.println( + "API URL for night inspection questions: " + apiUrl + ); + + ResponseEntity response = + restTemplate.getForEntity( + apiUrl, + Object.class + ); + + return ResponseEntity + .status(response.getStatusCode()) + .body(response.getBody()); + + } catch (HttpClientErrorException e) { + + System.out.println( + "Question API Client Error: " + + e.getStatusCode() + ); + + return ResponseEntity + .status(e.getStatusCode()) + .body(e.getResponseBodyAsString()); + + } catch (HttpServerErrorException e) { + + System.out.println( + "Question API Server Error: " + + e.getStatusCode() + ); + + return ResponseEntity + .status(e.getStatusCode()) + .body(e.getResponseBodyAsString()); + + } catch (ResourceAccessException e) { + + System.out.println( + "Question API Connection Error: " + + e.getMessage() + ); + + return ResponseEntity + .status(HttpStatus.BAD_GATEWAY) + .body( + Map.of( + "status", false, + "message", + "Unable to connect to Question Master API." + ) + ); + + } catch (Exception e) { + + System.out.println( + "Question API Exception" + ); + + e.printStackTrace(); + + return ResponseEntity + .status(HttpStatus.INTERNAL_SERVER_ERROR) + .body( + Map.of( + "status", false, + "message", + "Unable to load question details." + ) + ); + } + } + +// @GetMapping("/questions") +// public ResponseEntity getquestionsDetails(@RequestParam("cid") String cid) { +// +// try { +// +// String apiUrl = appConfig.shelterurl + "/questions?cid=" + cid; +// +// System.out.println("apiUrl for night inspection questions:" +apiUrl); +// +// ResponseEntity response = +// restTemplate.getForEntity(apiUrl, String.class); +// +// return ResponseEntity +// .status(response.getStatusCode()) +// .body(response.getBody()); +// +// } catch (HttpClientErrorException e) { +// +// return ResponseEntity +// .status(e.getStatusCode()) +// .body(e.getResponseBodyAsString()); +// +// } catch (HttpServerErrorException e) { +// +// return ResponseEntity +// .status(e.getStatusCode()) +// .body(e.getResponseBodyAsString()); +// +// } catch (ResourceAccessException e) { +// +// return ResponseEntity +// .status(HttpStatus.BAD_GATEWAY) +// .body("Unable to connect to Question Master API."); +// +// } catch (Exception e) { +// +// System.out.println("apiUrl for night inspection questions Exception....."); +// e.printStackTrace(); +// +// return ResponseEntity +// .status(HttpStatus.INTERNAL_SERVER_ERROR) +// .body("Unable to load question details."); +// +// } +// } // @GetMapping("/questions") // public ResponseEntity getQuestions(@RequestParam String cid) { diff --git a/src/main/resources/templates/modules/shelterinspection/visitlist.html b/src/main/resources/templates/modules/shelterinspection/visitlist.html index 84dfd5a..8dbec3d 100644 --- a/src/main/resources/templates/modules/shelterinspection/visitlist.html +++ b/src/main/resources/templates/modules/shelterinspection/visitlist.html @@ -738,7 +738,7 @@ - @@ -1249,8 +1249,179 @@ //load question api + let questionMaster = []; + function loadQuestionMaster(callback) { + + $.ajax({ + url: "/gcc/api/shelterinspection/questions", + type: "GET", + data: { + cid: 1 + }, + dataType: "json", + + success: function(res) { + + console.log("Question Master Response:", res); + + if (res && res.data && Array.isArray(res.data)) { + + questionMaster = res.data; + + console.log( + "Question Master Loaded:", + questionMaster.length + ); + + if (callback) { + callback(); + } + + } else { + + console.error( + "Question master data not found.", + res + ); + + questionMaster = []; + + } + }, + + error: function(xhr, status, error) { + + console.error( + "Question Master API Error:", + xhr.status, + error + ); + + console.error( + "Response:", + xhr.responseText + ); + + questionMaster = []; + + let message = "Unable to load question master."; + + if (xhr.status === 502) { + + message = + "Question Master service is currently unavailable."; + + } else if (xhr.status === 404) { + + message = + "Question Master API was not found."; + + } else if (xhr.status === 500) { + + message = + "Internal server error while loading question master."; + + } else if (xhr.status === 400) { + + message = + "Invalid request for Question Master."; + + } + + console.error("Question Master Error:", message); + + } + }); + } + + + + /* let questionMaster = []; + + function loadQuestionMaster(callback) { + + $.ajax({ + url: "/gcc/api/shelterinspection/questions", + type: "GET", + data: { + cid: 1 + }, + + success: function(res) { + + console.log("Question Master Response:", res); + + questionMaster = res.data; + if (res && res.data) { + + questionMaster = res.data; + + console.log( + "Question Master Loaded:", + questionMaster.length + ); + + if (callback) { + callback(); + } + + } else { + + console.error("Question master data not found."); + + questionMaster = []; + +/* Swal.fire({ + icon: "warning", + title: "Question Master", + text: "Question master data is not available.", + allowOutsideClick: false + }); * + } + }, + + error: function(xhr, status, error) { + + console.error( + "Question Master API Error:", + xhr.status, + error + ); + + console.error( + "Response:", + xhr.responseText + ); + + questionMaster = []; + + let message = "Unable to load question master."; + + if (xhr.status === 502) { + message = "Question Master service is currently unavailable."; + } + else if (xhr.status === 404) { + message = "Question Master API was not found."; + } + else if (xhr.status === 500) { + message = "Internal server error while loading question master."; + } + +/* Swal.fire({ + icon: "error", + title: "Question Master Error", + text: message, + allowOutsideClick: false + }); * + } + }); + } */ + + + /* let questionMaster = []; + function loadQuestionMaster(callback){ $.ajax({ @@ -1268,7 +1439,7 @@ } }); - } + } */ function buildStaffList(answer){