You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
757 lines
32 KiB
757 lines
32 KiB
package com.gcc.restapiservices.petregistration.controller;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeParseException;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Random;
|
|
|
|
import org.json.JSONObject;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.dao.EmptyResultDataAccessException;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
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.RestTemplate;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
import com.gcc.restapiservices.configuration.AppConfig;
|
|
import com.gcc.restapiservices.petregistration.constants.AppConstants;
|
|
import com.gcc.restapiservices.petregistration.service.PetRegistrationApiService;
|
|
import com.gcc.restapiservices.petregistration.util.ApiResponseUtil;
|
|
import com.gcc.restapiservices.swimmingpool.util.ApiResponse;
|
|
import com.razorpay.Order;
|
|
import com.razorpay.RazorpayClient;
|
|
import com.razorpay.RazorpayException;
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpSession;
|
|
|
|
@RestController
|
|
@RequestMapping("/gccrestservices/petregistration/api")
|
|
|
|
public class PetRegistrationApiController {
|
|
|
|
@Autowired
|
|
private PetRegistrationApiService petRegistrationApiService;
|
|
|
|
@Autowired
|
|
private AppConfig appConfig;
|
|
|
|
@GetMapping("/breed")
|
|
public ResponseEntity<?> getBreedList(@RequestParam int type) {
|
|
|
|
List<Map<String, Object>> result = petRegistrationApiService.getBreedList(type);
|
|
try {
|
|
|
|
if (result.isEmpty()) {
|
|
return ApiResponseUtil.notFound("No data found");
|
|
}
|
|
|
|
return ApiResponseUtil.success(result, "Data found");
|
|
} catch (Exception e) {
|
|
return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
// get owner details
|
|
|
|
@GetMapping("/ownerinfo")
|
|
public ResponseEntity<?> getOwnerDetails(@RequestParam String mobile) {
|
|
|
|
List<Map<String, Object>> result = petRegistrationApiService.getOwnerDetails(mobile);
|
|
try {
|
|
|
|
// Check if mobile is missing or blank
|
|
if (mobile == null || mobile.trim().isEmpty()) {
|
|
return ApiResponseUtil.error("Mobile number is required", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
// Check if mobile is not 10 digits
|
|
if (!mobile.matches("\\d{10}")) {
|
|
return ApiResponseUtil.error("Mobile number must be exactly 10 digits", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
if (result.isEmpty()) {
|
|
return ApiResponseUtil.notFound("No data found");
|
|
}
|
|
|
|
return ApiResponseUtil.success(result, "Data found");
|
|
} catch (Exception e) {
|
|
return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
// get pet type
|
|
@GetMapping("/pettypes")
|
|
public ResponseEntity<?> getPetTypes() {
|
|
|
|
List<Map<String, Object>> result = petRegistrationApiService.getTypeOfPets();
|
|
try {
|
|
|
|
if (result.isEmpty()) {
|
|
return ApiResponseUtil.notFound("No data found");
|
|
}
|
|
|
|
return ApiResponseUtil.success(result, "Data found");
|
|
} catch (Exception e) {
|
|
return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
// get pet type
|
|
@GetMapping("/allyears")
|
|
public ResponseEntity<?> getAllYears() {
|
|
|
|
List<Map<String, Object>> result = petRegistrationApiService.getAllYears();
|
|
try {
|
|
|
|
if (result.isEmpty()) {
|
|
return ApiResponseUtil.notFound("No data found");
|
|
}
|
|
|
|
return ApiResponseUtil.success(result, "Data found");
|
|
} catch (Exception e) {
|
|
return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
// get pet type
|
|
@GetMapping("/allmonths")
|
|
public ResponseEntity<?> getAllMonths() {
|
|
|
|
List<Map<String, Object>> result = petRegistrationApiService.getAllMonths();
|
|
try {
|
|
|
|
if (result.isEmpty()) {
|
|
return ApiResponseUtil.notFound("No data found");
|
|
}
|
|
|
|
return ApiResponseUtil.success(result, "Data found");
|
|
} catch (Exception e) {
|
|
return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
@GetMapping("/userexistornot")
|
|
public ResponseEntity<?> userExistOrNot(@RequestParam String mobilenum) {
|
|
try {
|
|
|
|
// Check if mobile is missing or blank
|
|
if (mobilenum == null || mobilenum.trim().isEmpty()) {
|
|
return ApiResponseUtil.error("Mobile number is required", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
// Check if mobile is not 10 digits
|
|
if (!mobilenum.matches("\\d{10}")) {
|
|
return ApiResponseUtil.error("Mobile number must be exactly 10 digits", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
boolean result = petRegistrationApiService.isPhoneRegistered(mobilenum);
|
|
System.out.println("result: " + result);
|
|
|
|
String message = result ? "Mobile number already registered" : "Mobile number not registered";
|
|
|
|
return ApiResponseUtil.success(result, message);
|
|
|
|
} catch (Exception e) {
|
|
return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
// save new owner registration
|
|
|
|
@PostMapping("/pet-owner/register")
|
|
public ResponseEntity<?> savePinDetails(HttpServletRequest request,
|
|
@RequestParam(required = false) String title,
|
|
@RequestParam(required = false) String username,
|
|
@RequestParam(required = false) String doornumber,
|
|
@RequestParam(required = false) String street,
|
|
@RequestParam(required = false) String area,
|
|
@RequestParam(required = false) String city,
|
|
@RequestParam(required = false) String pincode,
|
|
@RequestParam(required = false) String zone,
|
|
@RequestParam(required = false) String ward,
|
|
@RequestParam(required = false) String phone,
|
|
@RequestParam(required = false) String email,
|
|
@RequestParam(required = false) String pin) {
|
|
|
|
List<String> missingFields = new ArrayList<>();
|
|
if (title == null || title.trim().isEmpty())
|
|
missingFields.add("title");
|
|
if (username == null || username.trim().isEmpty())
|
|
missingFields.add("username");
|
|
if (doornumber == null || doornumber.trim().isEmpty())
|
|
missingFields.add("doornumber");
|
|
if (street == null || street.trim().isEmpty())
|
|
missingFields.add("street");
|
|
if (area == null || area.trim().isEmpty())
|
|
missingFields.add("area");
|
|
if (city == null || city.trim().isEmpty())
|
|
missingFields.add("city");
|
|
if (pincode == null || pincode.trim().isEmpty())
|
|
missingFields.add("pincode");
|
|
if (zone == null || zone.trim().isEmpty())
|
|
missingFields.add("zone");
|
|
if (ward == null || ward.trim().isEmpty())
|
|
missingFields.add("ward");
|
|
if (phone == null || phone.trim().isEmpty())
|
|
missingFields.add("phone");
|
|
if (email == null || email.trim().isEmpty())
|
|
missingFields.add("email");
|
|
if (pin == null || pin.trim().isEmpty())
|
|
missingFields.add("pin");
|
|
|
|
if (!missingFields.isEmpty()) {
|
|
return ApiResponseUtil.invalidRequest("Missing required fields: " + String.join(", ", missingFields));
|
|
}
|
|
|
|
try {
|
|
|
|
// Check if mobile is missing or blank
|
|
if (phone == null || phone.trim().isEmpty()) {
|
|
return ApiResponseUtil.error("Mobile number is required", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
// Check if mobile is not 10 digits
|
|
if (!phone.matches("\\d{10}")) {
|
|
return ApiResponseUtil.error("Mobile number must be exactly 10 digits", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
// Check if mobile is not 10 digits
|
|
if (!pincode.matches("\\d{6}")) {
|
|
return ApiResponseUtil.error("Pincode must be exactly 6 digits", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
// Validate email if provided
|
|
if (email != null && !email.isBlank()) {
|
|
String emailRegex = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.com$";
|
|
if (!email.matches(emailRegex)) {
|
|
return ApiResponseUtil.error("Invalid email id", HttpStatus.BAD_REQUEST);
|
|
}
|
|
}
|
|
|
|
// Check if mobile is not 10 digits
|
|
if (!pincode.matches("\\d{6}")) {
|
|
return ApiResponseUtil.error("Pincode must be exactly 6 digits", HttpStatus.BAD_REQUEST);
|
|
}
|
|
// pin validation
|
|
|
|
if (!pin.matches("\\d{4}")) {
|
|
return ApiResponseUtil.error("pin must be 4 digits only", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
return petRegistrationApiService.insertPetOwner(
|
|
title, username, doornumber, street, area, city, pincode, zone, ward, phone, email, pin);
|
|
} catch (Exception ex) {
|
|
return ApiResponseUtil.error("Internal server error: " + ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
@PostMapping("/saveregistrationdetails")
|
|
public ResponseEntity<?> saveRegistrationDetails(
|
|
@RequestParam(required = false) String petname,
|
|
@RequestParam(required = false) String species,
|
|
@RequestParam(required = false) String breed,
|
|
@RequestParam(required = false) String identification_mark,
|
|
@RequestParam(required = false) String petcolor,
|
|
@RequestParam(required = false) String gender,
|
|
@RequestParam(required = false) String age_year,
|
|
@RequestParam(required = false) String months,
|
|
@RequestParam(required = false) String is_sterilized,
|
|
@RequestParam(required = false) String is_adopted_street,
|
|
@RequestParam(required = false) String is_rabies_vaccination,
|
|
@RequestParam(required = false) String arv_date,
|
|
@RequestParam(required = false) String lastdate_of_deworming,
|
|
@RequestParam(required = false) String other_vaccination,
|
|
@RequestParam(required = false) String previous_licenseNo,
|
|
@RequestParam(required = false) String consultant_name,
|
|
@RequestParam(required = false) String council_number,
|
|
@RequestParam(required = false) String mobilenum,
|
|
@RequestParam(required = false) MultipartFile applicantphoto,
|
|
@RequestParam(required = false) MultipartFile addressproof,
|
|
@RequestParam(required = false) MultipartFile petphoto,
|
|
@RequestParam(required = false) MultipartFile rabiesvacCertificate) {
|
|
|
|
LocalDate today = LocalDate.now();
|
|
String registerdate = today.toString();
|
|
|
|
List<String> missingFields = new ArrayList<>();
|
|
|
|
if (petname == null || petname.trim().isEmpty())
|
|
missingFields.add("petname");
|
|
if (species == null || species.trim().isEmpty())
|
|
missingFields.add("species");
|
|
if (breed == null || breed.trim().isEmpty())
|
|
missingFields.add("breed");
|
|
// if (identification_mark == null || identification_mark.trim().isEmpty())
|
|
// missingFields.add("identification_mark"); optional
|
|
if (petcolor == null || petcolor.trim().isEmpty())
|
|
missingFields.add("petcolor");
|
|
if (gender == null || gender.trim().isEmpty())
|
|
missingFields.add("gender");
|
|
if (age_year == null || age_year.trim().isEmpty())
|
|
missingFields.add("age_year");
|
|
if (months == null || months.trim().isEmpty())
|
|
missingFields.add("months");
|
|
if (is_sterilized == null || is_sterilized.trim().isEmpty())
|
|
missingFields.add("is_sterilized");
|
|
if (is_adopted_street == null || is_adopted_street.trim().isEmpty())
|
|
missingFields.add("is_adopted_street");
|
|
if (is_rabies_vaccination == null || is_rabies_vaccination.trim().isEmpty())
|
|
missingFields.add("is_rabies_vaccination");
|
|
if (arv_date == null || arv_date.trim().isEmpty())
|
|
missingFields.add("arv_date");
|
|
// if (lastdate_of_deworming == null || lastdate_of_deworming.trim().isEmpty())
|
|
// missingFields.add("lastdate_of_deworming"); optional
|
|
// if (other_vaccination == null || other_vaccination.trim().isEmpty())
|
|
// missingFields.add("other_vaccination"); optional
|
|
// if (previous_licenseNo == null || previous_licenseNo.trim().isEmpty())
|
|
// missingFields.add("previous_licenseNo"); optional
|
|
// if (consultant_name == null || consultant_name.trim().isEmpty())
|
|
// missingFields.add("consultant_name"); optional
|
|
// if (council_number == null || council_number.trim().isEmpty())
|
|
// missingFields.add("council_number"); optional
|
|
if (mobilenum == null || mobilenum.trim().isEmpty())
|
|
missingFields.add("mobilenum");
|
|
|
|
if (applicantphoto == null || applicantphoto.isEmpty())
|
|
missingFields.add("applicantphoto");
|
|
if (addressproof == null || addressproof.isEmpty())
|
|
missingFields.add("addressproof");
|
|
if (petphoto == null || petphoto.isEmpty())
|
|
missingFields.add("petphoto");
|
|
if (rabiesvacCertificate == null || rabiesvacCertificate.isEmpty())
|
|
missingFields.add("rabiesvacCertificate");
|
|
|
|
if (!missingFields.isEmpty()) {
|
|
return ApiResponseUtil.invalidRequest("Missing required fields: " + String.join(", ", missingFields));
|
|
}
|
|
|
|
try {
|
|
// Save to DB
|
|
String saveStatus = petRegistrationApiService.saveAllRegistrationDetails(petname, species, breed,
|
|
identification_mark, petcolor, gender, age_year, months,
|
|
is_sterilized, is_adopted_street, is_rabies_vaccination,
|
|
arv_date, lastdate_of_deworming, other_vaccination, previous_licenseNo, consultant_name,
|
|
council_number, mobilenum,
|
|
applicantphoto, addressproof, petphoto, rabiesvacCertificate, registerdate);
|
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
|
System.out.println("saveStatus " + saveStatus);
|
|
|
|
// Check if mobile is missing or blank
|
|
if (mobilenum == null || mobilenum.trim().isEmpty()) {
|
|
return ApiResponseUtil.error("Mobile number is required", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
// Check if mobile is not 10 digits
|
|
if (!mobilenum.matches("\\d{10}")) {
|
|
return ApiResponseUtil.error("Mobile number must be exactly 10 digits", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
if (is_rabies_vaccination != null && !is_rabies_vaccination.isBlank()
|
|
&& is_rabies_vaccination.equalsIgnoreCase("Yes")) {
|
|
// Continue registration
|
|
} else {
|
|
return ApiResponseUtil.error(
|
|
"You can't register a pet without Rabies Vaccination. Please select 'Yes' only.",
|
|
HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
// Define the date format used in the request (adjust as needed)
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
|
|
|
if (arv_date != null && !arv_date.isBlank()) {
|
|
LocalDate arvDate = LocalDate.parse(arv_date.trim(), formatter);
|
|
if (arvDate.isAfter(LocalDate.now())) {
|
|
return ApiResponseUtil.error("ARV date cannot be in the future", HttpStatus.BAD_REQUEST);
|
|
}
|
|
}
|
|
|
|
if (lastdate_of_deworming != null && !lastdate_of_deworming.isBlank()) {
|
|
LocalDate dewormDate = LocalDate.parse(lastdate_of_deworming.trim(), formatter);
|
|
if (dewormDate.isAfter(LocalDate.now())) {
|
|
return ApiResponseUtil.error("Deworming date cannot be in the future", HttpStatus.BAD_REQUEST);
|
|
}
|
|
}
|
|
|
|
int yearsInt = 0;
|
|
int monthsInt = 0;
|
|
|
|
try {
|
|
if (age_year != null && !age_year.isBlank()) {
|
|
yearsInt = Integer.parseInt(age_year.trim());
|
|
}
|
|
if (months != null && !months.isBlank()) {
|
|
monthsInt = Integer.parseInt(months.trim());
|
|
}
|
|
|
|
if (yearsInt <= 0 && monthsInt <= 0) {
|
|
return ApiResponseUtil.error("Pet age must be at least 1 month (either in years or months)",
|
|
HttpStatus.BAD_REQUEST);
|
|
}
|
|
} catch (NumberFormatException e) {
|
|
return ApiResponseUtil.error("Invalid value for age_year or months. Both must be numbers.",
|
|
HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
if (saveStatus == null || saveStatus.isEmpty() || saveStatus.contains("error")) {
|
|
|
|
response.put("status", false);
|
|
response.put("message", saveStatus);
|
|
response.put("description", "Failed to save the details");
|
|
return ResponseEntity.ok(response);
|
|
} else {
|
|
response.put("status", true);
|
|
response.put("message", "success");
|
|
response.put("description", "Details were saved successfully");
|
|
response.put("petId", saveStatus);
|
|
}
|
|
|
|
// Add uniqueid to response
|
|
|
|
return ResponseEntity.ok(response);
|
|
|
|
} catch (Exception ex) {
|
|
return ApiResponseUtil.error("Internal server error: " + ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
// getpetdetails
|
|
|
|
// get pet type
|
|
@GetMapping("/getpetdetails")
|
|
public ResponseEntity<?> getPetDetails(@RequestParam String mobilenum) {
|
|
try {
|
|
|
|
// Check if mobile is missing or blank
|
|
if (mobilenum == null || mobilenum.trim().isEmpty()) {
|
|
return ApiResponseUtil.error("Mobile number is required", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
// Check if mobile is not 10 digits
|
|
if (!mobilenum.matches("\\d{10}")) {
|
|
return ApiResponseUtil.error("Mobile number must be exactly 10 digits", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
List<Map<String, Object>> results = petRegistrationApiService.getPetRegistrationDetailsbyMobile(mobilenum);
|
|
|
|
// if (results == null || results.isEmpty()) {
|
|
// return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
|
// .body("No Registration Data for mobile number: " + mobilenum);
|
|
// }
|
|
|
|
if (results == null || results.isEmpty()) {
|
|
return ApiResponseUtil.error("No PET Registration Details for mobile number ", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
return ApiResponseUtil.success(results, "Data found");
|
|
} catch (Exception e) {
|
|
return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
// renewal the pet certificate
|
|
@PostMapping("/updateARVDetails")
|
|
public ResponseEntity<?> updateARVDetails(
|
|
@RequestParam("uniqueid") String uniqueid,
|
|
@RequestParam("arvdate") String arvdate,
|
|
@RequestParam("rabiesvacCertificate") MultipartFile rabiesvacCertificate) {
|
|
try {
|
|
if (uniqueid == null || uniqueid.trim().isEmpty()) {
|
|
return ApiResponseUtil.error("Unique ID is required", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
if (arvdate == null || arvdate.trim().isEmpty()) {
|
|
return ApiResponseUtil.error("ARV date is required", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
|
|
|
LocalDate arvDate;
|
|
try {
|
|
arvDate = LocalDate.parse(arvdate.trim(), formatter);
|
|
} catch (DateTimeParseException e) {
|
|
return ApiResponseUtil.error("Invalid date format. Please use dd-MM-yyyy", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
// if (arvDate.isAfter(LocalDate.now())) {
|
|
// return ApiResponseUtil.error("ARV date cannot be in the future",
|
|
// HttpStatus.BAD_REQUEST);
|
|
// }
|
|
|
|
if (rabiesvacCertificate == null || rabiesvacCertificate.isEmpty()) {
|
|
return ApiResponseUtil.error("Rabies vaccination certificate is required", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
String result = petRegistrationApiService.updateARVAndRabiesCertificate(uniqueid, arvdate,
|
|
rabiesvacCertificate);
|
|
|
|
if ("success".equalsIgnoreCase(result)) {
|
|
return ApiResponseUtil.success(null, "Details updated successfully");
|
|
} else if (result.startsWith("Renewal allowed only after:")) {
|
|
return ApiResponseUtil.error(result, HttpStatus.BAD_REQUEST);
|
|
} else if (result.startsWith("No license validity")) {
|
|
return ApiResponseUtil.error(result, HttpStatus.NOT_FOUND);
|
|
} else if (result.startsWith("Invalid ARV date format")) {
|
|
return ApiResponseUtil.error(result, HttpStatus.BAD_REQUEST);
|
|
} else {
|
|
return ApiResponseUtil.error(result, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
// if ("success".equalsIgnoreCase(result)) {
|
|
// return ApiResponseUtil.success(null, "Details updated successfully");
|
|
// } else {
|
|
// return ApiResponseUtil.error(result, HttpStatus.NOT_FOUND);
|
|
// }
|
|
|
|
} catch (Exception e) {
|
|
return ApiResponseUtil.error("Exception: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
// @PostMapping("/create_order")
|
|
// public ResponseEntity<?> createOrder(@RequestParam String petId) throws RazorpayException {
|
|
|
|
// try {
|
|
// Map<String, Object> petDetail = petRegistrationApiService.getpetdetails(petId);
|
|
|
|
// int petStatus = 0;
|
|
// // Check if petDetail is empty
|
|
// if (!petDetail.isEmpty()) {
|
|
// petStatus = (int) petDetail.get("status");
|
|
// }
|
|
|
|
// if (petStatus != 2 && petStatus != 4) {
|
|
// return new ResponseEntity<>(
|
|
// new ApiResponse("error", "PET request must be accepted by the officer to proceed with payment.",
|
|
// null, HttpStatus.BAD_REQUEST.value()),
|
|
// HttpStatus.BAD_REQUEST);
|
|
// }
|
|
|
|
// System.out.println("key ID :-----" + appConfig.getKeyId());
|
|
// int pet_id = Integer.parseInt(petId);
|
|
|
|
// double amount = Double.parseDouble("50");
|
|
|
|
// // To enable testing mode in appConstants if required for testing & development
|
|
// var client = new RazorpayClient(AppConstants.key_id, AppConstants.key_secret);
|
|
// JSONObject options = new JSONObject();
|
|
// options.put("amount", amount * 100);
|
|
// options.put("currency", "INR");
|
|
// // options.put("receipt","Pet_ID/"+pet_id);
|
|
// Order od = client.orders.create(options);
|
|
// petRegistrationApiService.saveorderLog(od.get("id").toString(), od.toString(), pet_id);
|
|
// System.out.println(od);
|
|
// return ResponseEntity.ok(new ApiResponse("success", "Order created successfully", od.toJson().toMap(),
|
|
// HttpStatus.OK.value()));
|
|
// } catch (NumberFormatException ex) {
|
|
// throw new RuntimeException(ex);
|
|
// } catch (RazorpayException e) {
|
|
// return new ResponseEntity<>(new ApiResponse("error", "Razorpay error: " + e.getMessage(), null,
|
|
// HttpStatus.INTERNAL_SERVER_ERROR.value()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
// } catch (EmptyResultDataAccessException ex) {
|
|
// return new ResponseEntity<>(
|
|
// new ApiResponse("error", "PET request must be accepted by the officer to proceed with payment.",
|
|
// null, HttpStatus.BAD_REQUEST.value()),
|
|
// HttpStatus.BAD_REQUEST);
|
|
// } catch (Exception e) {
|
|
// return new ResponseEntity<>(new ApiResponse("error", "Unexpected error: " + e.getMessage(), null,
|
|
// HttpStatus.INTERNAL_SERVER_ERROR.value()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
// }
|
|
// }
|
|
|
|
@PostMapping("/Confirm")
|
|
public ResponseEntity<?> confirmPayment(
|
|
@RequestParam("petId") String petId,
|
|
@RequestParam(name = "source", defaultValue = "0") String source,
|
|
@RequestParam("mobno") String mobno,
|
|
@RequestParam(value = "orderId", required = true) String orderId,
|
|
@RequestBody Map<String, Object> paymentResponse) {
|
|
|
|
try {
|
|
// Validate orderId is not null or empty
|
|
if (orderId == null || orderId.trim().isEmpty()) {
|
|
return ResponseEntity.badRequest().body(Map.of(
|
|
"message", "Order ID is required and cannot be null or empty",
|
|
"error", "Missing required parameter: orderId"));
|
|
}
|
|
|
|
System.out.println("Controller Testing.................");
|
|
return petRegistrationApiService.processPaymentConfirmation(petId, source, mobno, orderId, paymentResponse);
|
|
} catch (Exception e) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
.body(Map.of("message", "Failed to confirm payment", "error", e.getMessage()));
|
|
}
|
|
}
|
|
|
|
// get zones
|
|
|
|
@GetMapping("/getZones")
|
|
public ResponseEntity<?> getZones() {
|
|
|
|
List<Map<String, Object>> result = petRegistrationApiService.getZones();
|
|
try {
|
|
|
|
if (result.isEmpty()) {
|
|
return ApiResponseUtil.notFound("No data found");
|
|
}
|
|
|
|
return ApiResponseUtil.success(result, "Data found");
|
|
} catch (Exception e) {
|
|
return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
// get Ward by zoneid
|
|
|
|
@GetMapping("/getWardByZoneId")
|
|
public ResponseEntity<?> getWardByZoneId(@RequestParam String zoneid) {
|
|
|
|
List<Map<String, Object>> result = petRegistrationApiService.getWardByZoneId(zoneid);
|
|
try {
|
|
|
|
// Check if mobile is missing or blank
|
|
if (zoneid == null || zoneid.trim().isEmpty()) {
|
|
return ApiResponseUtil.error("ZoneId is required", HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
if (result.isEmpty()) {
|
|
return ApiResponseUtil.notFound("No data found");
|
|
}
|
|
|
|
return ApiResponseUtil.success(result, "Data found");
|
|
} catch (Exception e) {
|
|
return ApiResponseUtil.error("Internal server error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
@GetMapping(value = "/sendOTP")
|
|
public String sendOtp(HttpServletRequest request, @RequestParam String mobileNo) {
|
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
|
String MobileNo = mobileNo;
|
|
System.out.print("\n MobileNo---:" + mobileNo);
|
|
Random rand = new Random();
|
|
int otp = rand.nextInt(90000) + 10000;
|
|
|
|
System.out.print("\n otp---:" + otp);
|
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm");
|
|
LocalDateTime now = LocalDateTime.now();
|
|
System.out.println(dtf.format(now));
|
|
|
|
String generatedToken = "Welcome to GCC " + otp + " is your OTP for gcc QR System";
|
|
|
|
String key = "pfTEYN6H";
|
|
String urlString = appConfig.getGetOtpUrl() + "from=GCCCRP&key=" + key + "&sender=GCCCRP&to=" + MobileNo
|
|
+ "&body=" + generatedToken + "&entityid=1401572690000011081&templateid=1407168250479102852";
|
|
|
|
System.out.print("\n urlString---: " + urlString);
|
|
String bodyMessage = "";
|
|
|
|
if (mobileNo == null || mobileNo.trim().isEmpty()) {
|
|
throw new IllegalArgumentException("Mobile number is required");
|
|
}
|
|
|
|
// Validate mobile number is exactly 10 digits
|
|
if (!mobileNo.matches("\\d{10}")) {
|
|
throw new IllegalArgumentException("Mobile number must be exactly 10 digits");
|
|
}
|
|
|
|
try {
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
String Response = restTemplate.getForObject(urlString, String.class);
|
|
|
|
// Using Jackson ObjectMapper to parse the response JSON
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
ObjectNode jsonResponse = (ObjectNode) objectMapper.readTree(Response);
|
|
|
|
// Add mobileNo and otp to the response JSON
|
|
jsonResponse.put("MobileNo", MobileNo);
|
|
jsonResponse.put("otp", otp);
|
|
|
|
// Convert the updated JSON object back to string
|
|
bodyMessage = jsonResponse.toString();
|
|
// bodyMessage=Response;
|
|
System.out.println("\n bodyMessage" + bodyMessage);
|
|
|
|
System.out.println("OTP sent successfully!");
|
|
|
|
} catch (Exception e) {
|
|
System.out.print("ERROR---: " + e);
|
|
bodyMessage = "Error";
|
|
}
|
|
HttpSession session = request.getSession();
|
|
session.setAttribute("otp", otp);
|
|
return bodyMessage;
|
|
|
|
}
|
|
|
|
// get licensedetails api
|
|
@GetMapping("/getLicenseDetails")
|
|
public ResponseEntity<?> getLicenseDetailsByMobileNo(
|
|
@RequestParam(value = "licenseno", required = false) String licenseno) {
|
|
if (licenseno == null || licenseno.isEmpty()) {
|
|
return ApiResponseUtil.invalidRequest("license number is required.");
|
|
}
|
|
|
|
try {
|
|
|
|
List<Map<String, Object>> licenseDetails = petRegistrationApiService.getLicenseListByMobNo(licenseno);
|
|
if (licenseDetails == null || licenseDetails.isEmpty()) {
|
|
return ApiResponseUtil.notFound("No bookings found for licenseno: " + licenseno);
|
|
}
|
|
|
|
// Success response
|
|
Map<String, Object> response = new HashMap<>();
|
|
response.put("status", "SUCCESS");
|
|
response.put("statuscode", "200");
|
|
response.put("licenseDetails", licenseDetails);
|
|
|
|
return ResponseEntity.ok(response);
|
|
|
|
} catch (Exception e) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
.body("Internal server error: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@GetMapping("/getCountByMobileNo")
|
|
public ResponseEntity<?> getCountByMobileNo(String mobileno) {
|
|
|
|
int mobileCount = petRegistrationApiService.getCountByMobileNo(mobileno);
|
|
|
|
System.out.println("mobileCount: " + mobileCount);
|
|
if(mobileCount>=3) {
|
|
return ApiResponseUtil.success(mobileCount, "Already you reached the license limit (Max 3 pets)");
|
|
}else {
|
|
return ApiResponseUtil.success(mobileCount, "You can proceed with the license registration");
|
|
}
|
|
}
|
|
|
|
|
|
}
|