SriPaari 1 year ago
parent
commit
16f07f3cd6
  1. 60
      src/main/java/com/example/VictoriaPublicHall/controller/BookingController.java
  2. 48
      src/main/java/com/example/VictoriaPublicHall/controller/LoginController.java
  3. 23
      src/main/java/com/example/VictoriaPublicHall/controller/MainController.java
  4. 60
      src/main/java/com/example/VictoriaPublicHall/service/BookingService.java
  5. 34
      src/main/java/com/example/VictoriaPublicHall/service/LoginService.java
  6. 81
      src/main/resources/templates/admin/login.html
  7. 60
      src/main/resources/templates/admin/reports.html
  8. 4
      src/main/resources/templates/fragments/admin-navmenu.html

60
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<Map<String, Object>> create(@RequestBody Map<String, Object> payload) {
return ResponseEntity.ok(service.create(payload));
public ResponseEntity<Map<String, Object>> create(@RequestBody(required = false) Map<String, Object> 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<Map<String, Object>> getSummary(@PathVariable String refId) {
return ResponseEntity.ok(service.getSummary(refId));
private ResponseEntity<Map<String, Object>> buildErrorResponse(int status, String message) {
Map<String, Object> 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<Map<String, Object>> 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<Map<String, Object>> 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<Map<String, Object>> buildErrorResponse(String paramName) {
Map<String, Object> 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<Map<String,Object>> getGroups(){
return ResponseEntity.ok(service.getGroups());
}
@GetMapping("/getslots")
public ResponseEntity<Map<String,Object>> getSlots(){
return ResponseEntity.ok(service.getSlots());
}
}

48
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<String> 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");
}
}
}

23
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";
}
}
}

60
src/main/java/com/example/VictoriaPublicHall/service/BookingService.java

@ -244,12 +244,27 @@ public class BookingService {
}
public Map<String, Object> 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<String> seatStrings = jdbc.queryForList(
Map<String, Object> 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<String> 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<String, Object> 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<String, Object> booking = new HashMap<>();
booking.put("booking_id", bookingId);
booking.put("group_id", groupId);
result.put("bookings", Collections.singletonList(booking));
return result;
}
public Map<String, Object> getGroups() {
String sql = "SELECT id, group_name, group_slot " +
"FROM group_master WHERE is_delete = 0 AND is_active = 1";
List<Map<String, Object>> list = jdbc.queryForList(sql);
Map<String, Object> resp = new HashMap<>();
resp.put("status", "success");
resp.put("count", list.size());
resp.put("data", list);
return resp;
}
public Map<String, Object> getSlots() {
String sql = "SELECT id, slot_timing " +
"FROM slots_master WHERE is_delete = 0 AND is_active = 1";
List<Map<String, Object>> list = jdbc.queryForList(sql);
Map<String, Object> resp = new HashMap<>();
resp.put("status", "success");
resp.put("count", list.size());
resp.put("data", list);
return resp;
}
}

34
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<Map<String, Object>> results = jdbcTemplate.queryForList(sql, usernametxt, passwordtxt);
System.out.println("results:" + results);
// Check if any results were found
if (!results.isEmpty()) {
Map<String, Object> login = results.get(0);
return (String) login.get("user_name");
} else {
return null;
}
}
}

81
src/main/resources/templates/admin/login.html

@ -0,0 +1,81 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Login - Victoria Public Hall</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
</head>
<body style="background: url('/images/vph_image.jpg') no-repeat center center fixed;
background-size: 100% 100%;"
class="d-flex align-items-center justify-content-center vh-100">
<div class="card shadow p-4" style="width: 400px; border-radius: 12px; background-color: rgba(255,255,255,0.95);">
<div class="row m-b-20">
<div class="col-md-12">
<div class="text-center">
<img src="/images/logo.png" width="60px" height="65px" alt="logo.png">
</div>
<h5 class="text-center" style="color:#15455D;">Greater Chennai Corporation</h5>
<h5 class="text-center mb-3" style="color:#15455D;">Victoria Public Hall</h5>
<h5 class="text-center" style="color:#01A9AC;">Admin Login</h5>
</div>
</div>
<div th:if="${error}" class="alert alert-danger text-center" th:text="${error}"></div>
<form class="md-float-material form-material" onsubmit="return login();">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="row mt-3">
<div class="col-md-12 text-center">
<button type="submit" class="btn"
style="background-color:#01A9AC; color:white; border:none; padding:8px 25px; border-radius:6px;">
Login
</button>
</div>
</div>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
function login() {
var usernametxt = $("#username").val();
var passwordtxt = $("#password").val();
$.ajax({
type: "POST",
url: '/victoriapublichall/validatelogin',
data: { usernametxt: usernametxt, passwordtxt: passwordtxt }
}).done(function (response) {
if (response && response !== "error") {
redirectToReports(response);
} else {
Swal.fire({ icon: 'error', title: 'Oops...', text: 'Invalid Username or Password!' });
$("#username").val(""); $("#password").val("");
}
}).fail(function () {
Swal.fire({ icon: 'error', title: 'Error', text: 'An unexpected error occurred. Please try again later.' });
});
return false;
}
function redirectToReports(userName) {
if (userName === "admin") {
window.location.href = "/victoriapublichall/reports";
} else {
console.error("Invalid referenceName:", userName);
}
}
</script>
</body>
</html>

60
src/main/resources/templates/admin/reports.html

@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="~{fragments/user-head :: head}">
<title>Admin Reports</title>
<!-- DataTables CSS -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.2/css/buttons.bootstrap4.min.css">
</head>
<body>
<div th:replace="~{fragments/preloader :: div}"></div>
<div id="pcoded" class="pcoded">
<div class="pcoded-container">
<!-- Top Navigation -->
<nav th:replace="~{fragments/user-nav :: nav}"></nav>
<div class="pcoded-main-container">
<!-- Sidebar Menu -->
<nav th:replace="~{fragments/admin-navmenu :: nav}"></nav>
<!-- Page Wrapper -->
<div class="pcoded-wrapper">
<div class="pcoded-content">
<div class="pcoded-inner-content">
<div class="main-body">
<div class="page-wrapper">
<!-- Container Fix -->
<div class="container-fluid mt-4">
<div class="row">
<div class="col-md-12">
<div class="card shadow-sm">
<div class="card-body">
</div>
</div>
</div>
</div>
</div>
<!-- End Container Fix -->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer th:replace="~{fragments/footer :: footer}"></footer>
<script th:replace="~{fragments/user-script :: script}"></script>
<script type="text/javascript">
</script>
</body>
</html>

4
src/main/resources/templates/fragments/admin-navmenu.html

@ -2,7 +2,7 @@
<div class="pcoded-inner-navbar">
<ul class="pcoded-item pcoded-left-item">
<li class="pcoded-hasmenu">
<a href="/heritagewalk/registration">
<a href="/victoriapublichall/reports">
<span class="pcoded-micon"><i class="feather icon-home"></i></span>
<span class="pcoded-mtext">Home</span>
@ -23,7 +23,7 @@
</button>
</li>
<li class="pcoded-hasmenu">
<a href="/heritagewalk/login">
<a href="/victoriapublichall/login">
<span class="pcoded-micon"><i class="fa fa-sign-out"></i></span>
<span class="pcoded-mtext">Logout</span>

Loading…
Cancel
Save