Skip to content

Commit

Permalink
confirmation de reservation
Browse files Browse the repository at this point in the history
  • Loading branch information
e.elhjoujy committed Oct 22, 2023
1 parent 4ce971e commit 77df404
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class ReservationDaoImpl implements ReservationDao{
EntityManager entityManager = hyperJpa.getEntityManager();
EntityTransaction transaction = entityManager.getTransaction();
@Override
public void ajouterReservation(ReservationEntity reservationEntity) {
public boolean ajouterReservation(ReservationEntity reservationEntity) {

try {
transaction.begin();
entityManager.persist(reservationEntity.getClient());
Expand All @@ -27,10 +28,11 @@ public void ajouterReservation(ReservationEntity reservationEntity) {
}
entityManager.persist(reservationEntity);
transaction.commit();
return true;
}catch (Exception e){
transaction.rollback();
}

return false;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ma/yc/airafraik/dao/ReservationDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface ReservationDao {


public void ajouterReservation(ReservationEntity reservationEntity);
public boolean ajouterReservation(ReservationEntity reservationEntity);

public void modifierReservation(ReservationEntity reservationEntity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
public interface ReservationService {
public double confirmationReservation(ReservationEntity reservationEntity);
public double annulationReservation(ReservationEntity reservationEntity);
public boolean envoyerEmail(ReservationEntity reservationEntity);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ma.yc.airafraik.service.impl;

import ma.yc.airafraik.FunctionalTest.Client.ConfirmationReservationEtEnvoyeEmail;
import ma.yc.airafraik.core.Util;
import ma.yc.airafraik.dao.Impl.ReservationDaoImpl;
import ma.yc.airafraik.dao.ReservationDao;
Expand All @@ -11,6 +12,7 @@
public class ReservationServiceImpl implements ReservationService {

private PaiementService paiementService ;
private ConfirmationReservationEtEnvoyeEmail confirmationReservationEtEnvoyeEmail;
private ReservationDao reservationDao;

public ReservationServiceImpl() {
Expand Down Expand Up @@ -51,7 +53,16 @@ public double confirmationReservation(ReservationEntity reservationEntity) {
// Handle the case where the flight type is none of the specified values
}

this.reservationDao.ajouterReservation(reservationEntity);
boolean save = this.reservationDao.ajouterReservation(reservationEntity);
if (!save) {
// Handle the case where the reservation could not be saved
return 0;
}else {
//TODO : SEEND EMAIL TO CLIENT WITH HIS RESERVATION CODE AND PDF FILE
this.envoyerEmail(reservationEntity);

}

return totalCost;
}

Expand All @@ -62,4 +73,10 @@ public double annulationReservation(ReservationEntity reservationEntity) {

return 1;
}

@Override
public boolean envoyerEmail(ReservationEntity reservationEntity) {

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,19 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S



this.reservationService.confirmationReservation(reservationEntity);
Double prixtotal = this.reservationService.confirmationReservation(reservationEntity);

if (prixtotal == 0){
resp.sendRedirect("/sorry-try-again.jsp");
}

resp.sendRedirect("/thank-you.jsp");
req.setAttribute("client",client);
req.setAttribute("reservation",reservationEntity);
req.setAttribute("prixTotal",prixtotal);

req.getRequestDispatcher("thank-you.jsp").forward(req, resp);
//TODO : DISTROY THE SESSION
session.invalidate();

}

Expand Down
3 changes: 0 additions & 3 deletions src/main/webapp/reservation-confirmation-page.jsp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<%@ page import="java.util.Collection" %>
<%@ page import="ma.yc.airafraik.entities.VolEntity" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
%>


Expand Down
30 changes: 23 additions & 7 deletions src/main/webapp/thank-you.jsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
Expand All @@ -8,26 +9,41 @@
<div class="container">
<div class="text-center mt-5">
<h1>Thank You!</h1>
<h2 class="text-success ">
Your reservation has been successfully submitted.
</h2>
<h3>
Prix total : <c:out value="${prixTotal}"/> DH
</h3>
<p>Your reservation has been successfully submitted. Here are the details:</p>


<div class="alert alert-success">
<strong>Reservation Details:</strong>
<ul>
<li><strong>Name:</strong> John Doe</li>
<li><strong>Email:</strong> [email protected]</li>
<li><strong>Date:</strong> October 25, 2023</li>
<li><strong>Time:</strong> 7:00 PM</li>
<li><strong>Name:</strong>
<c:out value="${client.nom}"/>
</li>
<li><strong>Email:</strong>
<c:out value="${client.email}"/>
</li>
<%-- <li><strong>Date:</strong>--%>
<%-- <c:out value="${reservation.date_Reservation}"/>--%>
<%-- </li>--%>
<%-- <li><strong>Time:</strong>--%>
<%-- <c:out value="${reservation.heure_Reservation}"/>--%>
<%-- </li>--%>
</ul>
</div>

<p>If you have any questions or need further assistance, please contact our customer service:</p>
<address>
<strong>Customer Service:</strong><br>
Phone: (123) 456-7890<br>
Email: info@example.com
Phone: 0659707721 <br>
Email: elhjoujy@gmail.com
</address>

<a href="" class="btn btn-primary">Return to Home</a>
<a href="${pageContext.request.contextPath}/" class="btn btn-primary">Return to Home</a>
</div>
</div>

Expand Down

0 comments on commit 77df404

Please sign in to comment.