Skip to content

Commit

Permalink
Gestion du bagage: chaque voyageur peut bénéficier d'un bagage gratui…
Browse files Browse the repository at this point in the history
…t de 10Kg Max, chaque point supllémrantaire et payé au Kg
  • Loading branch information
e.elhjoujy committed Oct 25, 2023
1 parent d53681a commit 5611bff
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/main/java/ma/yc/airafraik/entities/BagageEntity.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package ma.yc.airafraik.entities;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "bagage")
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class BagageEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id ;

private double poids ;
private double prix ;
@ManyToOne
private ReservationEntity reservation ;

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


public interface BagageService {
public double calculerPrixBagage(double poids);
}
21 changes: 21 additions & 0 deletions src/main/java/ma/yc/airafraik/service/impl/BagageServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ma.yc.airafraik.service.impl;

import ma.yc.airafraik.service.BagageService;

public class BagageServiceImpl implements BagageService {
@Override
public double calculerPrixBagage(double poids) {
double prix = 0;

if (poids <= 10) {
prix = poids * 25; // Chaque 1 KG vaut 25 Euros
} else if (poids > 10 && poids <= 15) {
prix = 10 * 25 + (poids - 10) * 18; // Au-delà de 10 Kg, 1 KG vaut 18 Euros
} else {
prix = 10 * 25 + 5 * 18 + (poids - 15) * 18; // Au-delà de 15 Kg, 1 KG vaut toujours 18 Euros
}

return prix;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import ma.yc.airafraik.core.Print;
import ma.yc.airafraik.entities.BagageEntity;
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.BagageService;
import ma.yc.airafraik.service.ReservationService;
import ma.yc.airafraik.service.VolsService;
import ma.yc.airafraik.service.impl.BagageServiceImpl;
import ma.yc.airafraik.service.impl.ReservationServiceImpl;
import ma.yc.airafraik.service.impl.VolsServiceImpl;

Expand All @@ -26,13 +29,16 @@ public class RservationConfirmationController extends HttpServlet {

private VolsService volsService;
private ReservationService reservationService;
private BagageService bagageService;
private HttpSession session;
private ServletContext context;
private String message ;
@Override
public void init(ServletConfig config) throws ServletException {
this.volsService = new VolsServiceImpl();
this.context = config.getServletContext();
this.reservationService = new ReservationServiceImpl();
this.bagageService = new BagageServiceImpl();
}

@Override
Expand Down Expand Up @@ -90,16 +96,26 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
VolEntity vol = (VolEntity) req.getSession().getAttribute("vol");
reservationEntity.setStatus(ReservationStatus.EN_ATTENTE);
reservationEntity.getVolEntities().add(vol);

// TODO: 25/10/2023 call prix total de la reservation
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"));


// TODO: 25/10/2023 BAGAGE
BagageEntity bagageEntity = new BagageEntity();
double poids = Double.parseDouble(req.getParameter("poids"));
double prixPoids = Double.parseDouble(req.getParameter("poids"));
bagageEntity.setPrix(bagageService.calculerPrixBagage(prixPoids));
bagageEntity.setPoids(poids);

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

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

Expand All @@ -110,6 +126,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
req.setAttribute("client",client);
req.setAttribute("reservation",reservationEntity);
req.setAttribute("prixTotal",prixtotal);
req.setAttribute("bagage",bagageEntity);

req.getRequestDispatcher("thank-you.jsp").forward(req, resp);
//TODO : DISTROY THE SESSION
Expand Down
7 changes: 7 additions & 0 deletions src/main/webapp/reservation-confirmation-page.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
<input type="tel" class="form-control" id="telephone" name="telephone" required>
</div>

<%-- Bagage --%>
<div class="form-group">
<label for="bagage">Bagage: </label>
<input type="number" name="baagae" id="bagage" >
</div>


<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
Expand Down

0 comments on commit 5611bff

Please sign in to comment.