Skip to content

Commit

Permalink
UI is ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
ugale-deepak3010 committed Jul 26, 2024
1 parent 580f78b commit 778e9ea
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 6 deletions.
5 changes: 5 additions & 0 deletions a4--deep-hotel-webpages/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>-->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class RoomReservationService {
@Autowired
ReservationRepo reservationRepo;

public List<RoomReservation> getRoomReservationForDate(String reservationDate) {
public List<RoomReservation> getRoomReservationForDate(String reservationDate, boolean getAll) {

Date resDate;

Expand Down Expand Up @@ -56,16 +56,27 @@ public List<RoomReservation> getRoomReservationForDate(String reservationDate) {

roomReservation.setReservationId(res.getId());
roomReservation.setReservationDate(res.getResDate().toString());
Optional<Guest> guest= guestRepo.findById(res.getGuestId());

Optional<Guest> guest = guestRepo.findById(res.getGuestId());

roomReservation.setGuestId(guest.get().getId());
roomReservation.setFirstName(guest.get().getFirstName());
roomReservation.setLastName(guest.get().getLastName());

});

return roomReservationMap.values().stream().toList();
return roomReservationMap.values().stream().filter(rs->{

if (getAll) {
return true;
}
if (rs.getReservationDate()!=null) {
if (rs.getReservationDate().equals(reservationDate)) {
return true;
}
}
return false;
} ).toList();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.DeepHotel.WebController;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.DeepHotel.Service.RoomReservationService;

@Controller
@RequestMapping("/occupancy")
public class OccupancyController {

@Autowired
RoomReservationService roomReservationService;

@GetMapping
public String getMethodName(Model model, @RequestParam(required = false) String resDate) {

Date date = new Date();
String todaysDate = new String();

String finalDate = new String();

boolean getAll = false;

if (resDate != null) {

try {
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// date = simpleDateFormat.parse(resDate);

LocalDate date2 = LocalDate.parse(resDate, DateTimeFormatter.ISO_DATE);

System.err.println(date);
System.out.println("--");
System.err.println(date2);
finalDate = date2.toString();

} catch (Exception e) {
System.err.println("exception caught in parsing date: " + e.getMessage());
}
} else {

getAll = true;
todaysDate = LocalDate.now().toString();
resDate=todaysDate;
finalDate = todaysDate;
}

System.err.println("1: " + finalDate);
System.err.println("2: " + resDate);
model.addAttribute("date", finalDate);
model.addAttribute("reservations", roomReservationService.getRoomReservationForDate(resDate, getAll));

return "occupancy";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.DeepHotel.WebController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.DeepHotel.Repository.RoomRepo;

import org.springframework.web.bind.annotation.GetMapping;

@Controller
@RequestMapping("/room")
public class RoomController {

@Autowired
RoomRepo roomRepo;

@GetMapping
public String getMethodName(Model model) {
model.addAttribute("rooms", roomRepo.findAll());
return "room-list";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.DeepHotel.WebController;

import org.springframework.stereotype.Controller;
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.ResponseBody;

@Controller
@RequestMapping("/welcome")
public class WelcomeController {

@GetMapping
@ResponseBody
public String getWelcome(@RequestParam(value = "name", required = false, defaultValue = "Deepak") String name) {

return "<h1>"+name+" Welcome!! </h1>";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ spring.datasource.username=postgres
spring.datasource.password=postgres

#we already added data in docker container



#Thyemeleaf

spring.mvc.view.suffix=.html
102 changes: 102 additions & 0 deletions a4--deep-hotel-webpages/src/main/resources/templates/occupancy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Thymeleaf | Rooms</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">

<button class="navbar-toggler" type="button"
data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">

<li class="nav-item"><a class="nav-link " th:href="@{/room}">Room</a>
</li>
<li class="nav-item"><a class="nav-link active "
aria-current="page" th:href="@{/occupancy}">occupancy</a></li>


<li class="nav-item"><a class="nav-link disabled"
aria-disabled="true">Disabled</a></li>
</ul>
</div>
<a class="navbar-brand" href="#">Occupancy</a>
</div>
</nav>

<div class="container">

<div class="container">
<input id="datePicker" class="btn btn-outline-primary" type="date" onchange="handleDate()"
th:value="${date}" />

<button type="button" onclick="clearFiler()"
class="btn btn-outline-danger">Clear Filter</button>

</div>

<table class="table table-striped table-hover ">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Room Name</th>
<th scope="col">Guest</th>
<th scope="col">Reservation Date</th>
</tr>
</thead>
<tbody class="table-group-divider">
<tr th:each="reservation: ${reservations}">
<th th:text="${reservation.roomNumber}">1</th>
<td th:text="${reservation.roomName}">roomName</td>
<td
th:text="${reservation.lastName}!=null?${reservation.lastName}+' '+${reservation.firstName}:'VACANT'">Guest</td>
<td th:text="${reservation.reservationDate}">reservationDate</td>
</tr>

</tbody>

</table>
</div>




<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
<script type="text/javascript">
function handleDate() {
let date = document.getElementById("datePicker").valueAsDate
let result = date.toISOString().split('T')[0]
if ('URLSearchParams' in window) {
var searchParams = new URLSearchParams(window.location.search);
searchParams.set("resDate", result)
window.location.search = searchParams.toString();
} else {
console.log("URLSearchParms not present");
var searchParams = new URLSearchParams(window.location.search);
searchParams.set("resDate", result)
window.location.search = searchParams.toString();
}
}

function clearFiler(){
window.location= window.location.href.replace(window.location.search, '')
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Thymeleaf | Rooms</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">

<button class="navbar-toggler" type="button"
data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">

<li class="nav-item">
<a class="nav-link active" aria-current="page" th:href="@{/room}">Room</a>
</li>
<li class="nav-item">
<a class="nav-link" th:href="@{/occupancy}">occupancy</a>
</li>


<li class="nav-item"><a class="nav-link disabled"
aria-disabled="true">Disabled</a></li>
</ul>
</div>
<a class="navbar-brand" href="#">Room</a>
</div>
</nav>

<div class="container">

<table class="table table-striped table-hover ">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Room Name</th>
<th scope="col">Bed Info</th>
</tr>
</thead>
<tbody class="table-group-divider">
<tr th:each="room: ${rooms}">
<th th:text="${room.roomNumber}">1</th>
<td th:text="${room.name}">Name</td>
<td th:text="${room.bedInfo}">bed Info</td>

</tr>

</tbody>
</table>
</div>




<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
</body>
</html>

0 comments on commit 778e9ea

Please sign in to comment.