-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fonctionnalité de création d'une réservation
- Loading branch information
1 parent
762b7a9
commit 9bf729f
Showing
7 changed files
with
490 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<%@ page language="java" contentType="text/html; charset=US-ASCII" | ||
pageEncoding="US-ASCII"%> | ||
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%> | ||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
<html> | ||
<head> | ||
|
||
|
||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> | ||
<title>Reserve Bus</title> | ||
</head> | ||
<body> | ||
|
||
<h2>Reserve Bus</h2> | ||
|
||
<sf:form method="get" | ||
action="${pageContext.request.contextPath}/resultsfrom" | ||
commandName="bus"> | ||
|
||
<table class="formtable"> | ||
|
||
<tr> | ||
<td class="label">Leave From:</td> | ||
<td><sf:input class="control" path="leaveFrom" name="leaveFrom" | ||
type="text" /><br /> | ||
<div class="error"> | ||
<sf:errors path="leaveFrom"></sf:errors> | ||
</div></td> | ||
<tr> | ||
|
||
<td class="label">Going To:</td> | ||
<td><sf:input class="control" path="goingTo" name="goingTo" | ||
type="text" /><br /> | ||
<div class="error"> | ||
<sf:errors path="goingTo"></sf:errors> | ||
</div></td> | ||
<tr> | ||
<td class="label">Date Leave (YYYY-MM-DD):</td> | ||
|
||
<td><sf:input class="control" path="dateLeave" name="dateLeave" | ||
type="text" /><br /> | ||
<div class="error"> | ||
<sf:errors path="dateLeave"></sf:errors> | ||
</div></td> | ||
<tr> | ||
<td class="label">Date Return (YYYY-MM-DD):</td> | ||
<td><sf:input class="control" path="dateReturn" | ||
name="dateReturn" type="text" /><br /> | ||
<div class="error"> | ||
<sf:errors path="dateReturn"></sf:errors> | ||
</div></td> | ||
<tr> | ||
<td class="label"></td> | ||
<td><input class="control" value="Search" type="submit" /></td> | ||
</tr> | ||
</table> | ||
|
||
</sf:form> | ||
|
||
<c:forEach var="results" items="${results}"> | ||
<p> | ||
<c:out value="${results.leaveFrom}"></c:out> | ||
<c:out value="${results.dateLeave}"></c:out> | ||
<p> | ||
<c:out value="${results.goingTo}"></c:out> | ||
<c:out value="${results.dateReturn}"></c:out> | ||
<p> | ||
|
||
<c:if test="${results != null}"> | ||
<sf:form method="post" | ||
action="${pageContext.request.contextPath}/reservebook" | ||
commandName="bus"> | ||
|
||
<sf:input type="hidden" name="dateReturn" path="dateReturn" /> | ||
<sf:input type="hidden" name="dateLeave" path="dateLeave" /> | ||
<sf:input type="hidden" name="leaveFrom" path="leaveFrom" /> | ||
<sf:input type="hidden" name="goingTo" path="goingTo" /> | ||
|
||
<input class="control" value="Book" type="submit" /> | ||
|
||
|
||
</sf:form> | ||
</c:if> | ||
</c:forEach> | ||
|
||
|
||
|
||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.telly.controllers; | ||
|
||
import com.telly.dao.FormValidationGroup; | ||
import com.telly.dao.Reserve; | ||
import com.telly.service.ReserveService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import java.security.Principal; | ||
|
||
public class UserController { | ||
@Autowired | ||
ReserveService reserveService; | ||
@RequestMapping(value = "/reservebook", method = RequestMethod.POST) | ||
public String createReserveBook(@Validated(FormValidationGroup.class) Reserve reserve, BindingResult result, Principal principal) { | ||
|
||
if (result.hasErrors()) { | ||
return "reservebus"; | ||
} | ||
|
||
String username = principal.getName(); | ||
reserve.getUser().setUsername(username); | ||
|
||
reserveService.reserve(reserve); | ||
|
||
|
||
return "home"; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package com.telly.dao; | ||
|
||
import java.io.Serializable; | ||
import java.sql.Date; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
import javax.validation.constraints.Size; | ||
|
||
import org.hibernate.validator.constraints.NotBlank; | ||
|
||
@Entity | ||
@Table(name="reserve") | ||
public class Reserve implements Serializable { | ||
|
||
|
||
private static final long serialVersionUID = 5362437768854142524L; | ||
|
||
|
||
@Id | ||
@Column(name="dateleave") | ||
private Date dateLeave; | ||
|
||
|
||
@Column(name="datereturn") | ||
private Date dateReturn; | ||
|
||
@Column(name="leavingfrom") | ||
private String leaveFrom; | ||
|
||
@Column(name="goingto") | ||
private String goingTo; | ||
|
||
@ManyToOne | ||
@JoinColumn(name="username") | ||
private User user; | ||
|
||
|
||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public Reserve() { | ||
this.user = new User(); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
public Reserve(Date dateLeave, Date dateReturn, String leaveFrom, String goingTo, User user) { | ||
this.dateLeave = dateLeave; | ||
this.dateReturn = dateReturn; | ||
this.leaveFrom = leaveFrom; | ||
this.goingTo = goingTo; | ||
this.user = user; | ||
} | ||
|
||
|
||
public Date getDateLeave() { | ||
return dateLeave; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public void setDateLeave(Date dateLeave) { | ||
this.dateLeave = dateLeave; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public Date getDateReturn() { | ||
return dateReturn; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public void setDateReturn(Date dateReturn) { | ||
this.dateReturn = dateReturn; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public String getLeaveFrom() { | ||
return leaveFrom; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public void setLeaveFrom(String leaveFrom) { | ||
this.leaveFrom = leaveFrom; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public String getGoingTo() { | ||
return goingTo; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
public void setGoingTo(String goingTo) { | ||
this.goingTo = goingTo; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
@Override | ||
public String toString() { | ||
return "Bus [dateLeave=" + dateLeave + ", dateReturn=" + dateReturn + ", leaveFrom=" + leaveFrom + ", goingTo=" | ||
+ goingTo + "]"; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.telly.dao; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.Criteria; | ||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.criterion.Restrictions; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.access.annotation.Secured; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
|
||
|
||
@Repository | ||
@Transactional | ||
@Component("reserveDao") | ||
public class ReserveDao { | ||
|
||
@Autowired | ||
private SessionFactory sessionFactory; | ||
|
||
public Session session() { | ||
return sessionFactory.getCurrentSession(); | ||
} | ||
|
||
|
||
|
||
@Transactional | ||
public void reserve(Reserve reserve) { | ||
session().save(reserve); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public List<Reserve> getReserve(String username) { | ||
Criteria crit = session().createCriteria(Reserve.class); | ||
|
||
crit.add(Restrictions.eq("user.username", username)); | ||
|
||
return crit.list(); | ||
} | ||
|
||
} |
Oops, something went wrong.