|
|
|
@ -11,6 +11,7 @@ import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.ui.Model; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
@ -180,70 +181,146 @@ public String viewWorkspaceList(Model model) { |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/home") |
|
|
|
public String viewHome(@RequestParam int bid, |
|
|
|
@RequestParam(value = "cid", required = false) Integer cidParam, |
|
|
|
Model model) { |
|
|
|
|
|
|
|
// ✅ Get coworking spaces for this building |
|
|
|
List<Map<String, Object>> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); |
|
|
|
@GetMapping("/home") |
|
|
|
public String viewHomeGet(@RequestParam(value = "bid", required = false) Integer bid, |
|
|
|
@RequestParam(value = "cid", required = false) Integer cidParam, |
|
|
|
Model model) { |
|
|
|
if (bid == null) { |
|
|
|
return "redirect:/muthalvarpadaippagam"; // or show error page |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//System.out.println("home inside:" + spaces); |
|
|
|
|
|
|
|
// Remove duplicate category rows (keep first per cid) |
|
|
|
spaces = spaces.stream() |
|
|
|
.collect(Collectors.toMap( |
|
|
|
m -> (Integer) m.get("cid"), |
|
|
|
m -> m, |
|
|
|
(existing, replacement) -> existing |
|
|
|
)) |
|
|
|
.values() |
|
|
|
.stream() |
|
|
|
.toList(); |
|
|
|
// ✅ Default CID → first space of that building |
|
|
|
Integer cid = (cidParam != null) |
|
|
|
? cidParam |
|
|
|
: (spaces.isEmpty() ? null : (Integer) spaces.get(0).get("cid")); |
|
|
|
|
|
|
|
// ✅ Get subcategory (pricing/capacity) details for this category |
|
|
|
/*List<Map<String, Object>> pricingDetails = (cid != null) |
|
|
|
? homeService.getPricingDetailsByCid(cid) |
|
|
|
: List.of();*/ |
|
|
|
List<Map<String, Object>> readingZoneDetails = homeService.getPricingDetailsByCid(cid); |
|
|
|
List<Map<String, Object>> deskSpaceDetails = homeService.getPricingDetailsByCid(cid); |
|
|
|
List<Map<String, Object>> conferenceHallDetails = homeService.getPricingDetailsByCid(cid); |
|
|
|
|
|
|
|
// ✅ Get category images for this category |
|
|
|
List<Map<String, Object>> homeImg = (cid != null) |
|
|
|
? homeService.getImgByCid(cid) |
|
|
|
: List.of(); |
|
|
|
|
|
|
|
// ✅ Identify the selected space |
|
|
|
Map<String, Object> selectedSpace = spaces.stream() |
|
|
|
.filter(space -> cid != null && cid.equals(space.get("cid"))) |
|
|
|
.findFirst() |
|
|
|
.orElse(null); |
|
|
|
//ak |
|
|
|
return loadHomePage(bid, cidParam, model); |
|
|
|
} |
|
|
|
// POST – used by hidden form (no URL params visible!) |
|
|
|
@PostMapping("/home") |
|
|
|
public String viewHomePost(@RequestParam int bid, |
|
|
|
@RequestParam(value = "cid", required = false) Integer cidParam, |
|
|
|
Model model) { |
|
|
|
return loadHomePage(bid, cidParam, model); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Add everything to model |
|
|
|
model.addAttribute("bid", bid); |
|
|
|
model.addAttribute("cid", cid); |
|
|
|
model.addAttribute("spaces", spaces); |
|
|
|
System.out.println("spaces:" + spaces); |
|
|
|
model.addAttribute("selectedSpace", selectedSpace); |
|
|
|
//model.addAttribute("pricingDetails", pricingDetails); |
|
|
|
model.addAttribute("readingZoneDetails", readingZoneDetails); |
|
|
|
model.addAttribute("deskSpaceDetails", deskSpaceDetails); |
|
|
|
model.addAttribute("conferenceHallDetails", conferenceHallDetails); |
|
|
|
model.addAttribute("homeImg", homeImg); |
|
|
|
// previously used |
|
|
|
// @GetMapping("/home") |
|
|
|
// public String viewHome(@RequestParam int bid, |
|
|
|
// @RequestParam(value = "cid", required = false) Integer cidParam, |
|
|
|
// Model model) { |
|
|
|
|
|
|
|
// // ✅ Get coworking spaces for this building |
|
|
|
// List<Map<String, Object>> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); |
|
|
|
|
|
|
|
|
|
|
|
return "user/home"; |
|
|
|
} |
|
|
|
// //System.out.println("home inside:" + spaces); |
|
|
|
|
|
|
|
// // Remove duplicate category rows (keep first per cid) |
|
|
|
// spaces = spaces.stream() |
|
|
|
// .collect(Collectors.toMap( |
|
|
|
// m -> (Integer) m.get("cid"), |
|
|
|
// m -> m, |
|
|
|
// (existing, replacement) -> existing |
|
|
|
// )) |
|
|
|
// .values() |
|
|
|
// .stream() |
|
|
|
// .toList(); |
|
|
|
// // ✅ Default CID → first space of that building |
|
|
|
// Integer cid = (cidParam != null) |
|
|
|
// ? cidParam |
|
|
|
// : (spaces.isEmpty() ? null : (Integer) spaces.get(0).get("cid")); |
|
|
|
|
|
|
|
// // ✅ Get subcategory (pricing/capacity) details for this category |
|
|
|
// /*List<Map<String, Object>> pricingDetails = (cid != null) |
|
|
|
// ? homeService.getPricingDetailsByCid(cid) |
|
|
|
// : List.of();*/ |
|
|
|
// List<Map<String, Object>> readingZoneDetails = homeService.getPricingDetailsByCid(cid); |
|
|
|
// List<Map<String, Object>> deskSpaceDetails = homeService.getPricingDetailsByCid(cid); |
|
|
|
// List<Map<String, Object>> conferenceHallDetails = homeService.getPricingDetailsByCid(cid); |
|
|
|
|
|
|
|
// // ✅ Get category images for this category |
|
|
|
// List<Map<String, Object>> homeImg = (cid != null) |
|
|
|
// ? homeService.getImgByCid(cid) |
|
|
|
// : List.of(); |
|
|
|
|
|
|
|
// // ✅ Identify the selected space |
|
|
|
// Map<String, Object> selectedSpace = spaces.stream() |
|
|
|
// .filter(space -> cid != null && cid.equals(space.get("cid"))) |
|
|
|
// .findFirst() |
|
|
|
// .orElse(null); |
|
|
|
// //ak |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // ✅ Add everything to model |
|
|
|
// model.addAttribute("bid", bid); |
|
|
|
// model.addAttribute("cid", cid); |
|
|
|
// model.addAttribute("spaces", spaces); |
|
|
|
// System.out.println("spaces:" + spaces); |
|
|
|
// model.addAttribute("selectedSpace", selectedSpace); |
|
|
|
// //model.addAttribute("pricingDetails", pricingDetails); |
|
|
|
// model.addAttribute("readingZoneDetails", readingZoneDetails); |
|
|
|
// model.addAttribute("deskSpaceDetails", deskSpaceDetails); |
|
|
|
// model.addAttribute("conferenceHallDetails", conferenceHallDetails); |
|
|
|
// model.addAttribute("homeImg", homeImg); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return "user/home"; |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 🔥 Reusable method |
|
|
|
private String loadHomePage(int bid, Integer cidParam, Model model) { |
|
|
|
|
|
|
|
// Get coworking spaces for this building |
|
|
|
List<Map<String, Object>> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); |
|
|
|
|
|
|
|
// Remove duplicate CIDs |
|
|
|
spaces = spaces.stream() |
|
|
|
.collect(Collectors.toMap( |
|
|
|
m -> (Integer) m.get("cid"), |
|
|
|
m -> m, |
|
|
|
(existing, replacement) -> existing |
|
|
|
)) |
|
|
|
.values() |
|
|
|
.stream() |
|
|
|
.toList(); |
|
|
|
|
|
|
|
// Default CID |
|
|
|
Integer cid = (cidParam != null) |
|
|
|
? cidParam |
|
|
|
: (spaces.isEmpty() ? null : (Integer) spaces.get(0).get("cid")); |
|
|
|
|
|
|
|
// Pricing details |
|
|
|
List<Map<String, Object>> readingZoneDetails = homeService.getPricingDetailsByCid(cid); |
|
|
|
List<Map<String, Object>> deskSpaceDetails = homeService.getPricingDetailsByCid(cid); |
|
|
|
List<Map<String, Object>> conferenceHallDetails = homeService.getPricingDetailsByCid(cid); |
|
|
|
|
|
|
|
// Images |
|
|
|
List<Map<String, Object>> homeImg = (cid != null) |
|
|
|
? homeService.getImgByCid(cid) |
|
|
|
: List.of(); |
|
|
|
|
|
|
|
// Selected category |
|
|
|
Map<String, Object> selectedSpace = spaces.stream() |
|
|
|
.filter(space -> cid != null && cid.equals(space.get("cid"))) |
|
|
|
.findFirst() |
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
// Add to model |
|
|
|
model.addAttribute("bid", bid); |
|
|
|
model.addAttribute("cid", cid); |
|
|
|
model.addAttribute("spaces", spaces); |
|
|
|
model.addAttribute("selectedSpace", selectedSpace); |
|
|
|
model.addAttribute("readingZoneDetails", readingZoneDetails); |
|
|
|
model.addAttribute("deskSpaceDetails", deskSpaceDetails); |
|
|
|
model.addAttribute("conferenceHallDetails", conferenceHallDetails); |
|
|
|
model.addAttribute("homeImg", homeImg); |
|
|
|
|
|
|
|
return "user/home"; // Thymeleaf view |
|
|
|
} |
|
|
|
|
|
|
|
//ak |
|
|
|
@GetMapping("/api/pricing") |
|
|
|
@ -529,59 +606,183 @@ public String getSpaceFragment(@RequestParam("cid") Integer cid, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/book") |
|
|
|
public String showCategoryPage(@RequestParam int buildingId, |
|
|
|
@RequestParam int categoryId, |
|
|
|
//////////existing code for /book with subId handling |
|
|
|
|
|
|
|
// @GetMapping("/book") |
|
|
|
// public String getCategoryPageGet(@RequestParam(value = "buildingId", required = false) Integer buildingId, |
|
|
|
// @RequestParam(value = "categoryId", required = false) Integer categoryId, |
|
|
|
// @RequestParam(value = "subId", required = false) Integer subId, |
|
|
|
// Model model) { |
|
|
|
|
|
|
|
// // Validate required fields |
|
|
|
// if (buildingId == null || categoryId == null) { |
|
|
|
// return "redirect:/muthalvarpadaippagam"; // Return home safely |
|
|
|
// } |
|
|
|
|
|
|
|
// return showCategoryPage(buildingId, categoryId, subId, model); |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// //added by yogi |
|
|
|
// @PostMapping("/book") |
|
|
|
// public String showCategoryPagePost(@RequestParam int buildingId, |
|
|
|
// @RequestParam int categoryId, |
|
|
|
// @RequestParam(required = false) Integer subId, |
|
|
|
// Model model) { |
|
|
|
|
|
|
|
// return showCategoryPage(buildingId, categoryId, subId, model); |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @GetMapping("/book") |
|
|
|
// public String showCategoryPage(@RequestParam int buildingId, |
|
|
|
// @RequestParam int categoryId, |
|
|
|
// @RequestParam(required = false) Integer subId, |
|
|
|
// Model model) { |
|
|
|
// // System.out.println("buildingId:" + buildingId); |
|
|
|
// // System.out.println("categoryId:" + categoryId); |
|
|
|
|
|
|
|
// List<Map<String, Object>> buildingCategoryDetails = |
|
|
|
// buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId); |
|
|
|
// //System.out.println("buildingCategoryDetails:" + buildingCategoryDetails); |
|
|
|
|
|
|
|
// model.addAttribute("homeImg", homeService.getImgByCid(categoryId)); |
|
|
|
|
|
|
|
// if (!buildingCategoryDetails.isEmpty()) { |
|
|
|
// Map<String, Object> firstRecord = buildingCategoryDetails.get(0); |
|
|
|
// model.addAttribute("details", firstRecord); |
|
|
|
// //ak |
|
|
|
// Object buildingName = firstRecord.get("Building_Name"); |
|
|
|
// Object buildingAddress = firstRecord.get("Address"); |
|
|
|
// Object latitude = firstRecord.get("Latitude"); |
|
|
|
// Object longitude = firstRecord.get("Longitude"); |
|
|
|
|
|
|
|
// model.addAttribute("buildingName", buildingName); |
|
|
|
// model.addAttribute("buildingAddress", buildingAddress); |
|
|
|
// model.addAttribute("latitude", latitude); |
|
|
|
// model.addAttribute("longitude", longitude); |
|
|
|
|
|
|
|
// // ✅ Prefer URL parameter subId, else fallback from DB |
|
|
|
// if (subId == null) { |
|
|
|
// Object scidObj = firstRecord.get("scid"); |
|
|
|
// subId = (scidObj != null) ? Integer.parseInt(scidObj.toString()) : 0; |
|
|
|
// } |
|
|
|
|
|
|
|
// model.addAttribute("subId", subId); |
|
|
|
// System.out.println("SubId: " + subId); |
|
|
|
// } |
|
|
|
|
|
|
|
// model.addAttribute("buildingId", buildingId); |
|
|
|
// model.addAttribute("categoryId", categoryId); |
|
|
|
|
|
|
|
// String url = switch (categoryId) { |
|
|
|
// case 1 -> "user/book-reading"; |
|
|
|
// case 2 -> "user/book-workdesk"; |
|
|
|
// case 3 -> "user/book-Conferance"; |
|
|
|
// case 4 -> "user/book-reading"; |
|
|
|
// default -> throw new IllegalArgumentException("Invalid category ID: " + categoryId); |
|
|
|
// }; |
|
|
|
|
|
|
|
// return url; |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// --------------------- GET : Visible URL --------------------- |
|
|
|
@GetMapping("/book") |
|
|
|
public String getCategoryPage(@RequestParam(value = "buildingId" ,required = false) Integer buildingId, |
|
|
|
@RequestParam(value = "categoryId", required = false) Integer categoryId, |
|
|
|
@RequestParam(value = "subId", required = false) Integer subId, Model model) { |
|
|
|
|
|
|
|
// Validate required fields |
|
|
|
if (buildingId == null || categoryId == null) { |
|
|
|
return "redirect:/muthalvarpadaippagam"; |
|
|
|
} |
|
|
|
|
|
|
|
return showCategoryPage(buildingId, categoryId, subId, model); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------- POST : Hidden Form (no URL params) --------------------- |
|
|
|
@PostMapping("/book") |
|
|
|
public String postCategoryPage(@RequestParam Integer buildingId, |
|
|
|
@RequestParam Integer categoryId, |
|
|
|
@RequestParam(required = false) Integer subId, |
|
|
|
Model model) { |
|
|
|
// System.out.println("buildingId:" + buildingId); |
|
|
|
// System.out.println("categoryId:" + categoryId); |
|
|
|
|
|
|
|
return showCategoryPage(buildingId, categoryId, subId, model); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------- COMMON LOADING METHOD --------------------- |
|
|
|
private String showCategoryPage(int buildingId, |
|
|
|
int categoryId, |
|
|
|
Integer subId, |
|
|
|
Model model) { |
|
|
|
|
|
|
|
List<Map<String, Object>> buildingCategoryDetails = |
|
|
|
buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId); |
|
|
|
//System.out.println("buildingCategoryDetails:" + buildingCategoryDetails); |
|
|
|
|
|
|
|
model.addAttribute("homeImg", homeService.getImgByCid(categoryId)); |
|
|
|
|
|
|
|
String displayName = null; |
|
|
|
|
|
|
|
|
|
|
|
if (!buildingCategoryDetails.isEmpty()) { |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> firstRecord = buildingCategoryDetails.get(0); |
|
|
|
displayName = (String) firstRecord.get("Category_Display_Name"); |
|
|
|
|
|
|
|
model.addAttribute("details", firstRecord); |
|
|
|
//ak |
|
|
|
Object buildingName = firstRecord.get("Building_Name"); |
|
|
|
Object buildingAddress = firstRecord.get("Address"); |
|
|
|
Object latitude = firstRecord.get("Latitude"); |
|
|
|
Object longitude = firstRecord.get("Longitude"); |
|
|
|
|
|
|
|
model.addAttribute("buildingName", buildingName); |
|
|
|
model.addAttribute("buildingAddress", buildingAddress); |
|
|
|
model.addAttribute("latitude", latitude); |
|
|
|
model.addAttribute("longitude", longitude); |
|
|
|
|
|
|
|
// ✅ Prefer URL parameter subId, else fallback from DB |
|
|
|
|
|
|
|
model.addAttribute("buildingName", firstRecord.get("Building_Name")); |
|
|
|
model.addAttribute("buildingAddress", firstRecord.get("Address")); |
|
|
|
model.addAttribute("latitude", firstRecord.get("Latitude")); |
|
|
|
model.addAttribute("longitude", firstRecord.get("Longitude")); |
|
|
|
|
|
|
|
// If subId is not passed, get from DB |
|
|
|
if (subId == null) { |
|
|
|
Object scidObj = firstRecord.get("scid"); |
|
|
|
subId = (scidObj != null) ? Integer.parseInt(scidObj.toString()) : 0; |
|
|
|
} |
|
|
|
|
|
|
|
model.addAttribute("subId", subId); |
|
|
|
System.out.println("SubId: " + subId); |
|
|
|
} |
|
|
|
|
|
|
|
model.addAttribute("buildingId", buildingId); |
|
|
|
model.addAttribute("categoryId", categoryId); |
|
|
|
|
|
|
|
String url = switch (categoryId) { |
|
|
|
case 1 -> "user/book-reading"; |
|
|
|
case 2 -> "user/book-workdesk"; |
|
|
|
case 3 -> "user/book-Conferance"; |
|
|
|
case 4 -> "user/book-reading"; |
|
|
|
default -> throw new IllegalArgumentException("Invalid category ID: " + categoryId); |
|
|
|
}; |
|
|
|
// Select page by category |
|
|
|
// return switch (categoryId) { |
|
|
|
// case 1 -> "user/book-reading"; |
|
|
|
// case 2 -> "user/book-workdesk"; |
|
|
|
// case 3 -> "user/book-Conferance"; |
|
|
|
// case 4 -> "user/book-reading"; |
|
|
|
// default -> throw new IllegalArgumentException("Invalid category ID: " + categoryId); |
|
|
|
// }; |
|
|
|
|
|
|
|
return url; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (displayName == null) { |
|
|
|
throw new IllegalArgumentException("Category name not found"); |
|
|
|
} |
|
|
|
|
|
|
|
String url = switch (displayName.trim()) { |
|
|
|
case "Meeting Rooms" -> "user/book-Conferance"; |
|
|
|
case "Learning Centre" -> "user/book-reading"; |
|
|
|
case "Desk Space" -> "user/book-workdesk"; |
|
|
|
default -> throw new IllegalArgumentException("Unknown Category Name: " + displayName); |
|
|
|
}; |
|
|
|
|
|
|
|
return url; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|