Skip to content

Commit

Permalink
Panchenko. Added new features for tours - available in time slot, all…
Browse files Browse the repository at this point in the history
… and weekly schedule
  • Loading branch information
KostyantynPanchenko committed Oct 26, 2016
1 parent 19264eb commit edafddb
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 47 deletions.
10 changes: 8 additions & 2 deletions WebContent/WEB-INF/views/excursions/excursions.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<spring:url value="/tours/all" var="all" />
<spring:url value="/tours/timeslot" var="slot" />
<spring:url value="/tours/from" var="from" />

<html>
<jsp:include page="../head.jsp"></jsp:include>
Expand All @@ -31,8 +33,12 @@
</c:forEach>
</table>
</c:if>
<br/>
<a href="${all}" class="w3-btn-block w3-teal">Weekly schedule</a>
<br/>
<div class="w3-container w3-content w3-center w3-padding-32" style="max-width: 200px">
<p><a href="${all}" class="w3-btn-block w3-round w3-teal">Weekly schedule</a></p>
<p><a href="${slot}" class="w3-btn-block w3-round w3-teal">From .. to ..</a></p>
<!--p><a href="${from}" class="w3-btn-block w3-round w3-teal">All after...</a></p-->
</div>
</div>
</div>

Expand Down
13 changes: 11 additions & 2 deletions WebContent/WEB-INF/views/excursions/excursionsAll.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<spring:url value="/resources/images/cover.jpg" var="coverPhoto" />
<spring:url value="/resources/images/avatar.png" var="avatar" />
<spring:url value="/tours" var="tours" />
<spring:url value="/tours/timeslot" var="slot" />

<html>
<jsp:include page="../head.jsp"></jsp:include>
Expand Down Expand Up @@ -36,6 +36,15 @@
</table>
</c:if>
</div>
<div class="w3-content" style="max-width: 2000px;">
<div class="w3-container w3-content w3-center" style="max-width: 800px" >
<h3 class="w3-wide"><spring:message code="menu.tours" /></h3>
<div class="w3-container w3-content w3-center" style="max-width: 200px">
<p><a href="${tours}" class="w3-btn-block w3-round w3-teal">Available tours</a></p>
<p><a href="${slot}" class="w3-btn-block w3-round w3-teal">From .. to ..</a></p>
</div>
</div>
</div>
</div>

<!-- Footer -->
Expand Down
51 changes: 51 additions & 0 deletions WebContent/WEB-INF/views/excursions/excursionsInSlot.jsp
Original file line number Diff line number Diff line change
@@ -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" %>

<spring:url value="/tours/all" var="all" />
<spring:url value="/tours/timeslot" var="slot" />
<spring:url value="/tours/from" var="from" />

<html>
<jsp:include page="../head.jsp"></jsp:include>
<body>
<jsp:include page="../menu.jsp"></jsp:include>

<!-- Page content -->
<div class="w3-content" style="max-width: 2000px; margin-top: 46px">
<div class="w3-container w3-content w3-center w3-padding-64" style="max-width: 800px" >
<h2 class="w3-wide">Find available tours:</h2>
<div class="w3-container w3-content w3-center" style="max-width:260px">
<form method="POST" action="${slot}">
<p>From: <input type="datetime-local" name="start" class="w3-input w3-border" /></p>
<p>To: <input type="datetime-local" name="end" class="w3-input w3-border" /></p>
<p><input type="submit" class="w3-btn-block w3-round w3-teal"/></p>
</form>
</div>
</div>
</div>


<div class="w3-content" style="max-width: 2000px;">
<div class="w3-container w3-content w3-center"
style="max-width: 800px" >
<h3 class="w3-wide"><spring:message code="menu.tours" /></h3>
<div class="w3-container w3-content w3-center" style="max-width: 200px">
<p><a href="${tours}" class="w3-btn-block w3-round w3-teal">Available tours</a></p>
<p><a href="${all}" class="w3-btn-block w3-round w3-teal">Weekly schedule</a></p>
</div>
</div>
</div>

<!-- Footer -->
<footer
class="w3-container w3-padding-64 w3-center w3-opacity w3-light-grey w3-xlarge">
</footer>

</body>
</html>

66 changes: 66 additions & 0 deletions WebContent/WEB-INF/views/excursions/excursionsInSlotResults.jsp
Original file line number Diff line number Diff line change
@@ -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" %>

<spring:url value="/tours" var="tours" />
<spring:url value="/tours/all" var="all" />
<spring:url value="/tours/timeslot" var="slot" />
<spring:url value="/tours/from" var="from" />

<html>
<jsp:include page="../head.jsp"></jsp:include>
<body>
<jsp:include page="../menu.jsp"></jsp:include>

<!-- Page content -->
<div class="w3-content" style="max-width: 2000px; margin-top: 46px">
<div class="w3-container w3-content w3-center w3-padding-64" style="max-width: 800px" >
<h2 class="w3-wide">Tours in given time slot:</h2>
<c:choose>
<c:when test="${not empty excursions}">
<table class="w3-table w3-striped w3-border w3-bordered w3-hoverable">
<thead>
<tr class="w3-light-grey"><th>Name</th><th>Start</th><th>Duration</th><th>Guide</th></tr>
</thead>
<jsp:useBean id="myFormatter" class="com.softserve.museum.utils.LocalDateTimeCustomFormatter" scope="page"></jsp:useBean>
<c:forEach items="${excursions}" var="current">
<tr>
<td>${current.details.name}</td>
<td>${myFormatter.format(current.start)}</td>
<td>${current.details.duration}</td>
<td>${current.guide.firstName} ${current.guide.lastName}</td>
</tr>
</c:forEach>
</table>
</c:when>
<c:otherwise>
<h2 class="w3-wide">not found!</h2>
</c:otherwise>
</c:choose>
</div>
</div>


