-
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 21, 2023
1 parent
9394511
commit 9b2f68f
Showing
17 changed files
with
564 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ma.yc.airafraik.dao; | ||
|
||
import ma.yc.airafraik.entities.AvionEntity; | ||
|
||
import java.util.Collection; | ||
|
||
public interface AvionDao { | ||
|
||
public boolean ajouterAvion(AvionEntity avion); | ||
public boolean supprimerAvion(String id); | ||
public boolean modifierAvion(AvionEntity avion); | ||
public AvionEntity consulterAvion(String id); | ||
public Collection<AvionEntity> consulterAvions(); | ||
|
||
|
||
|
||
|
||
} |
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,68 @@ | ||
package ma.yc.airafraik.dao.Impl; | ||
|
||
import ma.yc.airafraik.connection.HyperJpa; | ||
import ma.yc.airafraik.dao.AvionDao; | ||
import ma.yc.airafraik.entities.AvionEntity; | ||
|
||
import java.util.Collection; | ||
|
||
public class AvionDaoImpl implements AvionDao { | ||
HyperJpa hyperJpa ; | ||
|
||
public AvionDaoImpl() { | ||
this.hyperJpa = HyperJpa.getInstance(); | ||
} | ||
|
||
@Override | ||
public boolean ajouterAvion(AvionEntity avion) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean supprimerAvion(String id) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean modifierAvion(AvionEntity avion) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public AvionEntity consulterAvion(String id) { | ||
Integer idInt = Integer.parseInt(id); | ||
try{ | ||
this.hyperJpa.beginTransaction(); | ||
AvionEntity avionEntity = this.hyperJpa.getEntityManager(). | ||
createQuery("select a from AvionEntity a where a.id = :id", AvionEntity.class). | ||
setParameter("id", idInt).getSingleResult(); | ||
|
||
this.hyperJpa.commitTransaction(); | ||
return avionEntity; | ||
}catch (Exception e){ | ||
e.printStackTrace(); | ||
this.hyperJpa.rollbackTransaction(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Collection<AvionEntity> consulterAvions() { | ||
try{ | ||
this.hyperJpa.beginTransaction(); | ||
Collection<AvionEntity> avionEntities = this.hyperJpa.getEntityManager(). | ||
createQuery("select a from AvionEntity a", AvionEntity.class).getResultList(); | ||
|
||
this.hyperJpa.commitTransaction(); | ||
return avionEntities; | ||
|
||
}catch (Exception e){ | ||
e.printStackTrace(); | ||
this.hyperJpa.rollbackTransaction(); | ||
} | ||
finally { | ||
// this.hyperJpa.close(); | ||
} | ||
return null; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ma.yc.airafraik.service; | ||
|
||
import ma.yc.airafraik.entities.AvionEntity; | ||
|
||
import java.util.Collection; | ||
|
||
public interface AvionService { | ||
|
||
public Collection<AvionEntity> consulterAvions(); | ||
public AvionEntity consulterAvion(String id); | ||
|
||
public void ajouterAvion(AvionEntity avionEntity); | ||
} |
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,9 @@ | ||
package ma.yc.airafraik.service; | ||
|
||
import ma.yc.airafraik.entities.VolEntity; | ||
|
||
public interface VolService { | ||
public boolean ajouterVol(VolEntity vol); | ||
|
||
boolean supprimerVol(String id); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/ma/yc/airafraik/service/impl/AvionServiceImpl.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ma.yc.airafraik.service.impl; | ||
|
||
import ma.yc.airafraik.dao.AvionDao; | ||
import ma.yc.airafraik.dao.Impl.AvionDaoImpl; | ||
import ma.yc.airafraik.entities.AvionEntity; | ||
import ma.yc.airafraik.service.AvionService; | ||
|
||
import java.util.Collection; | ||
|
||
public class AvionServiceImpl implements AvionService { | ||
|
||
private AvionDao avionDao; | ||
|
||
public AvionServiceImpl() { | ||
this.avionDao = new AvionDaoImpl(); | ||
} | ||
|
||
@Override | ||
public Collection<AvionEntity> consulterAvions() { | ||
return this.avionDao.consulterAvions(); | ||
} | ||
|
||
@Override | ||
public AvionEntity consulterAvion(String id) { | ||
if (id == null) return null; | ||
return this.avionDao.consulterAvion(id); | ||
} | ||
|
||
@Override | ||
public void ajouterAvion(AvionEntity avionEntity) { | ||
|
||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/ma/yc/airafraik/service/impl/VolServiceImpl.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ma.yc.airafraik.service.impl; | ||
|
||
import ma.yc.airafraik.dao.Impl.VolDaoImpl; | ||
import ma.yc.airafraik.dao.VolDao; | ||
import ma.yc.airafraik.entities.VolEntity; | ||
import ma.yc.airafraik.service.SearchVolsService; | ||
import ma.yc.airafraik.service.VolService; | ||
|
||
public class VolServiceImpl implements VolService { | ||
|
||
private VolDao volDao; | ||
private SearchVolsService searchVolsService; | ||
|
||
|
||
public VolServiceImpl() { | ||
this.volDao = new VolDaoImpl(); | ||
this.searchVolsService = new SearchVolsServiceImpl(); | ||
} | ||
|
||
@Override | ||
public boolean ajouterVol(VolEntity vol) { | ||
if (vol == null) return false; | ||
return this.volDao.ajouterVol(vol); | ||
} | ||
|
||
@Override | ||
public boolean supprimerVol(String id) { | ||
VolEntity vol = this.searchVolsService.searchVolParId(id); | ||
return this.volDao.supprimerVol(vol); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/ma/yc/airafraik/web/Admin/AvionController.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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
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.core.Print; | ||
import ma.yc.airafraik.entities.AvionEntity; | ||
import ma.yc.airafraik.entities.VolEntity; | ||
import ma.yc.airafraik.service.AvionService; | ||
import ma.yc.airafraik.service.SearchVolsService; | ||
import ma.yc.airafraik.service.VolService; | ||
import ma.yc.airafraik.service.impl.VolServiceImpl; | ||
|
||
import java.io.IOException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
@WebServlet(name = "AvionController", value = "/admin-avion") | ||
public class AvionController extends HttpServlet { | ||
|
||
private VolService volService ; | ||
private AvionService avionService; | ||
private String message; | ||
@Override | ||
public void init() throws ServletException { | ||
this.volService = new VolServiceImpl(); | ||
super.init(); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException { | ||
//TODO : 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"); | ||
String dateDepartStr = request.getParameter("date_depart"); | ||
String dateArriveeStr = request.getParameter("date_arrivee"); | ||
String villeDepart = request.getParameter("ville_depart"); | ||
String villeArrivee = request.getParameter("ville_arrivee"); | ||
int nombreDePlaces = Integer.parseInt(request.getParameter("nombre_de_places")); | ||
double prix = Double.parseDouble(request.getParameter("prix")); | ||
Integer avionId = Integer.parseInt(request.getParameter("avion")); | ||
|
||
// Parse date strings to Date objects | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
Date dateDepart = null; | ||
Date dateArrivee = null; | ||
try { | ||
dateDepart = dateFormat.parse(dateDepartStr); | ||
dateArrivee = dateFormat.parse(dateArriveeStr); | ||
} catch (java.text.ParseException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
// Create a new VolEntity object and set the data | ||
VolEntity vol = new VolEntity(); | ||
vol.setCode(code); | ||
vol.setHeureDepart(heureDepart); | ||
vol.setHeureArrivee(heureArrivee); | ||
vol.setDateDepart(dateDepart); | ||
vol.setDateArrive(dateArrivee); | ||
vol.setVilleDepart(villeDepart); | ||
vol.setVilleArrivee(villeArrivee); | ||
vol.setNomberDePlaces(nombreDePlaces); | ||
AvionEntity avion = new AvionEntity(); | ||
vol.setAvion(this.avionService.consulterAvion(avionId.toString())); | ||
// You need to retrieve the AvionEntity object based on avionId and set it to vol | ||
|
||
vol.setPrix(prix); | ||
|
||
if (this.volService.ajouterVol(vol)) | ||
request.setAttribute("message","Avion ajouté avec succès"); | ||
else | ||
request.setAttribute("message","Erreur lors de l'ajout de l'avion"); | ||
|
||
// req.getRequestDispatcher("views/admin/dashboard.jsp").forward(req,resp); | ||
resp.sendRedirect("admin-dashboard"); | ||
} | ||
} |
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.