Skip to content

Commit

Permalink
fonctionnalité de création d'une réservation
Browse files Browse the repository at this point in the history
  • Loading branch information
HadadjMeriem committed Jan 15, 2022
1 parent 762b7a9 commit 9bf729f
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 0 deletions.
92 changes: 92 additions & 0 deletions WebContent/WEB-INF/jsps/results.jsp
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>
21 changes: 21 additions & 0 deletions src/main/java/com/telly/controllers/BusController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import java.security.Principal;
import java.util.List;

import org.springframework.web.bind.annotation.RequestMethod;
import com.telly.dao.FormValidationGroup;
public class BusController {
Expand All @@ -33,4 +35,23 @@ public String createReserve(@Validated(FormValidationGroup.class) Bus bus, Bindi
return "home";

}
@RequestMapping("/results")
public String leave(Model model, Principal principal) {

model.addAttribute("bus", new Bus());

return "results";
}
@RequestMapping(value = "/resultsfrom", method = RequestMethod.GET)
public String leaveFrom(@Validated(FormValidationGroup.class) Bus bus, BindingResult result, Model model,
Principal principal) {

List<Bus> results = busService.getCity(bus.getLeaveFrom(), bus.getGoingTo(), bus.getDateLeave(),
bus.getDateReturn());
model.addAttribute("results", results);
System.out.println(results);

return "results";

}
}
33 changes: 33 additions & 0 deletions src/main/java/com/telly/controllers/UserController.java
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";

}
}
160 changes: 160 additions & 0 deletions src/main/java/com/telly/dao/Reserve.java
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 + "]";
}












}
45 changes: 45 additions & 0 deletions src/main/java/com/telly/dao/ReserveDao.java
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();
}

}
Loading

0 comments on commit 9bf729f

Please sign in to comment.