-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
e.elhjoujy
committed
Oct 22, 2023
1 parent
9b2f68f
commit 4ce971e
Showing
15 changed files
with
249 additions
and
63 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
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
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
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 |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
|
||
public enum ReservationStatus { | ||
CONFIRMED, | ||
CANCELLED, | ||
EN_ATTENTE, | ||
PENDING | ||
ANNULER , | ||
EXPIRE | ||
|
||
} |
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,7 @@ | ||
package ma.yc.airafraik.enums; | ||
|
||
public enum ReserveType { | ||
ALLER, // Represents a one-way flight | ||
RETOUR, // Represents a return (round-trip) flight | ||
ALLER_RETOUR // Represents a round-trip flight | ||
} |
6 changes: 4 additions & 2 deletions
6
src/main/java/ma/yc/airafraik/service/ReservationService.java
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package ma.yc.airafraik.service; | ||
|
||
import ma.yc.airafraik.entities.ReservationEntity; | ||
|
||
public interface ReservationService { | ||
public double confirmationReservation(Object object); | ||
public double annulationReservation(Object object); | ||
public double confirmationReservation(ReservationEntity reservationEntity); | ||
public double annulationReservation(ReservationEntity reservationEntity); | ||
} |
44 changes: 40 additions & 4 deletions
44
src/main/java/ma/yc/airafraik/service/impl/ReservationServiceImpl.java
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
73 changes: 70 additions & 3 deletions
73
src/main/java/ma/yc/airafraik/web/RservationConfirmationController.java
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 |
---|---|---|
@@ -1,47 +1,114 @@ | ||
package ma.yc.airafraik.web; | ||
|
||
import jakarta.servlet.ServletConfig; | ||
import jakarta.servlet.ServletContext; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.annotation.WebServlet; | ||
import jakarta.servlet.http.HttpServlet; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import jakarta.servlet.http.HttpSession; | ||
import ma.yc.airafraik.core.Print; | ||
import ma.yc.airafraik.entities.ClientEntity; | ||
import ma.yc.airafraik.entities.ReservationEntity; | ||
import ma.yc.airafraik.entities.VolEntity; | ||
import ma.yc.airafraik.enums.ReservationStatus; | ||
import ma.yc.airafraik.service.ReservationService; | ||
import ma.yc.airafraik.service.SearchVolsService; | ||
import ma.yc.airafraik.service.impl.ReservationServiceImpl; | ||
import ma.yc.airafraik.service.impl.SearchVolsServiceImpl; | ||
import org.hibernate.Session; | ||
|
||
import java.io.IOException; | ||
import java.sql.Timestamp; | ||
import java.util.Collection; | ||
|
||
@WebServlet(name = "RservationConfirmationController", value = "/reservation-confirmation") | ||
public class RservationConfirmationController extends HttpServlet { | ||
|
||
private SearchVolsService searchVolsService ; | ||
private ReservationService reservationService; | ||
private HttpSession session; | ||
private ServletContext context; | ||
@Override | ||
public void init(ServletConfig config) throws ServletException { | ||
super.init(config); | ||
this.searchVolsService = new SearchVolsServiceImpl(); | ||
this.context = config.getServletContext(); | ||
this.reservationService = new ReservationServiceImpl(); | ||
} | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
HttpSession session = req.getSession(); // Get the session associated with the request | ||
|
||
String id = req.getParameter("id"); | ||
Double prixTotal = Double.parseDouble(req.getParameter("prixTotal")); | ||
|
||
if (id != null) { | ||
Print.log("id : " + id); | ||
VolEntity vols = searchVolsService.searchVolParId(id); | ||
req.setAttribute("vols",vols); | ||
// reservationEntity.setVolEntities((Collection<VolEntity>) req.getSession().getAttribute("vols")); | ||
// reservationEntity.setPrixTotal((Double) req.getSession().getAttribute("prixTotal")); | ||
// reservationEntity.setDate_Reservation(new Timestamp(System.currentTimeMillis())); | ||
// reservationEntity.setNumberDeAdulets((Integer) req.getSession().getAttribute("numberDeAdulets")); | ||
// reservationEntity.setNumberDeEnfants((Integer) req.getSession().getAttribute("numberDeEnfants")); | ||
// reservationEntity.setNumberDeBebes((Integer) req.getSession().getAttribute("numberDeBebe")); | ||
|
||
session.setAttribute("vols", vols); | ||
prixTotal = vols.getPrix() * (Integer) session.getAttribute("numberDeAdultes") + vols.getPrix() * (Integer) session.getAttribute("numberDeEnfants") + vols.getPrix() * (Integer) session.getAttribute("numberDeBebes"); | ||
session.setAttribute("prixTotal", prixTotal); | ||
|
||
|
||
req.getRequestDispatcher("reservation-confirmation.jsp").forward(req, resp); | ||
|
||
}else{ | ||
resp.sendRedirect("/"); | ||
} | ||
super.doGet(req, resp); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
super.doPost(req, resp); | ||
// Get the values from the form | ||
|
||
|
||
String nom = req.getParameter("nom"); | ||
String prenom = req.getParameter("prenom"); | ||
String adresse = req.getParameter("adresse"); | ||
String email = req.getParameter("email"); | ||
String telephone = req.getParameter("telephone"); | ||
|
||
//TODO : CALL THE SERVICE TO SAVE THE RESERVATION | ||
|
||
ClientEntity client = new ClientEntity(); | ||
client.setNom(nom); | ||
client.setPrenom(prenom); | ||
client.setAdresse(adresse); | ||
client.setEmail(email); | ||
client.setTelephone(telephone); | ||
|
||
ReservationEntity reservationEntity = new ReservationEntity(); | ||
reservationEntity.setClient(client); | ||
VolEntity vol = (VolEntity) req.getSession().getAttribute("vol"); | ||
reservationEntity.setStatus(ReservationStatus.EN_ATTENTE); | ||
reservationEntity.getVolEntities().add(vol); | ||
double prixTotal = vol.getPrix() * (Integer) context.getAttribute("numberDeAdultes") | ||
+ vol.getPrix() * (Integer) context.getAttribute("numberDeEnfants") | ||
+ vol.getPrix() * (Integer) context.getAttribute("numberDeBebes"); | ||
reservationEntity.setPrixTotal(prixTotal); | ||
reservationEntity.setDate_Reservation(new Timestamp(System.currentTimeMillis())); | ||
reservationEntity.setNumberDeAdulets(((Integer) context.getAttribute("numberDeAdultes"))); | ||
reservationEntity.setNumberDeEnfants((Integer) context.getAttribute("numberDeEnfants")); | ||
reservationEntity.setNumberDeBebes((Integer) context.getAttribute("numberDeBebes")); | ||
|
||
|
||
|
||
this.reservationService.confirmationReservation(reservationEntity); | ||
|
||
|
||
resp.sendRedirect("/thank-you.jsp"); | ||
|
||
} | ||
|
||
} | ||
|
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
Oops, something went wrong.