Skip to content

Commit

Permalink
[FIX , BUG , TEST ] [] AJOUTER QUELQUE UNITTEST ET L'AMELIORATION DE …
Browse files Browse the repository at this point in the history
…QUELQUE FUNCTION'S
  • Loading branch information
e.elhjoujy committed Oct 27, 2023
1 parent 7c30da0 commit 2cdbf25
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 107 deletions.
24 changes: 24 additions & 0 deletions src/main/java/ma/yc/airafraik/dao/Impl/AccountDaoImpl.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
package ma.yc.airafraik.dao.Impl;

import jakarta.persistence.EntityManager;
import ma.yc.airafraik.connection.HyperJpa;
import ma.yc.airafraik.core.Util;
import ma.yc.airafraik.dao.AccountDao;
import ma.yc.airafraik.dto.Account;
import ma.yc.airafraik.entities.AdministrateurEntity;

public class AccountDaoImpl implements AccountDao {


private EntityManager em = HyperJpa.getInstance().getEntityManager();

@Override
public Account checkLoginAccount(String username, String password) {
Account account = new Account();
AdministrateurEntity administrateurEntity = em.createQuery("SELECT a FROM AdministrateurEntity a WHERE a.email = :email ", AdministrateurEntity.class)
.setParameter("email", username)
.getSingleResult();
if (administrateurEntity != null) {
if (administrateurEntity.getPassword().equals(password)) {
account.setUsername(administrateurEntity.getEmail());
account.setPassword(administrateurEntity.getPassword());
return account;
} else {
return null;
}
}

return null;

}

}
20 changes: 10 additions & 10 deletions src/main/java/ma/yc/airafraik/dao/Impl/VolDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ public boolean ajouterVols(VolEntity[] vols) {
}
this.transaction.commit();

hyperJpa.commitTransaction();
return true;

} finally {
hyperJpa.rollbackTransaction();
hyperJpa.close();
}
return false;
}

