From edafddbe39ba7de089c0a94a84da0366129ff4a6 Mon Sep 17 00:00:00 2001 From: KostyantynPanchenko Date: Wed, 26 Oct 2016 11:27:14 +0300 Subject: [PATCH] Panchenko. Added new features for tours - available in time slot, all and weekly schedule --- .../WEB-INF/views/excursions/excursions.jsp | 10 ++- .../views/excursions/excursionsAll.jsp | 13 +++- .../views/excursions/excursionsInSlot.jsp | 51 ++++++++++++++ .../excursions/excursionsInSlotResults.jsp | 66 +++++++++++++++++++ .../WEB-INF/views/exhibits/exhibits.jsp | 2 - .../museum/dao/generic/ExcursionDAO.java | 7 +- .../museum/dao/impl/ExcursionDAOimpl.java | 21 ++++-- .../museum/service/ExcursionService.java | 8 +-- .../service/impl/ExcursionServiceImpl.java | 14 ++-- .../utils/LocalDateTimeCustomFormatter.java | 2 +- .../web/controller/ExcursionsController.java | 49 ++++++++------ 11 files changed, 196 insertions(+), 47 deletions(-) create mode 100644 WebContent/WEB-INF/views/excursions/excursionsInSlot.jsp create mode 100644 WebContent/WEB-INF/views/excursions/excursionsInSlotResults.jsp diff --git a/WebContent/WEB-INF/views/excursions/excursions.jsp b/WebContent/WEB-INF/views/excursions/excursions.jsp index be6a301..db4c978 100644 --- a/WebContent/WEB-INF/views/excursions/excursions.jsp +++ b/WebContent/WEB-INF/views/excursions/excursions.jsp @@ -7,6 +7,8 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> + + @@ -31,8 +33,12 @@ -
- Weekly schedule +
+ diff --git a/WebContent/WEB-INF/views/excursions/excursionsAll.jsp b/WebContent/WEB-INF/views/excursions/excursionsAll.jsp index 1ae17fd..a355f90 100644 --- a/WebContent/WEB-INF/views/excursions/excursionsAll.jsp +++ b/WebContent/WEB-INF/views/excursions/excursionsAll.jsp @@ -6,8 +6,8 @@ <%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> - - + + @@ -36,6 +36,15 @@ +
+ +
diff --git a/WebContent/WEB-INF/views/excursions/excursionsInSlot.jsp b/WebContent/WEB-INF/views/excursions/excursionsInSlot.jsp new file mode 100644 index 0000000..2b79638 --- /dev/null +++ b/WebContent/WEB-INF/views/excursions/excursionsInSlot.jsp @@ -0,0 +1,51 @@ +<%@ page session="false" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> + + + + + + + + + + + +
+
+

Find available tours:

+
+
+

From:

+

To:

+

+
+
+
+
+ + + + + +
+
+ + + + diff --git a/WebContent/WEB-INF/views/excursions/excursionsInSlotResults.jsp b/WebContent/WEB-INF/views/excursions/excursionsInSlotResults.jsp new file mode 100644 index 0000000..f87c338 --- /dev/null +++ b/WebContent/WEB-INF/views/excursions/excursionsInSlotResults.jsp @@ -0,0 +1,66 @@ +<%@ page session="false" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> + + + + + + + + + + + + +
+
+

Tours in given time slot:

+ + + + + + + + + + + + + + + +
NameStartDurationGuide
${current.details.name}${myFormatter.format(current.start)}${current.details.duration}${current.guide.firstName} ${current.guide.lastName}
+
+ +

not found!

