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 26, 2023
1 parent ea3b614 commit 7c30da0
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void main(String[] args) {
HashMap<String, String> conditions = new HashMap<>();


//TODO : THE CLIENT WIL CHOOSE TWO DATE CALLED DATE_1 AND DATE_2 FROM THE CALENDER
// : THE CLIENT WIL CHOOSE TWO DATE CALLED DATE_1 AND DATE_2 FROM THE CALENDER
conditions.put("date_1", "2020-01-01");
conditions.put("date_2", "2023-12-31");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void main(String[] args) {
}

public static void confirmationReservation(){
//todo : client remplir les infrmations de base nom prenom email telephone ;
// : client remplir les infrmations de base nom prenom email telephone ;
HyperJpa jpa = HyperJpa.getInstance();
EntityManager em = jpa.getEntityManager();

Expand Down Expand Up @@ -73,7 +73,7 @@ public static void confirmationReservation(){



//TODO : SEARCH FOR POSSIBLE VOLS IN THIS DATE
// : SEARCH FOR POSSIBLE VOLS IN THIS DATE
//ArrayList<VolEntity> volEntities = FakeEntitesHelper.VolsPossibleParVilleDepartEtVilleArrivee("SAFI" , "RABAT");
// ADD EXTRACTS FOR EACH VOL
// volEntities.forEach(volEntity -> {
Expand All @@ -94,11 +94,11 @@ public static void confirmationReservation(){



//TODO : et le processus de paiement
// : et le processus de paiement
PaymentEntity paymentEntity = new PaymentEntity();

//
//TODO : CONFIRMATION
// : CONFIRMATION
if (false){
reservationEntity.setStatus(ReservationStatus.CONFIRMER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static ReservationEntity getReservationEntity(){
reservationEntity.setCancelled(false);
//THIS WILL BE DECIDED NEXT TIME
reservationEntity.setClient(null);
//TODO : WHEN WE SEARCH FOR POSSIBLE VOLS THIS WILL BE FILLED
// : WHEN WE SEARCH FOR POSSIBLE VOLS THIS WILL BE FILLED
reservationEntity.setVolEntities(null);

return reservationEntity;
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/ma/yc/airafraik/core/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ public static void clearScreen() {
}

public static String readString(String key , Scanner scanner){
//todo : fix this bug
scanner.nextLine();
Print.log(key+" : ");
return scanner.nextLine();
}

public static String readString(String key , Scanner scanner, String defaultValue){
//todo : fix this bug
scanner.nextLine();
Print.log(key+" : ");
String input = scanner.nextLine();
Expand Down Expand Up @@ -159,9 +157,8 @@ public static Date addHours(int i) {
}

//add more helper method
//todo : work with local storage to store information
public boolean storeInformation(String key , String value){
//todo : store the information in the local storage
// : store the information in the local storage
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class ReservationEntity {
private double prixTotal ;
@Column(name = "date_reservation")
private Timestamp date_Reservation;
//TODO : CLIENT RESERVE PLUSIERE
@ManyToOne
@JoinColumn(name = "client_id")
private ClientEntity client ;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/ma/yc/airafraik/entities/VolEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,5 @@ public String toString() {
'}';
}

//TODO : JE PEUX ENRGISTER LES VILLE DEPART ET ARRIVE ETQ OBJET
//TODO : AUSSI LES INFORMATION DE AERPORT ;

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
package ma.yc.airafraik.service.impl;

import ma.yc.airafraik.dao.AccountDao;
import ma.yc.airafraik.dao.Impl.AccountDaoImpl;
import ma.yc.airafraik.dto.Account;
import ma.yc.airafraik.service.AccountService;

import java.io.InputStream;

public class AccountAdminServiceImpl implements AccountService {

private AccountDao accountDao;

public AccountAdminServiceImpl() {
this.accountDao = new AccountDaoImpl();
}

@Override
public Account checkLoginAccount(String username, String password) {
return null;
if (username.isBlank() || password.isBlank()){
return null;
}
Account account = this.accountDao.checkLoginAccount(username,password);
if (account == null){
return null;
}else {
return account;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public double confirmationReservation(ReservationEntity reservationEntity) {
// 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
// : SEEND EMAIL TO CLIENT WITH HIS RESERVATION CODE AND PDF FILE
if (this.envoyerEmail(reservationEntity))
{
Print.log("Email sent successfully");
Expand Down Expand Up @@ -95,7 +95,7 @@ public boolean annulationReservation(String numeroReservation) {
if (numeroReservation == null){
return false;
}
//TODO : annuler sa réservation après la confirmation de son vol dans le cas d'annulation:
// : annuler sa réservation après la confirmation de son vol dans le cas d'annulation:
// 8% des frais est retenue pour la société AirAfrika > 24h avant le vol

Collection<ReservationEntity> reservationEntities = this.reservationDao.consulterReservations(numeroReservation);
Expand All @@ -107,7 +107,7 @@ public boolean annulationReservation(String numeroReservation) {
return false;
}
if (reservationEntity.getStatus() == ReservationStatus.CONFIRMER || reservationEntity.getStatus() == ReservationStatus.EN_ATTENTE){
//TODO : THE CLIENT CAN'T CANCEL HIS RESERVATION AFTER 24H BEFORE THE FLIGHT
// : THE CLIENT CAN'T CANCEL HIS RESERVATION AFTER 24H BEFORE THE FLIGHT
reservationEntity.setStatus(ReservationStatus.ANNULER);

for (VolEntity vol : reservationEntity.getVolEntities()){
Expand All @@ -117,7 +117,7 @@ public boolean annulationReservation(String numeroReservation) {
if (vol.getDateDepart().before(Util.addHours(24))){
return false;
}else {
//TODO : THE CLIENT WILL PAY 8% OF THE TOTAL COST OF THE FLIGHT
// : THE CLIENT WILL PAY 8% OF THE TOTAL COST OF THE FLIGHT
double totalCost = reservationEntity.getPrixTotal();
double cost = totalCost * 0.08;
reservationEntity.setPrixTotal(totalCost - cost);
Expand Down Expand Up @@ -155,7 +155,7 @@ public boolean envoyerEmail(ReservationEntity reservationEntity) {
public int statisticsReservation(ReservationStatus reservationStatus,HashMap<String, String> conditions) {


//TODO : THE CLIENT WIL CHOOSE TWO DATE CALLED DATE_1 AND DATE_2 FROM THE CALENDER
// : THE CLIENT WIL CHOOSE TWO DATE CALLED DATE_1 AND DATE_2 FROM THE CALENDER


if (reservationStatus == null || conditions == null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ public Collection<VolEntity> searchVols(String villeDepart, String villeArrivee,
// conditions.put("dateDepart",dateDepart);
// conditions.put("dateArrive",dateArrivee);
// conditions.put("nombrePassagers",nombrePassagers);

return this.volDao.consulterVols(conditions);
Collection<VolEntity> vols = this.volDao.consulterVols(conditions);
return vols;
}

@Override
public VolEntity searchVolParId(String id) {
if (id == null) return null;
VolEntity vol = this.volDao.consulterVol(id);


return vol;


Expand Down
55 changes: 55 additions & 0 deletions src/main/java/ma/yc/airafraik/web/Admin/AuthController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ma.yc.airafraik.web.Admin;

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 ma.yc.airafraik.service.AccountService;
import ma.yc.airafraik.service.impl.AccountAdminServiceImpl;

import java.io.IOException;

@WebServlet(name = "AuthController", value = {"/admin-login","/admin-logout"})
public class AuthController extends HttpServlet {


private AccountService accountService ;
private boolean isAuth ;

@Override
public void init() throws ServletException {
this.accountService = new AccountAdminServiceImpl();
super.init();
}

@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);
}else if (req.getServletPath().equals("/admin-logout")){
req.getSession().invalidate();
resp.sendRedirect("admin-login");
}
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String username = req.getParameter("username");
String password = req.getParameter("password");

isAuth = this.accountService.checkLoginAccount(username, password) != null;
if (isAuth){
req.getSession().setAttribute("isAuthentified",true);
req.getSession().setAttribute("username",username);
req.getSession().setAttribute("password",password);
req.setAttribute("message","Welcome "+username);
resp.sendRedirect("admin-dashboard");
}else{
req.setAttribute("message","Username or password is incorrect");
req.getRequestDispatcher("admin-login.jsp").forward(req,resp);
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void init() throws ServletException {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
//TODO : AJOUTER NOUVEAU AVION AND GO BACK TO ADMIN DASHBOARD
// : AJOUTER NOUVEAU AVION AND GO BACK TO ADMIN DASHBOARD
String code = request.getParameter("code");
String heureDepart = request.getParameter("heure_depart");
String heureArrivee = request.getParameter("heure_arrivee");
Expand Down
38 changes: 35 additions & 3 deletions src/main/java/ma/yc/airafraik/web/Admin/DashboardController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ma.yc.airafraik.web.Admin;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
Expand Down Expand Up @@ -27,24 +29,37 @@
public class DashboardController extends HttpServlet {

private AccountService accountService ;
private boolean isAccountValid = true;
private boolean isAuthentified = false;
private String message;
private VolsService volsService;
private AvionService avionService;
private ReservationService reservationService;
private ServletContext context;


@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
}

@Override
public void init() throws ServletException {
this.accountService = new AccountAdminServiceImpl();
this.volsService = new VolsServiceImpl();
this.avionService = new AvionServiceImpl();
this.reservationService = new ReservationServiceImpl();


}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// this.verifyAccount(req,resp);

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


if (req.getServletPath().equals("/admin-delete-vol")){
String idVol = req.getParameter("idVol");
boolean IsDeleted = this.volsService.deleteVol(idVol);
Expand Down Expand Up @@ -105,7 +120,22 @@ public HashMap<String, String> generateConditions(String startDate, String endDa
return conditions;
}

private void verifyAccount(HttpServletRequest req, HttpServletResponse resp) {
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);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (ServletException e) {
throw new RuntimeException(e);
}
}



// ma.yc.airafraik.dto.Account account = (ma.yc.airafraik.dto.Account) req.getSession().getAttribute("account");
// if(account != null){
// if(accountService.isAccountValid(account)){
Expand All @@ -121,6 +151,8 @@ private void verifyAccount(HttpServletRequest req, HttpServletResponse resp) {
// e.printStackTrace();
// }
// }

return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
String id = req.getParameter("id");
boolean isSupprimer = this.volService.supprimerVol(id);
if(isSupprimer){
req.setAttribute("message","Vol supprimer avec succes");
//TODO : SOMETHIGN TO DO
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ma/yc/airafraik/web/RechercheVolController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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.VolEntity;
import ma.yc.airafraik.service.VolsService;
Expand All @@ -20,6 +21,8 @@ public class RechercheVolController extends HttpServlet {

private VolsService volsService;
private ServletContext context;
private HttpSession session;
private String message ;

@Override
public void init(ServletConfig config) throws ServletException {
Expand Down Expand Up @@ -53,6 +56,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se


if (depart == null || origin == null || departuredate == null ) {
this.message = "Veuillez remplir tous les champs";
req.getRequestDispatcher("index.jsp").forward(req, resp);
}else{
//TODO : if those information are not null then we will search for the vols
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://127.0.0.1:5332/AIRAFRIK"/>
<property name="jakarta.persistence.jdbc.user" value="pc"/>
<property name="jakarta.persistence.jdbc.password" value="password"/>
<property name="jakarta.persistence.schema-generation.database.action" value="create"/>
<property name="jakarta.persistence.schema-generation.database.action" value="none"/>

<property name="hibernate.connection.url" value="jdbc:postgresql://127.0.0.1:5332/AIRAFRIK"/>
<property name="hibernate.connection.username" value="pc"/>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/views/admin/dashboard.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
</tr>
</thead>
<tbody>
<%-- TODO : LOOP INTO VOLS AND SHOW THEM HERE
<%-- : LOOP INTO VOLS AND SHOW THEM HERE
--%>
<c:forEach items="${vols}" var="vol">
<tr>
Expand Down
Loading

0 comments on commit 7c30da0

Please sign in to comment.