Skip to content

Commit

Permalink
Merge pull request #5 from elhajuojy/AIR-6-ETQ-client-rechercher-des-…
Browse files Browse the repository at this point in the history
…vols-possibles-depuis-la-barre-de-recherche

Air 6 etq client rechercher des vols possibles depuis la barre de recherche
  • Loading branch information
elhajoujy authored Oct 9, 2023
2 parents d299eb4 + 1d5338d commit 3c4a07b
Show file tree
Hide file tree
Showing 29 changed files with 313 additions and 37 deletions.
11 changes: 11 additions & 0 deletions database/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ CREATE TABLE VOL (
);


CREATE TABLE VOL_ESCALE(
ID SERIAL NOT NULL ,
VILLE_ESCALE VARCHAR(255),
HEURE_ESCALE VARCHAR(255),
VOL_ID INT NOT NULL,
CONSTRAINT FK_VOL FOREIGN KEY (VOL_ID) REFERENCES VOL(ID),
PRIMARY KEY (ID)

);


CREATE TABLE VOL_EXTRAS (
ID SERIAL NOT NULL ,
Expand All @@ -160,6 +170,7 @@ CREATE TABLE RESERVATION_VOL (




CREATE TABLE ADMINISTRATEUR (
ID SERIAL NOT NULL ,
CODE VARCHAR(255),
Expand Down
31 changes: 31 additions & 0 deletions database/queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- am going from safi to casablanca

SELECT * FROM VOL ;
--this is the perfect case
SELECT * FROM VOL WHERE ville_depart = 'SAFI' OR ville_arrivee = 'CASABLANCA';
SELECT * FROM VOL WHERE ville_depart = 'SAFI' OR ville_arrivee = 'RABAT';

-- now let's trying finding a flight from safi to rabat which includes going to casablanca and then to rabat
-- this is the case where we need to use the recursive query

--NOW WE CAN NOW THAT THERE'S TWO FLIGHTS THAT I CAN FROM SAFI TO RABAT BUT I HAVE TO VERIFY THE TIMIMG CONDITIONS
SELECT * FROM VOL f WHERE f.ville_depart = 'SAFI' OR f.ville_arrivee = 'RABAT' AND
f.heure_depart < (SELECT heure_arrivee FROM VOL s WHERE s.ville_arrivee = 'RABAT' AND s.heure_depart < f.heure_arrivee );

SELECT * FROM VOL s WHERE s.ville_arrivee = 'RABAT' AND s.heure_depart > '12.44' ;

SELECT * FROM VOL f WHERE f.ville_depart = 'SAFI' OR f.ville_arrivee IN
(SELECT ville_arrivee FROM VOL s WHERE s.ville_arrivee = 'RABAT' AND f.ville_arrivee = s.ville_depart );


SELECT * FROM VOL as f WHERE f.ville_depart = 'SAFI' or ville_arrivee =
(SELECT ville_arrivee FROM VOL as s WHERE s.ville_arrivee = 'RABAT' AND s.heure_depart < f.heure_arrivee );



-- LET'S START FROM THE BOTTOM FIRST I WILL NEED TO SPECIFY WHERE I WANT TO GO FROM WHICH IS SAFI AND THIS EXAMPLE
-- NEXT I NEED TO SPECIFY WHERE I WANT TO GO TO WHICH IS RABAT
-- NEXT I NEED TO VERIFY IF THERE'S POSSIBILTY TO GO FROM SAFI TO RABAT DIRECTLY
-- IF NOT I NEED TO VERIFY IF THERE'S A FLIGHT FROM SAFI TO CASABLANCA AND THEN FROM CASABLANCA TO RABAT
-- NEXT I NEED TO CHECK IF THE TIMING IS CORRECT

5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
<artifactId>hibernate-core-jakarta</artifactId>
<version>5.6.15.Final</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import ma.yc.airafraik.core.Util;
import ma.yc.airafraik.dao.Impl.VolDaoImpl;
import ma.yc.airafraik.dao.VolDao;
import ma.yc.airafraik.entites.SocieteAerienneEntity;
import ma.yc.airafraik.entites.VolEntity;
import pl.mjaron.etudes.Table;
import ma.yc.airafraik.entities.SocieteAerienneEntity;
import ma.yc.airafraik.entities.VolEntity;

import java.util.ArrayList;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package ma.yc.airafraik.FunctionalTest;


import ma.yc.airafraik.core.Print;
import ma.yc.airafraik.dao.Impl.VolDaoImpl;
import ma.yc.airafraik.dao.VolDao;
import ma.yc.airafraik.entities.VolEntity;
import pl.mjaron.etudes.Arr;

import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;

public class RecherchePossibleVols {

static String villeDepart = "SAFI";
static String villeArrivee = "RABAT";

public static void main(String[] args) {
VolDao volDao = new VolDaoImpl();
System.out.println("Hello World!");


}



public static ArrayList<VolEntity> filterVolsParPourLesConditions(ArrayList<VolEntity> vols){
HashMap<String , String> conditions = new HashMap<>();

conditions.put("villeDepart" , villeDepart);
conditions.put("villeArrivee" , villeArrivee);
ArrayList<VolEntity>vols = volDao.consulterVols(conditions);

ArrayList<VolEntity> filteredVols = filterVolsParPourLesConditions(vols);
Print.log(filteredVols.size());

ArrayList<VolEntity> filteredVols = new ArrayList<>();
Print.log(vols.size());

// Filter vols BY dateDepart NEED TO BE THE SAME AS THE
for (VolEntity volDepart : vols) {
if (Objects.equals(volDepart.getVilleDepart(), villeDepart)){
for (VolEntity volEscale : vols) {
if (Objects.equals(volEscale.getVilleDepart(), volDepart.getVilleArrivee()) ){
LocalTime localTimeVolDepart = LocalTime.parse(volDepart.getHeureArrivee());
LocalTime localTimeVolEscale = LocalTime.parse(volEscale.getHeureDepart());

if (localTimeVolDepart.isBefore(localTimeVolEscale)){
filteredVols.add(volEscale);
Print.log("Vol Depart : " + volDepart.getVilleDepart()+ " => " + volDepart.getHeureDepart() + " Vol Escale : " + volEscale.getHeureDepart()+ " || "
+ volEscale.getVilleDepart() + " => " + volEscale.getVilleArrivee() + " : " + volEscale.getHeureArrivee());

}


}
}
}
}
return filteredVols;
}
}
7 changes: 4 additions & 3 deletions src/main/java/ma/yc/airafraik/Helper/FakeEntitesHelper.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ma.yc.airafraik.Helper;

import ma.yc.airafraik.core.Util;
import ma.yc.airafraik.entites.*;
import ma.yc.airafraik.entities.*;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

public class FakeEntitesHelper {

Expand Down Expand Up @@ -62,8 +63,8 @@ public static VilleEntity getVilleEntity(){
public static LogEntity getLogEntity(){
LogEntity logEntity = new LogEntity();
logEntity.setDate(new java.sql.Timestamp(new java.util.Date().getTime()));
logEntity.setKey("key-name");
logEntity.setMessage("message log today is the best dday of my life");
logEntity.setKey("key-name-"+Util.generatedLong().toString());
logEntity.setMessage(" message log today is the best dday of my life");
logEntity.setLevel("level Name");
// LogEntity logEntity1 = entityManager.find(LogEntity.class, 1);
// System.out.println(logEntity.getMessage());
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/ma/yc/airafraik/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.Persistence;
import ma.yc.airafraik.Helper.FakeEntitesHelper;
import ma.yc.airafraik.entites.*;

import java.util.List;
import ma.yc.airafraik.entities.LogEntity;

public class Main {
public static void main(String[] args) {
Expand All @@ -19,15 +17,15 @@ public static void main(String[] args) {
try{
transaction.begin();

// LogEntity logEntity = FakeEntitesHelper.getLogEntity();
LogEntity logEntity = FakeEntitesHelper.getLogEntity();
//
// ClientEntity clientEntity = FakeEntitesHelper.getClientEntity();
//
// AdministrateurEntity administrateurEntity = FakeEntitesHelper.getAdministrateurEntity();
//
// VilleEntity ville = FakeEntitesHelper.getVilleEntity();
//
// entityManager.persist(ville);
entityManager.persist(logEntity);
//
// for (VilleImageEntity imageEntity : ville.getImageEntities()) {
// entityManager.persist(imageEntity);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/ma/yc/airafraik/connection/HyperJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.Persistence;
import ma.yc.airafraik.presistence.CustomPresistenceUnitInfo;
import org.hibernate.jpa.HibernatePersistenceProvider;

import java.util.HashMap;

public class HyperJpa {

Expand All @@ -13,6 +17,8 @@ public class HyperJpa {

private HyperJpa() {
entityManagerFactory = Persistence.createEntityManagerFactory("default");
// entityManagerFactory = new HibernatePersistenceProvider().
// createContainerEntityManagerFactory(new CustomPresistenceUnitInfo(), new HashMap<>());
entityManager = entityManagerFactory.createEntityManager();
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ma/yc/airafraik/core/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import ma.yc.airafraik.entites.SocieteAerienneEntity;
import ma.yc.airafraik.entites.VolEntity;
import ma.yc.airafraik.entities.SocieteAerienneEntity;
import ma.yc.airafraik.entities.VolEntity;
import org.mindrot.jbcrypt.BCrypt;


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ma.yc.airafraik.dao.Impl;

public class ReservationDaoImpl {
}
5 changes: 2 additions & 3 deletions src/main/java/ma/yc/airafraik/dao/Impl/VolDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.Query;
import jakarta.persistence.TypedQuery;
import jakarta.transaction.Transactional;
import ma.yc.airafraik.connection.HyperJpa;
import ma.yc.airafraik.core.Print;
import ma.yc.airafraik.dao.VolDao;
import ma.yc.airafraik.entites.VolEntity;
import ma.yc.airafraik.entities.VolEntity;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -207,7 +206,7 @@ public ArrayList<VolEntity> consulterVols(HashMap<String, String> conditions) {
// EntityManager entityManager = this.hyperJpa.getEntityManager();
String jpql = "SELECT v FROM VolEntity v WHERE ";
for (String key : conditions.keySet()) {
jpql += "v." + key + " = '" + conditions.get(key) + "' AND ";
jpql += "v." + key + " = '" + conditions.get(key) + "' OR ";
}
//remove the last AND
jpql = jpql.substring(0, jpql.length() - 4);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ma/yc/airafraik/dao/ReservationDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ma.yc.airafraik.dao;

import java.util.Collection;

public interface ReservationDao {

}
2 changes: 1 addition & 1 deletion src/main/java/ma/yc/airafraik/dao/VolDao.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ma.yc.airafraik.dao;

import ma.yc.airafraik.entites.VolEntity;
import ma.yc.airafraik.entities.VolEntity;

import java.util.ArrayList;
import java.util.Collection;
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/ma/yc/airafraik/entites/AeroportEntity.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/ma/yc/airafraik/entites/PaymentEntity.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ma.yc.airafraik.entites;
package ma.yc.airafraik.entities;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ma/yc/airafraik/entities/AeroportEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ma.yc.airafraik.entities;

public class AeroportEntity {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ma.yc.airafraik.entites;
package ma.yc.airafraik.entities;

import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ma.yc.airafraik.entites;
package ma.yc.airafraik.entities;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -10,7 +10,6 @@
import lombok.NoArgsConstructor;
import lombok.extern.java.Log;

import java.sql.Date;
import java.sql.Timestamp;

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

public class PaymentEntity {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ma.yc.airafraik.entites;
package ma.yc.airafraik.entities;

import jakarta.persistence.*;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ma.yc.airafraik.entites;
package ma.yc.airafraik.entities;

import jakarta.persistence.*;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ma.yc.airafraik.entites;
package ma.yc.airafraik.entities;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ma.yc.airafraik.entites;
package ma.yc.airafraik.entities;


import jakarta.persistence.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ma.yc.airafraik.entites;
package ma.yc.airafraik.entities;

import jakarta.persistence.*;
import lombok.*;
Expand All @@ -12,7 +12,6 @@
@Setter
@Getter
@Builder
@Log
@Entity
@Table(name = "VOL")
public class VolEntity {
Expand Down Expand Up @@ -46,6 +45,10 @@ public class VolEntity {
@OneToMany(mappedBy ="vol", cascade = CascadeType.ALL , fetch = FetchType.LAZY)
private Collection<VolExtrasEntity> volExtrasEntities = new ArrayList<>();

// @OneToMany(mappedBy ="vol", cascade = CascadeType.ALL , fetch = FetchType.LAZY)
// private Collection<VolEscaleEntity> volEscaleEntities = new ArrayList<>();


@ManyToMany
@JoinTable(
name = "reservation_vol",
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/ma/yc/airafraik/entities/VolEscaleEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ma.yc.airafraik.entities;

import jakarta.persistence.*;
import lombok.*;
import lombok.extern.java.Log;

@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
@Builder
@Log
@Entity
@Table(name = "vol_escale")
public class VolEscaleEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "ville_escale")
private String villeEscale ;

@Column(name = "heure_depart")
private String heureEscaleDepart ;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "vol_id")
private VolEntity vol = null ;


}
Loading

0 comments on commit 3c4a07b

Please sign in to comment.