Skip to content

Commit

Permalink
Whatever
Browse files Browse the repository at this point in the history
  • Loading branch information
pvepamb1 committed Sep 23, 2019
1 parent 3655413 commit 2bbfdc8
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pcf.flights;
package com.pcf.tripit.flights;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring:
name: flights-ms

jpa:
hibernate.ddl-auto: create
generate-ddl: true
properties.hibernate.dialect: org.hibernate.dialect.MySQL5Dialect

datasource:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pcf.hotels;
package com.pcf.tripit.hotels;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring:
name: hotels-ms

jpa:
hibernate.ddl-auto: create
generate-ddl: true
properties.hibernate.dialect: org.hibernate.dialect.MySQL5Dialect

datasource:
Expand Down
1 change: 1 addition & 0 deletions applications/tripit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencyManagement {
}

dependencies {
compile project(':components:ui')
compile('org.springframework.boot:spring-boot-starter-web')
compile('taglibs:standard:1.1.2')
compile('javax.servlet:jstl:1.2')
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
package com.pcf.tripit;

import com.pcf.tripit.hotelui.HotelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
public class TripitApplication {

@Value("${hotels.ms.url}")
private String url;

public static void main(String[] args) {
SpringApplication.run(TripitApplication.class, args);
}
//@Bean
/*public MovieClient movieClient(RestOperations restOperations) {
return new MovieClient("//movies-ms/movies", restOperations);
}*/

@Bean
public HotelClient hotelClient(RestOperations restOperations) {
return new HotelClient(url, restOperations);
}

@Bean
public RestOperations restOperations() {
return new RestTemplate();
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
spring.mvc.view.prefix=/WEB-INF/
spring.mvc.view.suffix=.jsp
hotels.ms.url=http://localhost:8081/hotels
25 changes: 14 additions & 11 deletions applications/tripit/src/main/webapp/WEB-INF/hotel.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c' %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:set var="language" value="${pageContext.request.locale}"/>
<fmt:setLocale value="${language}"/>
<html>
<head>
<title>Hotel</title>
Expand Down Expand Up @@ -99,13 +104,12 @@
</thead>

<tbody>
<c:forEach items="${hotels}" var="hotels">
<c:forEach items="${hotels}" var="hotel">
<tr>
<td><c:out value="${hotels.name}"/></td>
<td><c:out value="${hotels.address}"/></td>
<td><c:out value="${hotels.city}"/></td>
<td><c:out value="${hotels.price}"/></td>
<td><c:out value="${hotels.cost}"/></td>
<td><c:out value="${hotel.name}"/></td>
<td><c:out value="${hotel.address}"/></td>
<td><c:out value="${hotel.city}"/></td>
<td><c:out value="${hotel.price}"/></td>
<td><button class="button button2">Book</button></td>
</tr>
</c:forEach>
Expand All @@ -114,15 +118,14 @@

<c:if test="${count > 0}">
<c:if test="${page > 1}">
<a href="<c:url value="hotels"><c:param name="page" value="${page - 1}"/><c:param name="field" value="${field}"/><c:param name="key" value="${key}"/></c:url>">&lt; Prev</a>&nbsp;
<a href="<c:url value="moviefun"><c:param name="page" value="${page - 1}"/><c:param name="field" value="${field}"/><c:param name="key" value="${key}"/></c:url>">&lt; Prev</a>&nbsp;
</c:if>
Showing records ${start} to ${end} of ${count}
<c:if test="${page < pageCount}">
&nbsp;<a href="<c:url value="hotels"><c:param name="page" value="${page + 1}"/><c:param name="field" value="${field}"/><c:param name="key"
value="${key}"/></c:url>">Next &gt;</a>
&nbsp;<a href="<c:url value="moviefun"><c:param name="page" value="${page + 1}"/><c:param name="field" value="${field}"/><c:param name="key"
value="${key}"/></c:url>">Next &gt;</a>
</c:if>
</c:if>

</c:if>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion applications/tripit/src/main/webapp/WEB-INF/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<div class="hotelside">
<img src="../../assests/img/hotel.png" width="360px" height="360px" style="padding-left:150px; padding-top: 30px">
<button class="button" style="vertical-align:middle; margin-left: 250px; margin-top:90px"><span>Book Hotel </span></button>
<button onclick="window.location.href = '/hotels';" class="button" style="vertical-align:middle; margin-left: 250px; margin-top:90px"><span>Book Hotel </span></button>
</div>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,59 @@
package com.pcf.tripit.hotels;

import com.pcf.tripit.hotels.bookings.Booking;
import com.pcf.tripit.hotels.bookings.BookingID;
import com.pcf.tripit.hotels.bookings.BookingRepository;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/hotels")
public class HotelController {

private HotelRepository hotelRepository;
private BookingRepository bookingRepository;

public HotelController(HotelRepository hotelRepository) {
this.hotelRepository = hotelRepository;
}

/*@GetMapping
public Iterable<Hotel> getAvailable(@RequestParam String begin, @RequestParam String end) throws ParseException {
Date startDate = new SimpleDateFormat("YYYY/MM/DD").parse(begin);
Date endDate = new SimpleDateFormat("YYYY/MM/DD").parse(end);
List<Hotel> available = new ArrayList<>();
for(Hotel hotel: hotelRepository.findAll()){
boolean isAvailable = true;
Set<String> roomIdSet = new HashSet<>();
for(Booking booking: bookingRepository.findAll()){
if(hotel.getId()==booking.getId().getHotelId().getId() &&
!checkDateRange(startDate, endDate, booking.getBegin(), booking.getEnd())){
roomIdSet.add(booking.getId().getRoomId());
}
}
if(roomIdSet.size()>=hotel.getCapacity()) isAvailable = false;
if(isAvailable) available.add(hotel);
}
return available;
}*/

@GetMapping
private Iterable<Hotel> getavai(){
return hotelRepository.findAll();
}

private static boolean checkDateRange(Date start1, Date end1, Date start2, Date end2){
return((start1.before(start2) && end1.before(start2)) || (start1.after(end2) && end1.after(end2)));
}

@PostMapping
public ResponseEntity<Hotel> create(@RequestBody Hotel hotel){
hotelRepository.save(hotel);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.springframework.stereotype.Repository;

@Repository
public interface BookingRepository extends CrudRepository<BookingID, Long> {
public interface BookingRepository extends CrudRepository<Booking, BookingID> {
}
7 changes: 7 additions & 0 deletions components/ui/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apply from: "../../common.gradle"

dependencies {
compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
compile('commons-lang:commons-lang:2.4')
//compile("io.pivotal.spring.cloud:spring-cloud-services-starter-circuit-breaker:$SCSClientStartersVersion")
}
37 changes: 37 additions & 0 deletions components/ui/src/main/java/com/pcf/tripit/MainController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.pcf.tripit;

import com.pcf.tripit.hotelui.HotelClient;
import com.pcf.tripit.hotelui.HotelInitialList;
import com.pcf.tripit.hotelui.HotelUI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;

@Controller
public class MainController {

private HotelInitialList hotelInitialList;
private HotelClient hotelClient;

@Autowired
public MainController(HotelInitialList hotelInitialList, HotelClient hotelClient) {
this.hotelInitialList = hotelInitialList;
this.hotelClient = hotelClient;
}

@GetMapping("/")
public String message(Map<String, Object> model){
hotelInitialList.asList().forEach(hotelClient::create);
return "index";
}

/* @GetMapping("/setup")
public String setDatabase(){
model.put("hotels", hotelClient.getAll());
return "hotel";
}*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public HController(HotelClient hotelClient) {
@GetMapping("/hotels")
public String allHotels(Map<String, Object> model) {
model.put("hotels", hotelClient.getAll() );
return "hotels";
return "hotel";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public HotelClient(String hotelURL, RestOperations restOperations) {
this.restOperations = restOperations;
}

public void create(HotelClient hotel) {
public void create(HotelUI hotel) {
restOperations.postForEntity(hotelURL, hotel, HotelUI.class);
}

Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ include "applications:tripit"
include "applications:hotels-ms"
include "applications:flights-ms"
include "components:flights"
include "components:hotels"
include "components:hotels"
include "components:ui"

0 comments on commit 2bbfdc8

Please sign in to comment.