From 16f07f3cd6e227c08bb2f5c78496e982a9703109 Mon Sep 17 00:00:00 2001 From: SriPaari Date: Mon, 29 Sep 2025 13:24:35 +0530 Subject: [PATCH] http://10.100.1.53:3000/srishanmugip/Victoriapublichall_final.git --- .../controller/BookingController.java | 60 ++++++++++++-- .../controller/LoginController.java | 48 +++++++++++ .../controller/MainController.java | 23 ++++++ .../service/BookingService.java | 60 ++++++++++++-- .../service/LoginService.java | 34 ++++++++ src/main/resources/templates/admin/login.html | 81 +++++++++++++++++++ .../resources/templates/admin/reports.html | 60 ++++++++++++++ .../templates/fragments/admin-navmenu.html | 4 +- 8 files changed, 358 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/example/VictoriaPublicHall/controller/LoginController.java create mode 100644 src/main/java/com/example/VictoriaPublicHall/service/LoginService.java create mode 100644 src/main/resources/templates/admin/login.html create mode 100644 src/main/resources/templates/admin/reports.html diff --git a/src/main/java/com/example/VictoriaPublicHall/controller/BookingController.java b/src/main/java/com/example/VictoriaPublicHall/controller/BookingController.java index 21b0bd9..5d546e3 100644 --- a/src/main/java/com/example/VictoriaPublicHall/controller/BookingController.java +++ b/src/main/java/com/example/VictoriaPublicHall/controller/BookingController.java @@ -1,9 +1,13 @@ package com.example.VictoriaPublicHall.controller; import com.example.VictoriaPublicHall.service.BookingService; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; +import java.util.HashMap; import java.util.Map; @RestController @@ -17,20 +21,66 @@ public class BookingController { } @PostMapping("/savebooking") - public ResponseEntity> create(@RequestBody Map payload) { - return ResponseEntity.ok(service.create(payload)); + public ResponseEntity> create(@RequestBody(required = false) Map payload) { + try { + if (payload == null || payload.isEmpty()) { + return buildErrorResponse(HttpStatus.BAD_REQUEST.value(), "Request body is required"); + } + return ResponseEntity.ok(service.create(payload)); + } catch (ResponseStatusException ex) { + return buildErrorResponse(ex.getStatusCode().value(), ex.getReason()); + } catch (Exception ex) { + return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred"); + } } - @GetMapping("/summary/{refId}") - public ResponseEntity> getSummary(@PathVariable String refId) { - return ResponseEntity.ok(service.getSummary(refId)); + private ResponseEntity> buildErrorResponse(int status, String message) { + Map error = new HashMap<>(); + error.put("status", status); + error.put("error", HttpStatus.valueOf(status).getReasonPhrase()); + error.put("message", message); + return new ResponseEntity<>(error, HttpStatus.valueOf(status)); } + @GetMapping({"/summary","/summary/", "/summary/{refId}"}) + public ResponseEntity> getSummary(@PathVariable(required = false) String refId) { + if (refId == null || refId.isBlank()) { + return buildErrorResponse("refId"); + } + return ResponseEntity.ok(service.getSummary(refId)); + } @GetMapping("/occupied-seats") public ResponseEntity> getOccupiedSeats( @RequestParam String bookingDate, @RequestParam Long slotId) { + + if (bookingDate == null || bookingDate.isBlank()) { + return buildErrorResponse("bookingDate"); + } + if (slotId == null) { + return buildErrorResponse("slotId"); + } + return ResponseEntity.ok(service.getOccupiedSeats(bookingDate, slotId)); } + // Helper method for error response + private ResponseEntity> buildErrorResponse(String paramName) { + Map error = new HashMap<>(); + error.put("status", HttpStatus.BAD_REQUEST.value()); + error.put("error", "Missing Parameter"); + error.put("message", "Parameter '" + paramName + "' is required"); + return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST); + } + + @GetMapping("/getgroups") + public ResponseEntity> getGroups(){ + return ResponseEntity.ok(service.getGroups()); + } + + @GetMapping("/getslots") + public ResponseEntity> getSlots(){ + return ResponseEntity.ok(service.getSlots()); + } + } diff --git a/src/main/java/com/example/VictoriaPublicHall/controller/LoginController.java b/src/main/java/com/example/VictoriaPublicHall/controller/LoginController.java new file mode 100644 index 0000000..d51b354 --- /dev/null +++ b/src/main/java/com/example/VictoriaPublicHall/controller/LoginController.java @@ -0,0 +1,48 @@ +package com.example.VictoriaPublicHall.controller; + +import com.example.VictoriaPublicHall.service.LoginService; +import jakarta.servlet.http.HttpSession; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +@RequestMapping("/victoriapublichall") + +public class LoginController { + + @Autowired + private LoginService loginService; + + // Login validation + @PostMapping("/validatelogin") + public ResponseEntity checkLogin(@RequestParam String usernametxt, + @RequestParam String passwordtxt, + HttpSession session) { + System.out.println("Username: " + usernametxt); + System.out.println("Password: " + passwordtxt); + + try { + String userName = loginService.validateLogin(usernametxt, passwordtxt); + System.out.println("Received username: " + usernametxt + " and password: " + passwordtxt); + System.out.println("username .....:" + userName); + if (userName != null) { + // Set user info in the session + session.setAttribute("user_name",userName ); + + return ResponseEntity.ok(userName); + } else { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid username or password"); + } + } catch (Exception e) { + e.printStackTrace(); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Internal server error occurred"); + } + } + +} diff --git a/src/main/java/com/example/VictoriaPublicHall/controller/MainController.java b/src/main/java/com/example/VictoriaPublicHall/controller/MainController.java index a387372..d6540a6 100644 --- a/src/main/java/com/example/VictoriaPublicHall/controller/MainController.java +++ b/src/main/java/com/example/VictoriaPublicHall/controller/MainController.java @@ -1,8 +1,12 @@ package com.example.VictoriaPublicHall.controller; +import jakarta.servlet.http.HttpSession; 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; @RequestMapping(value = {"/","","/victoriapublichall"}) @Controller @@ -16,5 +20,24 @@ public class MainController { public String viewVictoriaHall(){ return "user/booking-summary"; } + @GetMapping("/login") + public String viewLogin(){ + return "admin/login"; + } + + + @GetMapping("/reports") + public String viewReports(Model model, HttpSession session) { + String userName = (String) session.getAttribute("user_name"); + + if (userName != null) { + System.out.println("User Name: " + userName); + model.addAttribute("user_name", userName); + return "admin/reports"; + } else { + System.out.println("User Name is null. Redirecting to admin login page."); + return "redirect:/victoriapublichall/login"; + } + } } diff --git a/src/main/java/com/example/VictoriaPublicHall/service/BookingService.java b/src/main/java/com/example/VictoriaPublicHall/service/BookingService.java index 09c269d..9f86138 100644 --- a/src/main/java/com/example/VictoriaPublicHall/service/BookingService.java +++ b/src/main/java/com/example/VictoriaPublicHall/service/BookingService.java @@ -244,12 +244,27 @@ public class BookingService { } public Map getOccupiedSeats(String bookingDate, Long slotId) { - String sql = " SELECT bs.seat_no FROM booking_slots bs " + - "JOIN registration_details r ON r.id = bs.booking_id WHERE r.booking_date = ? " + - "AND r.slot_id = ? AND r.is_delete = 0 "; + String sql = " SELECT bs.booking_id, r.group_id, bs.seat_no " + + "FROM booking_slots bs " + + "JOIN registration_details r ON r.id = bs.booking_id " + + "WHERE r.booking_date = ? AND r.slot_id = ? AND r.is_delete = 0 " + + "LIMIT 1"; - List seatStrings = jdbc.queryForList( + Map row = jdbc.queryForMap( sql, + LocalDate.parse(bookingDate), + slotId + ); + + Long bookingId = ((Number) row.get("booking_id")).longValue(); + Long groupId = ((Number) row.get("group_id")).longValue(); + + String seatSql = " SELECT bs.seat_no " + + "FROM booking_slots bs " + + "JOIN registration_details r ON r.id = bs.booking_id " + + "WHERE r.booking_date = ? AND r.slot_id = ? AND r.is_delete = 0 "; + + List seatStrings = jdbc.queryForList(seatSql, new Object[]{LocalDate.parse(bookingDate), slotId}, String.class ); @@ -262,12 +277,47 @@ public class BookingService { int availableCount = slotCapacity - occupiedSeats.size(); Map result = new HashMap<>(); - result.put("occupiedSeats", occupiedSeats); + result.put("slot_id", slotId); result.put("availableCount", availableCount); + result.put("occupiedSeats", occupiedSeats); result.put("capacity", slotCapacity); + Map booking = new HashMap<>(); + booking.put("booking_id", bookingId); + booking.put("group_id", groupId); + + result.put("bookings", Collections.singletonList(booking)); + return result; } + public Map getGroups() { + String sql = "SELECT id, group_name, group_slot " + + "FROM group_master WHERE is_delete = 0 AND is_active = 1"; + + List> list = jdbc.queryForList(sql); + + Map resp = new HashMap<>(); + resp.put("status", "success"); + resp.put("count", list.size()); + resp.put("data", list); + + return resp; + } + + public Map getSlots() { + String sql = "SELECT id, slot_timing " + + "FROM slots_master WHERE is_delete = 0 AND is_active = 1"; + + List> list = jdbc.queryForList(sql); + + Map resp = new HashMap<>(); + resp.put("status", "success"); + resp.put("count", list.size()); + resp.put("data", list); + + return resp; + } + } diff --git a/src/main/java/com/example/VictoriaPublicHall/service/LoginService.java b/src/main/java/com/example/VictoriaPublicHall/service/LoginService.java new file mode 100644 index 0000000..32e5b5c --- /dev/null +++ b/src/main/java/com/example/VictoriaPublicHall/service/LoginService.java @@ -0,0 +1,34 @@ +package com.example.VictoriaPublicHall.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +@Service +public class LoginService { + @Autowired + private JdbcTemplate jdbcTemplate; + public String validateLogin(String usernametxt, String passwordtxt) { + + System.out.println("sql:username: '" + usernametxt + "' and pin: '" + passwordtxt + "'"); + + // SQL query + String sql = "SELECT * FROM login WHERE user_name = ? AND password = ?"; + + // Execute the query and pass mobileNo and pin as parameters + List> results = jdbcTemplate.queryForList(sql, usernametxt, passwordtxt); + + System.out.println("results:" + results); + + // Check if any results were found + if (!results.isEmpty()) { + Map login = results.get(0); + return (String) login.get("user_name"); + } else { + return null; + } + } +} diff --git a/src/main/resources/templates/admin/login.html b/src/main/resources/templates/admin/login.html new file mode 100644 index 0000000..f1a2269 --- /dev/null +++ b/src/main/resources/templates/admin/login.html @@ -0,0 +1,81 @@ + + + + Login - Victoria Public Hall + + + + +
+
+
+
+ logo.png +
+
Greater Chennai Corporation
+
Victoria Public Hall
+
Admin Login
+
+
+ +
+ +
+
+ + +
+ +
+ + +
+ +
+
+ +
+
+
+
+ + + + + + diff --git a/src/main/resources/templates/admin/reports.html b/src/main/resources/templates/admin/reports.html new file mode 100644 index 0000000..9b4cf84 --- /dev/null +++ b/src/main/resources/templates/admin/reports.html @@ -0,0 +1,60 @@ + + + + + + Admin Reports + + + + + + +
+
+
+ + + + +
+ + + + +
+
+
+
+
+ + +
+
+
+
+
+ +
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+ + + + + diff --git a/src/main/resources/templates/fragments/admin-navmenu.html b/src/main/resources/templates/fragments/admin-navmenu.html index 5f048a1..5a05efc 100644 --- a/src/main/resources/templates/fragments/admin-navmenu.html +++ b/src/main/resources/templates/fragments/admin-navmenu.html @@ -2,7 +2,7 @@