@Override
Expand Down Expand Up @@ -214,14 +213,15 @@ public VolEntity consulterVol(String id) {
@Override
public ArrayList<VolEntity> consulterVols(HashMap<String, String> conditions) {
// EntityManager entityManager = this.hyperJpa.getEntityManager();
String jpql = "SELECT v FROM VolEntity v WHERE ";
String HQL = "SELECT v FROM VolEntity v WHERE ";
for (String key : conditions.keySet()) {
jpql += "v." + key + " = '" + conditions.get(key) + "' AND ";
HQL += "v." + key + " = '" + conditions.get(key) + "' AND ";
}

//remove the last AND
jpql = jpql.substring(0, jpql.length() - 4);
HQL = HQL.substring(0, HQL.length() - 4);

TypedQuery<VolEntity> query = entityManager.createQuery(jpql, VolEntity.class);
TypedQuery<VolEntity> query = entityManager.createQuery(HQL, VolEntity.class);
ArrayList<VolEntity> volEntities = (ArrayList<VolEntity>) query.getResultList();

return volEntities;
Expand All @@ -230,17 +230,17 @@ public ArrayList<VolEntity> consulterVols(HashMap<String, String> conditions) {
@Override
public Collection<VolEntity> consulterVols() {
// EntityManager entityManager = this.hyperJpa.getEntityManager();
String jpql = "SELECT v FROM VolEntity v";
TypedQuery<VolEntity> query = entityManager.createQuery(jpql, VolEntity.class);
String HQL = "SELECT v FROM VolEntity v";
TypedQuery<VolEntity> query = entityManager.createQuery(HQL, VolEntity.class);
Collection<VolEntity> volEntities = query.getResultList();
return volEntities;
}

@Override
public boolean deleteVol(String idVol) {
Integer id = Integer.parseInt(idVol);
String jpql = "DELETE FROM VolEntity v WHERE v.id = :code";
Query query = entityManager.createQuery(jpql);
String HQL = "DELETE FROM VolEntity v WHERE v.id = :code";
Query query = entityManager.createQuery(HQL);
query.setParameter("code", id);
try {
transaction.begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public Account checkLoginAccount(String username, String password) {
return null;
}
Account account = this.accountDao.checkLoginAccount(username,password);

if (account == null){
return null;
}else {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/ma/yc/airafraik/web/Admin/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void init() throws ServletException {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (req.getServletPath().equals("/admin-login")){
req.getRequestDispatcher("admin-login.jsp").forward(req,resp);
req.getRequestDispatcher("views/admin/login.jsp").forward(req,resp);
}else if (req.getServletPath().equals("/admin-logout")){
req.getSession().invalidate();
resp.sendRedirect("admin-login");
Expand All @@ -47,7 +47,9 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
resp.sendRedirect("admin-dashboard");
}else{
req.setAttribute("message","Username or password is incorrect");
req.getRequestDispatcher("admin-login.jsp").forward(req,resp);
// req.getRequestDispatcher("views/admin/login.jsp").forward(req,resp);
resp.sendRedirect("admin-dashboard");

}

}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/ma/yc/airafraik/web/Admin/DashboardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public void init() throws ServletException {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

if (this.verifyAccount(req,resp)){
return ;
}
// if (this.verifyAccount(req,resp)){
// return ;
// }


if (req.getServletPath().equals("/admin-delete-vol")){
Expand Down Expand Up @@ -124,13 +124,12 @@ private boolean verifyAccount(HttpServletRequest req, HttpServletResponse resp)
this.isAuthentified = req.getSession().getAttribute("isAuthentified") != null;
if (!isAuthentified){
try {
req.getRequestDispatcher("views/admin/login.jsp").forward(req,resp);
// req.getRequestDispatcher("views/admin/login.jsp").forward(req,resp);
resp.sendRedirect("admin-login");
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (ServletException e) {
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void init(ServletConfig config) throws ServletException {
this.context = config.getServletContext();
this.reservationService = new ReservationServiceImpl();
this.bagageService = new BagageServiceImpl();

}

@Override
Expand All @@ -60,8 +61,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
// 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);
prixTotal = vols.getPrix() * (Integer) context.getAttribute("numberDeAdultes") + vols.getPrix() * (Integer) context.getAttribute("numberDeEnfants") + vols.getPrix() * (Integer) context.getAttribute("numberDeBebes");
context.setAttribute("prixTotal", prixTotal);


req.getRequestDispatcher("reservation-confirmation.jsp").forward(req, resp);
Expand All @@ -74,6 +75,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Get the values from the form
HttpSession session = req.getSession(); // Get the session associated with the request


String nom = req.getParameter("nom");
Expand Down Expand Up @@ -110,13 +112,13 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S

// TODO: 25/10/2023 BAGAGE
BagageEntity bagageEntity = new BagageEntity();
String poidsString = req.getParameter("poids") == null ? "0" : req.getParameter("poids");
String poidsString = req.getParameter("poids") == null ? "0" : req.getParameter("baagae");
double poids = Double.parseDouble(poidsString);
bagageEntity.setPrix(bagageService.calculerPrixBagage(poids));
bagageEntity.setPoids(poids);

reservationEntity.setPrixTotal(prixTotal + bagageEntity.getPrix());
reservationEntity.setBagage(bagageEntity);
reservationEntity.setPrixTotal(prixTotal);
// reservationEntity.setBagage(bagageEntity);

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

Expand All @@ -129,9 +131,11 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
req.setAttribute("prixTotal",prixtotal);
req.setAttribute("bagage",bagageEntity);

req.getRequestDispatcher("thank-you.jsp").forward(req, resp);
if (prixtotal != 0) {
req.getRequestDispatcher("reservation-confirmation.jsp").forward(req, resp);
}
//TODO : DISTROY THE SESSION
session.invalidate();
// session.invalidate();

}

Expand Down
147 changes: 74 additions & 73 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,89 +11,90 @@
<div class="site-wrap">
<jsp:include page="templates/header.jsp"/>

<div class="site-blocks-cover m-auto" style="background-image: url(https://images.unsplash.com/photo-1561131668-f63504fc549d?auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&w=2914);" data-aos="fade">
<div class="container">
<div class="align-items-start align-items-md-center justify-content-end">
<div class="bg-dark text-center text-md-left pt-5 pt-md-0">
<h1 class="mb-2 text-white">
Quickly scan all your favorite travel sites
</h1>
<div class="search-bar-container ">
<%-- <div class="site-blocks-cover m-auto" style="background-image: url(https://images.unsplash.com/photo-1561131668-f63504fc549d?auto=format&fit=crop&q=80&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&w=2914);" data-aos="fade">--%>
<%-- <div class="container">--%>
<%-- <div class="align-items-start align-items-md-center justify-content-end">--%>
<%-- <div class="bg-dark text-center text-md-left pt-5 pt-md-0">--%>
<%-- <h1 class="mb-2 text-white">--%>
<%-- Quickly scan all your favorite travel sites--%>
<%-- </h1>--%>
<%-- <div class="search-bar-container ">--%>

</div>
</div>
</div>
</div>
<%-- </div>--%>
<%-- </div>--%>
<%-- </div>--%>
<%-- </div>--%>
</div>
<jsp:include page="templates/search-bar.jsp"/>

<div class="site-section site-section-sm site-blocks-1">
<div class="container">
<div class="row">
<div class="col-md-6 col-lg-4 d-lg-flex mb-4 mb-lg-0 pl-4" data-aos="fade-up" data-aos-delay="">
<div class="icon mr-4 align-self-start">
<span class="icon-truck"></span>
</div>

<div class="text">
<h2 class="text-uppercase">Free Shipping</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus at iaculis quam. Integer
accumsan tincidunt fringilla.</p>
</div>
</div>
<%-- <div class="site-section site-section-sm site-blocks-1">--%>
<%-- <div class="container">--%>
<%-- <div class="row">--%>
<%-- <div class="col-md-6 col-lg-4 d-lg-flex mb-4 mb-lg-0 pl-4" data-aos="fade-up" data-aos-delay="">--%>
<%-- <div class="icon mr-4 align-self-start">--%>
<%-- <span class="icon-truck"></span>--%>
<%-- </div>--%>

<div class="col-md-6 col-lg-4 d-lg-flex mb-4 mb-lg-0 pl-4" data-aos="fade-up" data-aos-delay="100">
<div class="icon mr-4 align-self-start">
<span class="icon-refresh2"></span>
</div>
<div class="text">
<h2 class="text-uppercase">Free Returns</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus at iaculis quam. Integer
accumsan tincidunt fringilla.</p>
</div>
</div>
<%-- <div class="text">--%>
<%-- <h2 class="text-uppercase">Free Shipping</h2>--%>
<%-- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus at iaculis quam. Integer--%>
<%-- accumsan tincidunt fringilla.</p>--%>
<%-- </div>--%>
<%-- </div>--%>

<div class="col-md-6 col-lg-4 d-lg-flex mb-4 mb-lg-0 pl-4" data-aos="fade-up" data-aos-delay="200">
<div class="icon mr-4 align-self-start">
<span class="icon-help"></span>
</div>
<div class="text">
<h2 class="text-uppercase">Customer Support</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus at iaculis quam. Integer
accumsan tincidunt fringilla.</p>
</div>
</div>
</div>
</div>
</div>
<%-- <div class="col-md-6 col-lg-4 d-lg-flex mb-4 mb-lg-0 pl-4" data-aos="fade-up" data-aos-delay="100">--%>
<%-- <div class="icon mr-4 align-self-start">--%>
<%-- <span class="icon-refresh2"></span>--%>
<%-- </div>--%>
<%-- <div class="text">--%>
<%-- <h2 class="text-uppercase">Free Returns</h2>--%>
<%-- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus at iaculis quam. Integer--%>
<%-- accumsan tincidunt fringilla.</p>--%>
<%-- </div>--%>
<%-- </div>--%>

<jsp:include page="templates/collections-section.jsp"/>
<%-- <div class="col-md-6 col-lg-4 d-lg-flex mb-4 mb-lg-0 pl-4" data-aos="fade-up" data-aos-delay="200">--%>
<%-- <div class="icon mr-4 align-self-start">--%>
<%-- <span class="icon-help"></span>--%>
<%-- </div>--%>
<%-- <div class="text">--%>
<%-- <h2 class="text-uppercase">Customer Support</h2>--%>
<%-- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus at iaculis quam. Integer--%>
<%-- accumsan tincidunt fringilla.</p>--%>
<%-- </div>--%>
<%-- </div>--%>
<%-- </div>--%>
<%-- </div>--%>
<%-- </div>--%>

<jsp:include page="templates/featured-products.jsp"/>
<%-- <jsp:include page="templates/collections-section.jsp"/>--%>

<div class="site-section block-8">
<div class="container">
<div class="row justify-content-center mb-5">
<div class="col-md-7 site-section-heading text-center pt-4">
<h2>Big Sale!</h2>
</div>
</div>
<div class="row align-items-center">
<div class="col-md-12 col-lg-7 mb-5">
<a href="#"><img src="static/images/blog_1.jpg" alt="Image placeholder"
class="img-fluid rounded"></a>
</div>
<div class="col-md-12 col-lg-5 text-center pl-md-5">
<h2><a href="#">50% less in all items</a></h2>
<p class="post-meta mb-4">By <a href="#">Carl Smith</a> <span class="block-8-sep">&bullet;</span>
September 3, 2018</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quisquam iste dolor accusantium facere
corporis ipsum animi deleniti fugiat. Ex, veniam?</p>
<p><a href="shop" class="btn btn-primary btn-sm">Shop Now</a></p>
</div>
</div>
</div>
</div>
<%-- <jsp:include page="templates/featured-products.jsp"/>--%>

<%-- <div class="site-section block-8">--%>
<%-- <div class="container">--%>
<%-- <div class="row justify-content-center mb-5">--%>
<%-- <div class="col-md-7 site-section-heading text-center pt-4">--%>
<%-- <h2>Big Sale!</h2>--%>
<%-- </div>--%>
<%-- </div>--%>
<%-- <div class="row align-items-center">--%>
<%-- <div class="col-md-12 col-lg-7 mb-5">--%>
<%-- <a href="#"><img src="static/images/blog_1.jpg" alt="Image placeholder"--%>
<%-- class="img-fluid rounded"></a>--%>
<%-- </div>--%>
<%-- <div class="col-md-12 col-lg-5 text-center pl-md-5">--%>
<%-- <h2><a href="#">50% less in all items</a></h2>--%>
<%-- <p class="post-meta mb-4">By <a href="#">Carl Smith</a> <span class="block-8-sep">&bullet;</span>--%>
<%-- September 3, 2018</p>--%>
<%-- <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quisquam iste dolor accusantium facere--%>
<%-- corporis ipsum animi deleniti fugiat. Ex, veniam?</p>--%>
<%-- <p><a href="shop" class="btn btn-primary btn-sm">Shop Now</a></p>--%>
<%-- </div>--%>
<%-- </div>--%>
<%-- </div>--%>
<%-- </div>--%>

<jsp:include page="templates/footer.jsp"/>
</div>
Expand Down
Loading

0 comments on commit 2cdbf25

Please sign in to comment.