<div class="w3-content" style="max-width: 2000px;">
<div class="w3-container w3-content w3-center" style="max-width: 800px" >
<h3 class="w3-wide"><spring:message code="menu.tours" /></h3>
<div class="w3-container w3-content w3-center" style="max-width: 200px">
<p><a href="${tours}" class="w3-btn-block w3-round w3-teal">Available tours</a></p>
<p><a href="${all}" class="w3-btn-block w3-round w3-teal">Weekly schedule</a></p>
<!--p><a href="${from}" class="w3-btn-block w3-round w3-teal">All after...</a></p-->
</div>
</div>
</div>

<!-- Footer -->
<footer
class="w3-container w3-padding-64 w3-center w3-opacity w3-light-grey w3-xlarge">
</footer>

</body>
</html>

2 changes: 0 additions & 2 deletions WebContent/WEB-INF/views/exhibits/exhibits.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<spring:url value="/resources/images/cover.jpg" var="coverPhoto" />
<spring:url value="/resources/images/avatar.png" var="avatar" />
<spring:url value="/exhibits/all" var="all" />
<spring:url value="/exhibits/byAuthor" var="byAuthor" />
<spring:url value="/exhibits/byMaterial" var="byMaterial" />
Expand Down
7 changes: 4 additions & 3 deletions src/com/softserve/museum/dao/generic/ExcursionDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
package com.softserve.museum.dao.generic;

import java.sql.Time;
import java.time.LocalDateTime;
import java.util.List;

Expand All @@ -25,9 +24,11 @@
*/
public interface ExcursionDAO extends GenericDAO<Excursion, Integer> {

public abstract List<Excursion> findExcursionByTime(Time start, Time end);
public abstract List<Excursion> findByTimeSlot(LocalDateTime start, LocalDateTime end);

public abstract List<Excursion> findExcursionByStart(Time start);
public abstract List<Excursion> findByStart(LocalDateTime start);

public abstract List<Excursion> findByEnd(LocalDateTime start);

public abstract List<Excursion> findInPeriod(LocalDateTime start,
LocalDateTime end);
Expand Down
21 changes: 15 additions & 6 deletions src/com/softserve/museum/dao/impl/ExcursionDAOimpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
package com.softserve.museum.dao.impl;

import java.sql.Time;
import java.time.LocalDateTime;
import java.util.List;

Expand Down Expand Up @@ -42,19 +41,29 @@ protected ExcursionDAOimpl() {

@SuppressWarnings("unchecked")
@Override
public List<Excursion> findExcursionByTime(Time start, Time end) {
public List<Excursion> 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<Excursion> findExcursionByStart(Time start) {
// TODO Auto-generated method stub
return null;
public List<Excursion> findByStart(LocalDateTime start) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Excursion.class);
criteria.add(Restrictions.ge("start", start));
return criteria.list();
}

@SuppressWarnings("unchecked")
@Override
public List<Excursion> findByEnd(LocalDateTime end) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Excursion.class);
criteria.add(Restrictions.le("end", end));
return criteria.list();
}

@SuppressWarnings("unchecked")
@Override
public List<Excursion> findInPeriod(LocalDateTime start, LocalDateTime end) {
Expand Down
8 changes: 4 additions & 4 deletions src/com/softserve/museum/service/ExcursionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,11 +33,11 @@ public interface ExcursionService {

public abstract List<ExcursionDetails> listExcursions();

public abstract List<Excursion> findExcursionByTime(Time start, Time end);
public abstract List<Excursion> findByTimeSlot(LocalDateTime start, LocalDateTime end);

public abstract List<Excursion> findExcursionByStart(Time start);
public abstract List<Excursion> findByStart(LocalDateTime start);

public abstract List<Excursion> findExcursionByEnd(Time end);
public abstract List<Excursion> findByEnd(LocalDateTime end);

public abstract List<Excursion> listSchedule();
}
14 changes: 7 additions & 7 deletions src/com/softserve/museum/service/impl/ExcursionServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,18 +44,18 @@ public List<ExcursionDetails> listExcursions() {
}

@Override
public List<Excursion> findExcursionByTime(Time start, Time end) {
return excursions.findExcursionByTime(start, end);
public List<Excursion> findByTimeSlot(LocalDateTime start, LocalDateTime end) {
return excursions.findByTimeSlot(start, end);
}

@Override
public List<Excursion> findExcursionByStart(Time start) {
return excursions.findExcursionByStart(start);
public List<Excursion> findByStart(LocalDateTime start) {
return excursions.findByStart(start);
}

@Override
public List<Excursion> findExcursionByEnd(Time end) {
return excursions.findExcursionByStart(end);
public List<Excursion> findByEnd(LocalDateTime end) {
return excursions.findByEnd(end);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
49 changes: 29 additions & 20 deletions src/com/softserve/museum/web/controller/ExcursionsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,24 +57,29 @@ public ModelAndView onTours() {
return model;
}

// @GetMapping("/available")
// public ModelAndView onAvailable() {
// ModelAndView model = new ModelAndView("guides/guidesAvailable");
// List<Guide> 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<Guide> 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<Excursion> excursions = excursionService.findByTimeSlot(startTime, endTime);
model.addObject("excursions", excursions);
return model;
}

}

0 comments on commit edafddb

Please sign in to comment.