+
+
+
+
+ + +
+ +
+ + +
+
+ + + + diff --git a/WebContent/WEB-INF/views/exhibits/exhibits.jsp b/WebContent/WEB-INF/views/exhibits/exhibits.jsp index 38c02ef..d2f3983 100644 --- a/WebContent/WEB-INF/views/exhibits/exhibits.jsp +++ b/WebContent/WEB-INF/views/exhibits/exhibits.jsp @@ -4,8 +4,6 @@ <%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> - - diff --git a/src/com/softserve/museum/dao/generic/ExcursionDAO.java b/src/com/softserve/museum/dao/generic/ExcursionDAO.java index 1244728..5edbcc2 100644 --- a/src/com/softserve/museum/dao/generic/ExcursionDAO.java +++ b/src/com/softserve/museum/dao/generic/ExcursionDAO.java @@ -8,7 +8,6 @@ */ package com.softserve.museum.dao.generic; -import java.sql.Time; import java.time.LocalDateTime; import java.util.List; @@ -25,9 +24,11 @@ */ public interface ExcursionDAO extends GenericDAO { - public abstract List findExcursionByTime(Time start, Time end); + public abstract List findByTimeSlot(LocalDateTime start, LocalDateTime end); - public abstract List findExcursionByStart(Time start); + public abstract List findByStart(LocalDateTime start); + + public abstract List findByEnd(LocalDateTime start); public abstract List findInPeriod(LocalDateTime start, LocalDateTime end); diff --git a/src/com/softserve/museum/dao/impl/ExcursionDAOimpl.java b/src/com/softserve/museum/dao/impl/ExcursionDAOimpl.java index 5843293..9fe489e 100644 --- a/src/com/softserve/museum/dao/impl/ExcursionDAOimpl.java +++ b/src/com/softserve/museum/dao/impl/ExcursionDAOimpl.java @@ -8,7 +8,6 @@ */ package com.softserve.museum.dao.impl; -import java.sql.Time; import java.time.LocalDateTime; import java.util.List; @@ -42,19 +41,29 @@ protected ExcursionDAOimpl() { @SuppressWarnings("unchecked") @Override - public List findExcursionByTime(Time start, Time end) { + public List findByTimeSlot(LocalDateTime start, LocalDateTime end) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Excursion.class); criteria.add(Restrictions.ge("start", start)); - criteria.add(Restrictions.le("start", start)); + criteria.add(Restrictions.le("end", end)); return criteria.list(); } + @SuppressWarnings("unchecked") @Override - public List findExcursionByStart(Time start) { - // TODO Auto-generated method stub - return null; + public List findByStart(LocalDateTime start) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Excursion.class); + criteria.add(Restrictions.ge("start", start)); + return criteria.list(); } + @SuppressWarnings("unchecked") + @Override + public List findByEnd(LocalDateTime end) { + Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Excursion.class); + criteria.add(Restrictions.le("end", end)); + return criteria.list(); + } + @SuppressWarnings("unchecked") @Override public List findInPeriod(LocalDateTime start, LocalDateTime end) { diff --git a/src/com/softserve/museum/service/ExcursionService.java b/src/com/softserve/museum/service/ExcursionService.java index 46b3664..7be33c3 100644 --- a/src/com/softserve/museum/service/ExcursionService.java +++ b/src/com/softserve/museum/service/ExcursionService.java @@ -8,7 +8,7 @@ */ package com.softserve.museum.service; -import java.sql.Time; +import java.time.LocalDateTime; import java.util.List; import com.softserve.museum.domain.Excursion; @@ -33,11 +33,11 @@ public interface ExcursionService { public abstract List listExcursions(); - public abstract List findExcursionByTime(Time start, Time end); + public abstract List findByTimeSlot(LocalDateTime start, LocalDateTime end); - public abstract List findExcursionByStart(Time start); + public abstract List findByStart(LocalDateTime start); - public abstract List findExcursionByEnd(Time end); + public abstract List findByEnd(LocalDateTime end); public abstract List listSchedule(); } diff --git a/src/com/softserve/museum/service/impl/ExcursionServiceImpl.java b/src/com/softserve/museum/service/impl/ExcursionServiceImpl.java index ee68d72..26ca505 100644 --- a/src/com/softserve/museum/service/impl/ExcursionServiceImpl.java +++ b/src/com/softserve/museum/service/impl/ExcursionServiceImpl.java @@ -8,7 +8,7 @@ */ package com.softserve.museum.service.impl; -import java.sql.Time; +import java.time.LocalDateTime; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; @@ -44,18 +44,18 @@ public List listExcursions() { } @Override - public List findExcursionByTime(Time start, Time end) { - return excursions.findExcursionByTime(start, end); + public List findByTimeSlot(LocalDateTime start, LocalDateTime end) { + return excursions.findByTimeSlot(start, end); } @Override - public List findExcursionByStart(Time start) { - return excursions.findExcursionByStart(start); + public List findByStart(LocalDateTime start) { + return excursions.findByStart(start); } @Override - public List findExcursionByEnd(Time end) { - return excursions.findExcursionByStart(end); + public List findByEnd(LocalDateTime end) { + return excursions.findByEnd(end); } @Override diff --git a/src/com/softserve/museum/utils/LocalDateTimeCustomFormatter.java b/src/com/softserve/museum/utils/LocalDateTimeCustomFormatter.java index 7b0a3c8..702d12e 100644 --- a/src/com/softserve/museum/utils/LocalDateTimeCustomFormatter.java +++ b/src/com/softserve/museum/utils/LocalDateTimeCustomFormatter.java @@ -5,7 +5,7 @@ public class LocalDateTimeCustomFormatter { - private static final DateTimeFormatter patern = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"); + private static final DateTimeFormatter patern = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm"); public LocalDateTimeCustomFormatter() { System.out.println("Formatter created"); diff --git a/src/com/softserve/museum/web/controller/ExcursionsController.java b/src/com/softserve/museum/web/controller/ExcursionsController.java index 4b58c72..df4865f 100644 --- a/src/com/softserve/museum/web/controller/ExcursionsController.java +++ b/src/com/softserve/museum/web/controller/ExcursionsController.java @@ -9,12 +9,16 @@ package com.softserve.museum.web.controller; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; 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; import org.springframework.web.servlet.ModelAndView; import com.softserve.museum.domain.Excursion; @@ -53,24 +57,29 @@ public ModelAndView onTours() { return model; } -// @GetMapping("/available") -// public ModelAndView onAvailable() { -// ModelAndView model = new ModelAndView("guides/guidesAvailable"); -// List guides = guideService.listGuides(); -// model.addObject("guides", guides); -// return model; -// } -// -// @PostMapping("/available") -// public ModelAndView findAvailable(@RequestParam(name="start") String input) { -// String str = input.replace('T', ' '); -// System.out.println(str); -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); -// LocalDateTime start = LocalDateTime.parse(str, formatter); -// System.out.println(start); -// ModelAndView model = new ModelAndView("guides/guidesAvailable"); -// List guides = guideService.listGuides(); -// model.addObject("guides", guides); -// return model; -// } + @GetMapping("/timeslot") + public String onTimeslotGet() { + return "excursions/excursionsInSlot"; + } + + @PostMapping("/timeslot") + public ModelAndView onTimeslotPost( + @RequestParam(name="start") String start, + @RequestParam(name="end") String end) { + + ModelAndView model = new ModelAndView("excursions/excursionsInSlotResults"); + start = start.replace('T', ' '); + end = end.replace('T', ' '); + model.addObject("start", start); + model.addObject("end", end); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + LocalDateTime startTime = LocalDateTime.parse(start, formatter); + LocalDateTime endTime = LocalDateTime.parse(end, formatter); + + List excursions = excursionService.findByTimeSlot(startTime, endTime); + model.addObject("excursions", excursions); + return model; + } + }