diff --git a/applications/flights-ms/src/main/java/com/pcf/flights/FlightMicroservice.java b/applications/flights-ms/src/main/java/com/pcf/tripit/flights/FlightMicroservice.java similarity index 90% rename from applications/flights-ms/src/main/java/com/pcf/flights/FlightMicroservice.java rename to applications/flights-ms/src/main/java/com/pcf/tripit/flights/FlightMicroservice.java index f27f923..2523d1d 100644 --- a/applications/flights-ms/src/main/java/com/pcf/flights/FlightMicroservice.java +++ b/applications/flights-ms/src/main/java/com/pcf/tripit/flights/FlightMicroservice.java @@ -1,4 +1,4 @@ -package com.pcf.flights; +package com.pcf.tripit.flights; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/components/flights/src/main/resources/application.yml b/applications/flights-ms/src/main/resources/application.yml similarity index 88% rename from components/flights/src/main/resources/application.yml rename to applications/flights-ms/src/main/resources/application.yml index 961c7c4..d859205 100644 --- a/components/flights/src/main/resources/application.yml +++ b/applications/flights-ms/src/main/resources/application.yml @@ -6,7 +6,7 @@ spring: name: flights-ms jpa: - hibernate.ddl-auto: create + generate-ddl: true properties.hibernate.dialect: org.hibernate.dialect.MySQL5Dialect datasource: diff --git a/applications/hotels-ms/src/main/java/com/pcf/hotels/HotelMicroservice.java b/applications/hotels-ms/src/main/java/com/pcf/tripit/hotels/HotelMicroservice.java similarity index 90% rename from applications/hotels-ms/src/main/java/com/pcf/hotels/HotelMicroservice.java rename to applications/hotels-ms/src/main/java/com/pcf/tripit/hotels/HotelMicroservice.java index d1ad42a..12f5e57 100644 --- a/applications/hotels-ms/src/main/java/com/pcf/hotels/HotelMicroservice.java +++ b/applications/hotels-ms/src/main/java/com/pcf/tripit/hotels/HotelMicroservice.java @@ -1,4 +1,4 @@ -package com.pcf.hotels; +package com.pcf.tripit.hotels; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/components/hotels/src/main/resources/application.yml b/applications/hotels-ms/src/main/resources/application.yml similarity index 88% rename from components/hotels/src/main/resources/application.yml rename to applications/hotels-ms/src/main/resources/application.yml index 2e5b154..261e929 100644 --- a/components/hotels/src/main/resources/application.yml +++ b/applications/hotels-ms/src/main/resources/application.yml @@ -6,7 +6,7 @@ spring: name: hotels-ms jpa: - hibernate.ddl-auto: create + generate-ddl: true properties.hibernate.dialect: org.hibernate.dialect.MySQL5Dialect datasource: diff --git a/applications/tripit/build.gradle b/applications/tripit/build.gradle index 92c4d60..fa3f8f6 100644 --- a/applications/tripit/build.gradle +++ b/applications/tripit/build.gradle @@ -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') diff --git a/applications/tripit/src/main/java/com/pcf/tripit/MainController.java b/applications/tripit/src/main/java/com/pcf/tripit/MainController.java deleted file mode 100644 index a9b1a1e..0000000 --- a/applications/tripit/src/main/java/com/pcf/tripit/MainController.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.pcf.tripit; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; - -@Controller -public class MainController { - @GetMapping("/") - public String message(){ - return "index"; - } - -} diff --git a/applications/tripit/src/main/java/com/pcf/tripit/TripitApplication.java b/applications/tripit/src/main/java/com/pcf/tripit/TripitApplication.java index ffd98ca..6e81ab0 100644 --- a/applications/tripit/src/main/java/com/pcf/tripit/TripitApplication.java +++ b/applications/tripit/src/main/java/com/pcf/tripit/TripitApplication.java @@ -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(); + } } diff --git a/applications/tripit/src/main/resources/application.properties b/applications/tripit/src/main/resources/application.properties index e522006..9ada523 100644 --- a/applications/tripit/src/main/resources/application.properties +++ b/applications/tripit/src/main/resources/application.properties @@ -1,2 +1,3 @@ spring.mvc.view.prefix=/WEB-INF/ spring.mvc.view.suffix=.jsp +hotels.ms.url=http://localhost:8081/hotels diff --git a/applications/tripit/src/main/webapp/WEB-INF/hotel.jsp b/applications/tripit/src/main/webapp/WEB-INF/hotel.jsp index 5b81cb3..784d97d 100644 --- a/applications/tripit/src/main/webapp/WEB-INF/hotel.jsp +++ b/applications/tripit/src/main/webapp/WEB-INF/hotel.jsp @@ -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" %> + + Hotel @@ -99,13 +104,12 @@ - + - - - - - + + + + @@ -114,15 +118,14 @@ - ">< Prev  + ">< Prev  Showing records ${start} to ${end} of ${count} -  ">Next > +  ">Next > - - + diff --git a/applications/tripit/src/main/webapp/WEB-INF/index.jsp b/applications/tripit/src/main/webapp/WEB-INF/index.jsp index dfa8b9f..07f7810 100644 --- a/applications/tripit/src/main/webapp/WEB-INF/index.jsp +++ b/applications/tripit/src/main/webapp/WEB-INF/index.jsp @@ -31,7 +31,7 @@
- +
diff --git a/components/hotels/src/main/java/com/pcf/tripit/hotels/HotelController.java b/components/hotels/src/main/java/com/pcf/tripit/hotels/HotelController.java index 23730c8..a723a84 100644 --- a/components/hotels/src/main/java/com/pcf/tripit/hotels/HotelController.java +++ b/components/hotels/src/main/java/com/pcf/tripit/hotels/HotelController.java @@ -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 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 available = new ArrayList<>(); + for(Hotel hotel: hotelRepository.findAll()){ + boolean isAvailable = true; + Set 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 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 create(@RequestBody Hotel hotel){ hotelRepository.save(hotel); diff --git a/components/hotels/src/main/java/com/pcf/tripit/hotels/bookings/BookingController.java b/components/hotels/src/main/java/com/pcf/tripit/hotels/bookings/BookingController.java deleted file mode 100644 index b8535d3..0000000 --- a/components/hotels/src/main/java/com/pcf/tripit/hotels/bookings/BookingController.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.pcf.tripit.hotels.bookings; - -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class BookingController { -} diff --git a/components/hotels/src/main/java/com/pcf/tripit/hotels/bookings/BookingRepository.java b/components/hotels/src/main/java/com/pcf/tripit/hotels/bookings/BookingRepository.java index c37944c..99df1d8 100644 --- a/components/hotels/src/main/java/com/pcf/tripit/hotels/bookings/BookingRepository.java +++ b/components/hotels/src/main/java/com/pcf/tripit/hotels/bookings/BookingRepository.java @@ -4,5 +4,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface BookingRepository extends CrudRepository { +public interface BookingRepository extends CrudRepository { } diff --git a/components/ui/build.gradle b/components/ui/build.gradle new file mode 100644 index 0000000..8141b51 --- /dev/null +++ b/components/ui/build.gradle @@ -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") +} \ No newline at end of file diff --git a/components/ui/src/main/java/com/pcf/tripit/MainController.java b/components/ui/src/main/java/com/pcf/tripit/MainController.java new file mode 100644 index 0000000..592808c --- /dev/null +++ b/components/ui/src/main/java/com/pcf/tripit/MainController.java @@ -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 model){ + hotelInitialList.asList().forEach(hotelClient::create); + return "index"; + } + + /* @GetMapping("/setup") + public String setDatabase(){ + model.put("hotels", hotelClient.getAll()); + return "hotel"; + }*/ + +} diff --git a/components/ui/src/main/java/com/pcf/tripit/hotelui/HController.java b/components/ui/src/main/java/com/pcf/tripit/hotelui/HController.java index cb5fd4a..509787c 100644 --- a/components/ui/src/main/java/com/pcf/tripit/hotelui/HController.java +++ b/components/ui/src/main/java/com/pcf/tripit/hotelui/HController.java @@ -16,6 +16,6 @@ public HController(HotelClient hotelClient) { @GetMapping("/hotels") public String allHotels(Map model) { model.put("hotels", hotelClient.getAll() ); - return "hotels"; + return "hotel"; } } diff --git a/components/ui/src/main/java/com/pcf/tripit/hotelui/HotelClient.java b/components/ui/src/main/java/com/pcf/tripit/hotelui/HotelClient.java index a063f98..9652039 100644 --- a/components/ui/src/main/java/com/pcf/tripit/hotelui/HotelClient.java +++ b/components/ui/src/main/java/com/pcf/tripit/hotelui/HotelClient.java @@ -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); } diff --git a/settings.gradle b/settings.gradle index d83590a..a70bb0f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,4 +3,5 @@ include "applications:tripit" include "applications:hotels-ms" include "applications:flights-ms" include "components:flights" -include "components:hotels" \ No newline at end of file +include "components:hotels" +include "components:ui" \ No newline at end of file