From 36b96e8170cf61d9826c62c479db5e384b2d0633 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 19 Jan 2022 15:49:07 +0100 Subject: [PATCH 01/35] first commit dev --- src/main/java/fr/cardon/simpleat/model/Restaurant.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/fr/cardon/simpleat/model/Restaurant.java b/src/main/java/fr/cardon/simpleat/model/Restaurant.java index 65e3ceb..54a6066 100644 --- a/src/main/java/fr/cardon/simpleat/model/Restaurant.java +++ b/src/main/java/fr/cardon/simpleat/model/Restaurant.java @@ -38,7 +38,6 @@ public class Restaurant { super(); // TODO Auto-generated constructor stub } - public Restaurant(String nom, String adresse, String telephone, boolean aEmporter, boolean surPlace, double prix, boolean accesPMR, String latitude, String longitude, String website, Collection typerestaus) { From 1d6ee8fe64efcc0777a8daaab8406784157fa923 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 19 Jan 2022 16:00:37 +0100 Subject: [PATCH 02/35] MAJ gitignore --- .gitignore | 4 ++++ src/main/resources/application.properties | 2 ++ 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index c2065bc..ae613fd 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,7 @@ out/ ### VS Code ### .vscode/ + + +### Empêcher ses fichiers d'être mis à jour +application.properties \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 180efdc..3e5ddc8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -20,3 +20,5 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDial # Permet d'exécuter le data.sql # =============================== ##spring.sql.init.mode=always + +## coucou \ No newline at end of file From 3bedab20e8105030ba15547a81a10b0a5b4b8bf9 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 19 Jan 2022 16:18:09 +0100 Subject: [PATCH 03/35] Revert "MAJ gitignore" This reverts commit 1d6ee8fe64efcc0777a8daaab8406784157fa923. --- .gitignore | 4 ---- src/main/resources/application.properties | 2 -- 2 files changed, 6 deletions(-) diff --git a/.gitignore b/.gitignore index ae613fd..c2065bc 100644 --- a/.gitignore +++ b/.gitignore @@ -35,7 +35,3 @@ out/ ### VS Code ### .vscode/ - - -### Empêcher ses fichiers d'être mis à jour -application.properties \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3e5ddc8..180efdc 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -20,5 +20,3 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDial # Permet d'exécuter le data.sql # =============================== ##spring.sql.init.mode=always - -## coucou \ No newline at end of file From 228e013a75a558b715c585584c990c7ae7e96f5a Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Thu, 20 Jan 2022 16:16:16 +0100 Subject: [PATCH 04/35] controller restauParType --- .../simpleat/controller/TypeRestauController.java | 7 +++++++ .../java/fr/cardon/simpleat/model/Restaurant.java | 15 ++++++++------- src/main/resources/application.properties | 7 ++++--- src/main/resources/data.sql | 10 +++++----- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java b/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java index cf2a3ce..4aa388e 100644 --- a/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java +++ b/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java @@ -2,6 +2,7 @@ package fr.cardon.simpleat.controller; import java.util.Collection; +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import fr.cardon.simpleat.model.Restaurant; import fr.cardon.simpleat.model.TypeRestau; import fr.cardon.simpleat.repository.TypeRestauRepository; @@ -36,6 +38,11 @@ public class TypeRestauController { return typeRestauRepository.findById(id); } + @GetMapping("/restaurantbytype/{id}") + public List findRestauByType(@PathVariable int id){ + return findTypetById(id).getRestaurants(); + } + @PostMapping("/add-type") public ResponseEntity ajoutType(@RequestBody TypeRestau type){ return ResponseEntity.status(HttpStatus.OK).body(typeRestauRepository.save(type)); diff --git a/src/main/java/fr/cardon/simpleat/model/Restaurant.java b/src/main/java/fr/cardon/simpleat/model/Restaurant.java index 65e3ceb..2f19041 100644 --- a/src/main/java/fr/cardon/simpleat/model/Restaurant.java +++ b/src/main/java/fr/cardon/simpleat/model/Restaurant.java @@ -3,7 +3,6 @@ package fr.cardon.simpleat.model; import java.util.ArrayList; import java.util.Collection; -import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -13,6 +12,8 @@ import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -25,7 +26,7 @@ public class Restaurant { private String telephone; private boolean aEmporter; private boolean surPlace; - private double prix; + private int prix; private boolean accesPMR; private String latitude; private String longitude; @@ -40,7 +41,7 @@ public class Restaurant { } - public Restaurant(String nom, String adresse, String telephone, boolean aEmporter, boolean surPlace, double prix, + public Restaurant(String nom, String adresse, String telephone, boolean aEmporter, boolean surPlace, int prix, boolean accesPMR, String latitude, String longitude, String website, Collection typerestaus) { super(); this.nom = nom; @@ -103,11 +104,11 @@ public class Restaurant { this.surPlace = surPlace; } @Column(nullable = true) - public double getPrix() { + public int getPrix() { return prix; } - public void setPrix(double prixMin) { - this.prix = prixMin; + public void setPrix(int prix) { + this.prix = prix; } @Column(nullable = true) public boolean isAccesPMR() { @@ -142,7 +143,7 @@ public class Restaurant { @JoinTable(name="type_restau", joinColumns = @JoinColumn(name = "id_restau"/*classe en cours*/,referencedColumnName = "id_restau" /*classe reliée*/) , inverseJoinColumns = @JoinColumn(name = "id_type",referencedColumnName = "id_type")) - @JsonIgnoreProperties("typerestaus") + @JsonBackReference("typerestaus") public Collection getTyperestaus() { return typerestaus; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 180efdc..875e116 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,10 +13,11 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # JPA / HIBERNATE # =============================== spring.jpa.show-sql=true -spring.jpa.hibernate.ddl-auto=update -##spring.jpa.hibernate.ddl-auto=create-drop +##spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect # =============================== # Permet d'exécuter le data.sql # =============================== -##spring.sql.init.mode=always +spring.sql.init.mode=always +spring.jpa.defer-datasource-initialization=true \ No newline at end of file diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index b075246..8dd4536 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -13,11 +13,11 @@ insert into personne (nom, prenom, email, password) values ('Crick', 'Andris', ' insert into role (id_role, intitule) values (1, 'Admin'); insert into role (id_role, intitule) values (2, 'User'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix_min, prix_max, accespmr, latitude, longitude) values ('L Perrigo Company', '301 Thierer Trail', '3092096786', false, true, 10, 16, false, '2.1961772', '22.4708685'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix_min, prix_max, accespmr, latitude, longitude) values ('Sanofi Pasteur Inc.', '9 Barnett Terrace', '6809964349', false, true, 1, 17, false, '31.45571', '34.43719'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix_min, prix_max, accespmr, latitude, longitude) values ('REMEDYREPACK INC.', '3 West Park', '4565542193', true, false, 2, 20, true, '49.817777', '19.785536'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix_min, prix_max, accespmr, latitude, longitude) values ('Physicians Total Care, Inc.', '462 Mosinee Lane', '8521719889', false, false, 1, 22, true, '-13.5', '48.86667'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix_min, prix_max, accespmr, latitude, longitude) values ('Triweld Industries, Inc.', '2482 Corscot Way', '7513208452', false, true, 5, 13, true, '34.326903', '108.117456'); +insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('L Perrigo Company', '301 Thierer Trail', '3092096786', false, true, 1, false, '2.1961772', '22.4708685'); +insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Sanofi Pasteur Inc.', '9 Barnett Terrace', '6809964349', false, true, 2, false, '31.45571', '34.43719'); +insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('REMEDYREPACK INC.', '3 West Park', '4565542193', true, false, 3, true, '49.817777', '19.785536'); +insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Physicians Total Care, Inc.', '462 Mosinee Lane', '8521719889', false, false, 4, true, '-13.5', '48.86667'); +insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Triweld Industries, Inc.', '2482 Corscot Way', '7513208452', false, true, 2, true, '34.326903', '108.117456'); insert into preference (id_restau, id_personne, note, favori) values (2, 9, 1, false); insert into preference (id_restau, id_personne, note, favori) values (3, 1, 5, false); From d06c06b5959ccd612d8d87f05efad5bb28d633f0 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Thu, 20 Jan 2022 16:35:56 +0100 Subject: [PATCH 05/35] ajout fichier tx Postman --- src/main/resources/Postman | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/resources/Postman diff --git a/src/main/resources/Postman b/src/main/resources/Postman new file mode 100644 index 0000000..0203063 --- /dev/null +++ b/src/main/resources/Postman @@ -0,0 +1,6 @@ +Nouvelle Requête POSTMAN: + +20/01/2022 + GET localhost:8080/restaurantbytype/1 + + From 5a64f29586aae8118457ed90b40ee63cdfbd80b1 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 21 Jan 2022 18:28:54 +0100 Subject: [PATCH 06/35] suppr restau+pref=OK --- build.gradle | 1 + .../controller/PreferenceController.java | 21 +- .../fr/cardon/simpleat/model/Personne.java | 22 + .../fr/cardon/simpleat/model/Preference.java | 72 ++- .../cardon/simpleat/model/PreferencePK.java | 15 +- .../fr/cardon/simpleat/model/Restaurant.java | 31 +- .../fr/cardon/simpleat/model/TypeRestau.java | 1 + src/main/resources/Postman | 563 +++++++++++++++++- src/main/resources/data.sql | 28 +- 9 files changed, 700 insertions(+), 54 deletions(-) diff --git a/build.gradle b/build.gradle index 92a2fa8..577c1f0 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' runtimeOnly 'mysql:mysql-connector-java' testImplementation 'org.springframework.boot:spring-boot-starter-test' + developmentOnly 'org.springframework.boot:spring-boot-devtools' } test { diff --git a/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java b/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java index 3dbca6b..3bbe8d3 100644 --- a/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java +++ b/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java @@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -61,11 +60,21 @@ public class PreferenceController { // return ResponseEntity.status(HttpStatus.OK).body(preferenceRepository.save(personne)); // } // -// @DeleteMapping(value = "/delete-restaurant/{id}") -// public void suppressionPerso(@PathVariable int id){ + @DeleteMapping("/delete-preference/{idrestau}/{iduser}") + public void deletePreferenceById(@PathVariable int iduser, @PathVariable int idrestau ){ + PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau)); + preferenceRepository.deleteById(id); + } + +// @DeleteMapping("/delete-pref-byrestau/{idrestau}") +// public void deletePreferenceByRestau(@PathVariable int idrestau ){ +// List list = personneRepository.findAll(); +// for (int i = 0; i < list.size(); i++) { +// if(findPreferenceById(list.get(i).getId(),idrestau).isEmpty() == false) { +// preferenceRepository.deleteById(new PreferencePK(list.get(i),new Restaurant(idrestau))); +// } +// //System.out.println(findPreferenceById(list.get(i).getId(),idrestau).isEmpty()); +// } // -// preferenceRepository.deleteById(id); // } - - } diff --git a/src/main/java/fr/cardon/simpleat/model/Personne.java b/src/main/java/fr/cardon/simpleat/model/Personne.java index 9b9b7bf..121f2a3 100644 --- a/src/main/java/fr/cardon/simpleat/model/Personne.java +++ b/src/main/java/fr/cardon/simpleat/model/Personne.java @@ -4,6 +4,7 @@ package fr.cardon.simpleat.model; import java.util.ArrayList; import java.util.Collection; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -12,7 +13,9 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity @@ -24,6 +27,7 @@ public class Personne { private String email; private String password; private Collection roles = new ArrayList(); + private Collection preference = new ArrayList(); public Personne() { @@ -32,6 +36,12 @@ public class Personne { } + public Personne(int id) { + super(); + this.id = id; + } + + public Personne(String nom, String prenom, String email, String password) { super(); this.nom = nom; @@ -107,4 +117,16 @@ public class Personne { this.roles = roles; } + @OneToMany(mappedBy = "personne", cascade = CascadeType.REMOVE) + @JsonIgnore + public Collection getPreference() { + return preference; + } + + public void setPreference(Collection preference) { + this.preference = preference; + } + + + } diff --git a/src/main/java/fr/cardon/simpleat/model/Preference.java b/src/main/java/fr/cardon/simpleat/model/Preference.java index a1267c2..c3b52e3 100644 --- a/src/main/java/fr/cardon/simpleat/model/Preference.java +++ b/src/main/java/fr/cardon/simpleat/model/Preference.java @@ -1,13 +1,20 @@ package fr.cardon.simpleat.model; import javax.persistence.Column; -import javax.persistence.EmbeddedId; import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity +@IdClass(PreferencePK.class) public class Preference { - private PreferencePK preferencePK; + private Personne personne; + private Restaurant restau; private int note; private boolean favoris; @@ -19,36 +26,79 @@ public class Preference { } - public Preference(PreferencePK preferencePK, int note, boolean favoris) { + + public Preference(Personne personne, Restaurant restau) { super(); - this.preferencePK = preferencePK; + this.personne = personne; + this.restau = restau; + } + + + + public Preference(Personne personne, Restaurant restau, int note, boolean favoris) { + super(); + this.personne = personne; + this.restau = restau; this.note = note; this.favoris = favoris; } - @EmbeddedId - public PreferencePK getPreferencePK() { - return preferencePK; + + @Id + @ManyToOne + @JoinColumn(name="id_personne" ) + @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) + public Personne getPersonne() { + return personne; } - public void setPreferencePK(PreferencePK preferencePK) { - this.preferencePK = preferencePK; + + + + public void setPersonne(Personne personne) { + this.personne = personne; } + + @Id + @ManyToOne + @JoinColumn(name="id_restau" ) + @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) + public Restaurant getRestau() { + return restau; + } + + + + public void setRestau(Restaurant restau) { + this.restau = restau; + } + + @Column(nullable = true) public int getNote() { return note; } + + + public void setNote(int note) { this.note = note; } + + @Column(nullable = true) - public boolean isFavori() { + public boolean isFavoris() { return favoris; } - public void setFavori(boolean favoris) { + + + + public void setFavoris(boolean favoris) { this.favoris = favoris; } + + } diff --git a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java index 8e17df1..567f698 100644 --- a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java +++ b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java @@ -3,16 +3,10 @@ package fr.cardon.simpleat.model; import java.io.Serializable; -import javax.persistence.CascadeType; import javax.persistence.Embeddable; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -@Embeddable + public class PreferencePK implements Serializable { /** @@ -36,9 +30,6 @@ public class PreferencePK implements Serializable { } - @ManyToOne - @JoinColumn(name="id_personne", referencedColumnName ="id_personne" ) - @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public Personne getPersonne() { return personne; } @@ -48,10 +39,6 @@ public class PreferencePK implements Serializable { this.personne = personne; } - - @ManyToOne // TODO mappedBy preferences dans restaurant - @JoinColumn(name="id_restau",referencedColumnName ="id_restau" ) - @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public Restaurant getRestau() { return restau; } diff --git a/src/main/java/fr/cardon/simpleat/model/Restaurant.java b/src/main/java/fr/cardon/simpleat/model/Restaurant.java index 9035bd2..7309600 100644 --- a/src/main/java/fr/cardon/simpleat/model/Restaurant.java +++ b/src/main/java/fr/cardon/simpleat/model/Restaurant.java @@ -3,6 +3,7 @@ package fr.cardon.simpleat.model; import java.util.ArrayList; import java.util.Collection; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -11,10 +12,9 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; -import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity @@ -32,6 +32,7 @@ public class Restaurant { private String longitude; private String website; private Collection typerestaus = new ArrayList(); + private Collection preference = new ArrayList(); //TODO @OneToMany relier avec une collec de preferences @@ -40,6 +41,17 @@ public class Restaurant { // TODO Auto-generated constructor stub } + + + + public Restaurant(int id) { + super(); + this.id = id; + } + + + + public Restaurant(String nom, String adresse, String telephone, boolean aEmporter, boolean surPlace, int prix, boolean accesPMR, String latitude, String longitude, String website, Collection typerestaus) { super(); @@ -142,7 +154,7 @@ public class Restaurant { @JoinTable(name="type_restau", joinColumns = @JoinColumn(name = "id_restau"/*classe en cours*/,referencedColumnName = "id_restau" /*classe reliée*/) , inverseJoinColumns = @JoinColumn(name = "id_type",referencedColumnName = "id_type")) - @JsonBackReference("typerestaus") + @JsonIgnore public Collection getTyperestaus() { return typerestaus; } @@ -150,5 +162,18 @@ public class Restaurant { public void setTyperestaus(Collection typerestaus) { this.typerestaus = typerestaus; } + + @OneToMany(mappedBy = "restau", cascade = CascadeType.REMOVE) + @JsonIgnore + public Collection getPreference() { + return preference; + } + + + public void setPreference(Collection preference) { + this.preference = preference; + } + + } diff --git a/src/main/java/fr/cardon/simpleat/model/TypeRestau.java b/src/main/java/fr/cardon/simpleat/model/TypeRestau.java index 01f6d51..53869e7 100644 --- a/src/main/java/fr/cardon/simpleat/model/TypeRestau.java +++ b/src/main/java/fr/cardon/simpleat/model/TypeRestau.java @@ -2,6 +2,7 @@ package fr.cardon.simpleat.model; import java.util.List; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/src/main/resources/Postman b/src/main/resources/Postman index 0203063..94de556 100644 --- a/src/main/resources/Postman +++ b/src/main/resources/Postman @@ -1,6 +1,557 @@ -Nouvelle Requête POSTMAN: - -20/01/2022 - GET localhost:8080/restaurantbytype/1 - - +{ + "info": { + "_postman_id": "5edbac98-7561-4ccc-b517-87c01aef2a41", + "name": "Simpleat", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Personne", + "item": [ + { + "name": "Accueil", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "formdata", + "formdata": [] + }, + "url": { + "raw": "localhost:8080/", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "" + ] + } + }, + "response": [] + }, + { + "name": "affichPersonnes", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/users", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "AffichUnePersonne", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/user/2", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "user", + "2" + ] + } + }, + "response": [] + }, + { + "name": "AjoutPersonne", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"nom\": \"nouvel\",\r\n \"prenom\": \"ajout\",\r\n \"email\": \"role@ajout.fr\",\r\n \"password\": \"root\",\r\n \"roles\": [\r\n {\r\n \"id\": 2\r\n }\r\n ]\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/add-user", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "add-user" + ] + } + }, + "response": [] + }, + { + "name": "UpdatePersonne", + "request": { + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"id\": 2,\r\n \"nom\": \"salut\",\r\n \"prenom\": \"enleve\",\r\n \"email\": \"nouvel@ajout.fr\",\r\n \"password\": \"root\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/update-user/2", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "update-user", + "2" + ] + } + }, + "response": [] + }, + { + "name": "DeletePersonne", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "localhost:8080/delete-user/1", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "delete-user", + "1" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Preference", + "item": [ + { + "name": "AffichPreference", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/preference/5/5", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "preference", + "5", + "5" + ] + } + }, + "response": [] + }, + { + "name": "AffichPreferences", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/preferences", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "preferences" + ] + } + }, + "response": [] + }, + { + "name": "Ajout preferences", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"preferencePK\": {\r\n \"personne\": {\r\n \"id\": 10\r\n },\r\n \"restau\": {\r\n \"id\": 2\r\n }\r\n },\r\n \"note\": 5,\r\n \"favori\": true\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/add-preference", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "add-preference" + ] + } + }, + "response": [] + }, + { + "name": "Delete preferences", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "localhost:8080/delete-preference/:idrestau/:iduser", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "delete-preference", + ":idrestau", + ":iduser" + ], + "variable": [ + { + "key": "idrestau", + "value": "3" + }, + { + "key": "iduser", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Del prefByRestau[OUT]", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "localhost:8080/delete-pref-byrestau/3", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "delete-pref-byrestau", + "3" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Restaurant", + "item": [ + { + "name": "AffichRestaurants", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/restaurants", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "restaurants" + ] + } + }, + "response": [] + }, + { + "name": "AfficheUnRestaurant", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/restaurant/2", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "restaurant", + "2" + ] + } + }, + "response": [] + }, + { + "name": "AfficheRestoParType", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/restaurantbytype/1", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "restaurantbytype", + "1" + ] + } + }, + "response": [] + }, + { + "name": "AjoutRestaurant", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": " {\r\n \"nom\": \"gevaudan\",\r\n \"adresse\": \"Montreil\",\r\n \"latitude\": \"31.45571\",\r\n \"longitude\": \"34.43719\",\r\n \"typerestaus\": [\r\n {\r\n \"id\": 3\r\n },\r\n {\r\n \"id\": 4\r\n }\r\n ]\r\n }", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/add-restaurant", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "add-restaurant" + ] + } + }, + "response": [] + }, + { + "name": "UpdateRestaurant", + "request": { + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": " {\r\n \"id\": 2,\r\n \"nom\": \"suepr\",\r\n \"adresse\": \"93100 Montreuil\",\r\n \"telephone\": \"6809964349\",\r\n \"aEmporter\": false,\r\n \"surPlace\": true,\r\n \"prixMin\": 1.0,\r\n \"prixMax\": 17.0,\r\n \"accesPMR\": false,\r\n \"latitude\": \"31.45571\",\r\n \"longitude\": \"34.43719\",\r\n \"typerestaus\": []\r\n }", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/update-restaurant/2", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "update-restaurant", + "2" + ] + } + }, + "response": [] + }, + { + "name": "DeleteRestaurant", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "localhost:8080/delete-restaurant/4", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "delete-restaurant", + "4" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Type", + "item": [ + { + "name": "AffichTypes", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/types", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "types" + ] + } + }, + "response": [] + }, + { + "name": "Affich1Type", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/type/2", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "type", + "2" + ] + } + }, + "response": [] + }, + { + "name": "UpdateType", + "request": { + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"id\": 2,\r\n \"libelle\": \"creperie\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/update-type/2", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "update-type", + "2" + ] + } + }, + "response": [] + }, + { + "name": "AddType", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"libelle\": \"coucou\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/add-type", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "add-type" + ] + } + }, + "response": [] + }, + { + "name": "DeleteType", + "request": { + "method": "DELETE", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "localhost:8080/delete-type/:id", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "delete-type", + ":id" + ], + "variable": [ + { + "key": "id", + "value": "2" + } + ] + } + }, + "response": [] + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 8dd4536..8aa3c00 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -19,20 +19,20 @@ insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, ac insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Physicians Total Care, Inc.', '462 Mosinee Lane', '8521719889', false, false, 4, true, '-13.5', '48.86667'); insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Triweld Industries, Inc.', '2482 Corscot Way', '7513208452', false, true, 2, true, '34.326903', '108.117456'); -insert into preference (id_restau, id_personne, note, favori) values (2, 9, 1, false); -insert into preference (id_restau, id_personne, note, favori) values (3, 1, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 9, 3, true); -insert into preference (id_restau, id_personne, note, favori) values (4, 6, 2, false); -insert into preference (id_restau, id_personne, note, favori) values (5, 5, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 10, 1, false); -insert into preference (id_restau, id_personne, note, favori) values (5, 3, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 7, 1, true); -insert into preference (id_restau, id_personne, note, favori) values (4, 2, 1, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 3, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (3, 10, 4, false); -insert into preference (id_restau, id_personne, note, favori) values (3, 3, 4, true); -insert into preference (id_restau, id_personne, note, favori) values (2, 3, 3, false); -insert into preference (id_restau, id_personne, note, favori) values (2, 8, 3, false); +insert into preference (id_restau, id_personne, note, favoris) values (2, 9, 1, false); +insert into preference (id_restau, id_personne, note, favoris) values (3, 1, 5, false); +insert into preference (id_restau, id_personne, note, favoris) values (1, 9, 3, true); +insert into preference (id_restau, id_personne, note, favoris) values (4, 6, 2, false); +insert into preference (id_restau, id_personne, note, favoris) values (5, 5, 5, false); +insert into preference (id_restau, id_personne, note, favoris) values (1, 10, 1, false); +insert into preference (id_restau, id_personne, note, favoris) values (5, 3, 5, false); +insert into preference (id_restau, id_personne, note, favoris) values (1, 7, 1, true); +insert into preference (id_restau, id_personne, note, favoris) values (4, 2, 1, false); +insert into preference (id_restau, id_personne, note, favoris) values (1, 3, 5, false); +insert into preference (id_restau, id_personne, note, favoris) values (3, 10, 4, false); +insert into preference (id_restau, id_personne, note, favoris) values (3, 3, 4, true); +insert into preference (id_restau, id_personne, note, favoris) values (2, 3, 3, false); +insert into preference (id_restau, id_personne, note, favoris) values (2, 8, 3, false); insert into type (id_type, libelle) values (1, 'Kebab'); insert into type (id_type, libelle) values (2, 'Supermarché'); From 786d8b23d9a438a8a56a058812df54a55d99a22a Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 21 Jan 2022 20:04:05 +0100 Subject: [PATCH 07/35] export collec postman --- src/main/resources/Postman | 563 ++++++++++++++++++++++++++++++++++++- 1 file changed, 557 insertions(+), 6 deletions(-) diff --git a/src/main/resources/Postman b/src/main/resources/Postman index 0203063..94de556 100644 --- a/src/main/resources/Postman +++ b/src/main/resources/Postman @@ -1,6 +1,557 @@ -Nouvelle Requête POSTMAN: - -20/01/2022 - GET localhost:8080/restaurantbytype/1 - - +{ + "info": { + "_postman_id": "5edbac98-7561-4ccc-b517-87c01aef2a41", + "name": "Simpleat", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Personne", + "item": [ + { + "name": "Accueil", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "formdata", + "formdata": [] + }, + "url": { + "raw": "localhost:8080/", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "" + ] + } + }, + "response": [] + }, + { + "name": "affichPersonnes", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/users", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "AffichUnePersonne", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/user/2", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "user", + "2" + ] + } + }, + "response": [] + }, + { + "name": "AjoutPersonne", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"nom\": \"nouvel\",\r\n \"prenom\": \"ajout\",\r\n \"email\": \"role@ajout.fr\",\r\n \"password\": \"root\",\r\n \"roles\": [\r\n {\r\n \"id\": 2\r\n }\r\n ]\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/add-user", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "add-user" + ] + } + }, + "response": [] + }, + { + "name": "UpdatePersonne", + "request": { + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"id\": 2,\r\n \"nom\": \"salut\",\r\n \"prenom\": \"enleve\",\r\n \"email\": \"nouvel@ajout.fr\",\r\n \"password\": \"root\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/update-user/2", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "update-user", + "2" + ] + } + }, + "response": [] + }, + { + "name": "DeletePersonne", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "localhost:8080/delete-user/1", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "delete-user", + "1" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Preference", + "item": [ + { + "name": "AffichPreference", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/preference/5/5", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "preference", + "5", + "5" + ] + } + }, + "response": [] + }, + { + "name": "AffichPreferences", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/preferences", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "preferences" + ] + } + }, + "response": [] + }, + { + "name": "Ajout preferences", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"preferencePK\": {\r\n \"personne\": {\r\n \"id\": 10\r\n },\r\n \"restau\": {\r\n \"id\": 2\r\n }\r\n },\r\n \"note\": 5,\r\n \"favori\": true\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/add-preference", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "add-preference" + ] + } + }, + "response": [] + }, + { + "name": "Delete preferences", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "localhost:8080/delete-preference/:idrestau/:iduser", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "delete-preference", + ":idrestau", + ":iduser" + ], + "variable": [ + { + "key": "idrestau", + "value": "3" + }, + { + "key": "iduser", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Del prefByRestau[OUT]", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "localhost:8080/delete-pref-byrestau/3", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "delete-pref-byrestau", + "3" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Restaurant", + "item": [ + { + "name": "AffichRestaurants", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/restaurants", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "restaurants" + ] + } + }, + "response": [] + }, + { + "name": "AfficheUnRestaurant", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/restaurant/2", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "restaurant", + "2" + ] + } + }, + "response": [] + }, + { + "name": "AfficheRestoParType", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/restaurantbytype/1", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "restaurantbytype", + "1" + ] + } + }, + "response": [] + }, + { + "name": "AjoutRestaurant", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": " {\r\n \"nom\": \"gevaudan\",\r\n \"adresse\": \"Montreil\",\r\n \"latitude\": \"31.45571\",\r\n \"longitude\": \"34.43719\",\r\n \"typerestaus\": [\r\n {\r\n \"id\": 3\r\n },\r\n {\r\n \"id\": 4\r\n }\r\n ]\r\n }", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/add-restaurant", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "add-restaurant" + ] + } + }, + "response": [] + }, + { + "name": "UpdateRestaurant", + "request": { + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": " {\r\n \"id\": 2,\r\n \"nom\": \"suepr\",\r\n \"adresse\": \"93100 Montreuil\",\r\n \"telephone\": \"6809964349\",\r\n \"aEmporter\": false,\r\n \"surPlace\": true,\r\n \"prixMin\": 1.0,\r\n \"prixMax\": 17.0,\r\n \"accesPMR\": false,\r\n \"latitude\": \"31.45571\",\r\n \"longitude\": \"34.43719\",\r\n \"typerestaus\": []\r\n }", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/update-restaurant/2", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "update-restaurant", + "2" + ] + } + }, + "response": [] + }, + { + "name": "DeleteRestaurant", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "localhost:8080/delete-restaurant/4", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "delete-restaurant", + "4" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Type", + "item": [ + { + "name": "AffichTypes", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/types", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "types" + ] + } + }, + "response": [] + }, + { + "name": "Affich1Type", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "localhost:8080/type/2", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "type", + "2" + ] + } + }, + "response": [] + }, + { + "name": "UpdateType", + "request": { + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"id\": 2,\r\n \"libelle\": \"creperie\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/update-type/2", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "update-type", + "2" + ] + } + }, + "response": [] + }, + { + "name": "AddType", + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"libelle\": \"coucou\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/add-type", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "add-type" + ] + } + }, + "response": [] + }, + { + "name": "DeleteType", + "request": { + "method": "DELETE", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "localhost:8080/delete-type/:id", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "delete-type", + ":id" + ], + "variable": [ + { + "key": "id", + "value": "2" + } + ] + } + }, + "response": [] + } + ] + } + ] +} \ No newline at end of file From 0b916f16c009c6b6a998ce428ea5fcf9c5473262 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Tue, 25 Jan 2022 11:18:38 +0100 Subject: [PATCH 08/35] maj typerestau --- src/main/java/fr/cardon/simpleat/model/TypeRestau.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/cardon/simpleat/model/TypeRestau.java b/src/main/java/fr/cardon/simpleat/model/TypeRestau.java index 53869e7..37beaeb 100644 --- a/src/main/java/fr/cardon/simpleat/model/TypeRestau.java +++ b/src/main/java/fr/cardon/simpleat/model/TypeRestau.java @@ -2,7 +2,6 @@ package fr.cardon.simpleat.model; import java.util.List; -import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -11,6 +10,7 @@ import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.Table; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; From 39c546794c4b23b017943f973b7a557031a5a711 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Tue, 25 Jan 2022 11:38:20 +0100 Subject: [PATCH 09/35] url delete-pref --- .../simpleat/controller/PreferenceController.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java b/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java index 3dbca6b..b77e8a9 100644 --- a/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java +++ b/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java @@ -61,11 +61,11 @@ public class PreferenceController { // return ResponseEntity.status(HttpStatus.OK).body(preferenceRepository.save(personne)); // } // -// @DeleteMapping(value = "/delete-restaurant/{id}") -// public void suppressionPerso(@PathVariable int id){ -// -// preferenceRepository.deleteById(id); -// } + @DeleteMapping("/delete-preference/{idrestau}/{iduser}") + public void deletePreferenceById(@PathVariable int iduser, @PathVariable int idrestau ){ + PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau)); + preferenceRepository.deleteById(id); + } } From 4dee7c966ff37c5a5d25e97fae518df62f76c937 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Tue, 25 Jan 2022 16:02:30 +0100 Subject: [PATCH 10/35] CRUD pref resto personne=ok --- .../fr/cardon/simpleat/model/Personne.java | 16 +++++++++++ .../cardon/simpleat/model/PreferencePK.java | 5 ++-- .../fr/cardon/simpleat/model/Restaurant.java | 16 ++++++++++- src/main/resources/Postman | 8 +++--- src/main/resources/data.sql | 28 +++++++++---------- 5 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/main/java/fr/cardon/simpleat/model/Personne.java b/src/main/java/fr/cardon/simpleat/model/Personne.java index 9b9b7bf..68c58a8 100644 --- a/src/main/java/fr/cardon/simpleat/model/Personne.java +++ b/src/main/java/fr/cardon/simpleat/model/Personne.java @@ -4,6 +4,7 @@ package fr.cardon.simpleat.model; import java.util.ArrayList; import java.util.Collection; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -12,7 +13,9 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity @@ -24,6 +27,7 @@ public class Personne { private String email; private String password; private Collection roles = new ArrayList(); + private Collection preference = new ArrayList(); public Personne() { @@ -106,5 +110,17 @@ public class Personne { public void setRoles(Collection roles) { this.roles = roles; } + + + @OneToMany(mappedBy = "preferencePK.personne", cascade = CascadeType.REMOVE) + @JsonIgnore + public Collection getPreference() { + return preference; + } + + + public void setPreference(Collection preference) { + this.preference = preference; + } } diff --git a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java index 8e17df1..ed364ae 100644 --- a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java +++ b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java @@ -8,6 +8,7 @@ import javax.persistence.Embeddable; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.PrimaryKeyJoinColumn; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -37,7 +38,7 @@ public class PreferencePK implements Serializable { @ManyToOne - @JoinColumn(name="id_personne", referencedColumnName ="id_personne" ) + @PrimaryKeyJoinColumn(name="id_personne", referencedColumnName ="id_personne" ) @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public Personne getPersonne() { return personne; @@ -50,7 +51,7 @@ public class PreferencePK implements Serializable { @ManyToOne // TODO mappedBy preferences dans restaurant - @JoinColumn(name="id_restau",referencedColumnName ="id_restau" ) + @PrimaryKeyJoinColumn(name="id_restau",referencedColumnName ="id_restau" ) @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public Restaurant getRestau() { return restau; diff --git a/src/main/java/fr/cardon/simpleat/model/Restaurant.java b/src/main/java/fr/cardon/simpleat/model/Restaurant.java index 9035bd2..a85ca3f 100644 --- a/src/main/java/fr/cardon/simpleat/model/Restaurant.java +++ b/src/main/java/fr/cardon/simpleat/model/Restaurant.java @@ -3,6 +3,7 @@ package fr.cardon.simpleat.model; import java.util.ArrayList; import java.util.Collection; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -11,6 +12,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -32,7 +34,7 @@ public class Restaurant { private String longitude; private String website; private Collection typerestaus = new ArrayList(); - + private Collection preference = new ArrayList(); //TODO @OneToMany relier avec une collec de preferences public Restaurant() { @@ -150,5 +152,17 @@ public class Restaurant { public void setTyperestaus(Collection typerestaus) { this.typerestaus = typerestaus; } + + + @OneToMany(mappedBy = "preferencePK.restau", cascade = CascadeType.REMOVE) + @JsonIgnore + public Collection getPreference() { + return preference; + } + + + public void setPreference(Collection preference) { + this.preference = preference; + } } diff --git a/src/main/resources/Postman b/src/main/resources/Postman index 94de556..a222d5a 100644 --- a/src/main/resources/Postman +++ b/src/main/resources/Postman @@ -169,15 +169,15 @@ } }, "url": { - "raw": "localhost:8080/preference/5/5", + "raw": "localhost:8080/preference/1/3", "host": [ "localhost" ], "port": "8080", "path": [ "preference", - "5", - "5" + "1", + "3" ] } }, @@ -208,7 +208,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"preferencePK\": {\r\n \"personne\": {\r\n \"id\": 10\r\n },\r\n \"restau\": {\r\n \"id\": 2\r\n }\r\n },\r\n \"note\": 5,\r\n \"favori\": true\r\n}", + "raw": "{\r\n \"personne\": {\r\n \"id\": 1\r\n },\r\n \"restau\": {\r\n \"id\": 5\r\n },\r\n \"note\": 5,\r\n \"favoris\": true\r\n}", "options": { "raw": { "language": "json" diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 8dd4536..669d7b9 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -19,20 +19,20 @@ insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, ac insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Physicians Total Care, Inc.', '462 Mosinee Lane', '8521719889', false, false, 4, true, '-13.5', '48.86667'); insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Triweld Industries, Inc.', '2482 Corscot Way', '7513208452', false, true, 2, true, '34.326903', '108.117456'); -insert into preference (id_restau, id_personne, note, favori) values (2, 9, 1, false); -insert into preference (id_restau, id_personne, note, favori) values (3, 1, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 9, 3, true); -insert into preference (id_restau, id_personne, note, favori) values (4, 6, 2, false); -insert into preference (id_restau, id_personne, note, favori) values (5, 5, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 10, 1, false); -insert into preference (id_restau, id_personne, note, favori) values (5, 3, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 7, 1, true); -insert into preference (id_restau, id_personne, note, favori) values (4, 2, 1, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 3, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (3, 10, 4, false); -insert into preference (id_restau, id_personne, note, favori) values (3, 3, 4, true); -insert into preference (id_restau, id_personne, note, favori) values (2, 3, 3, false); -insert into preference (id_restau, id_personne, note, favori) values (2, 8, 3, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 9, 1, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (3, 1, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 9, 3, true); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (4, 6, 2, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (5, 5, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 10, 1, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (5, 3, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 7, 1, true); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (4, 2, 1, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 3, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (3, 10, 4, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (3, 3, 4, true); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 3, 3, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 8, 3, false); insert into type (id_type, libelle) values (1, 'Kebab'); insert into type (id_type, libelle) values (2, 'Supermarché'); From 8f0cbdb7581f5e00a2d7f33a9bf4d774212015cd Mon Sep 17 00:00:00 2001 From: Thomas <37211499+thomascardon35@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:25:55 +0100 Subject: [PATCH 11/35] Update .gitignore exclusion de application.properties --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index c2065bc..1acaf36 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ out/ ### VS Code ### .vscode/ + +application.properties From 1f5f94ac6309b5ec46c6208e234f4e36de0c6a13 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Mon, 14 Feb 2022 17:30:49 +0100 Subject: [PATCH 12/35] data.sql et bug Boolean null --- .../fr/cardon/simpleat/model/Restaurant.java | 28 +++++------ src/main/resources/data.sql | 49 +++++++++++++++++-- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/main/java/fr/cardon/simpleat/model/Restaurant.java b/src/main/java/fr/cardon/simpleat/model/Restaurant.java index a85ca3f..0a50a79 100644 --- a/src/main/java/fr/cardon/simpleat/model/Restaurant.java +++ b/src/main/java/fr/cardon/simpleat/model/Restaurant.java @@ -26,10 +26,10 @@ public class Restaurant { private String nom; private String adresse; private String telephone; - private boolean aEmporter; - private boolean surPlace; - private int prix; - private boolean accesPMR; + private Boolean aEmporter; + private Boolean surPlace; + private Integer prix; + private Boolean accesPMR; private String latitude; private String longitude; private String website; @@ -42,8 +42,8 @@ public class Restaurant { // TODO Auto-generated constructor stub } - public Restaurant(String nom, String adresse, String telephone, boolean aEmporter, boolean surPlace, int prix, - boolean accesPMR, String latitude, String longitude, String website, Collection typerestaus) { + public Restaurant(String nom, String adresse, String telephone, Boolean aEmporter, Boolean surPlace, int prix, + Boolean accesPMR, String latitude, String longitude, String website, Collection typerestaus) { super(); this.nom = nom; this.adresse = adresse; @@ -91,31 +91,31 @@ public class Restaurant { this.telephone = telephone; } @Column(nullable = true) - public boolean isaEmporter() { + public Boolean isaEmporter() { return aEmporter; } - public void setaEmporter(boolean aEmporter) { + public void setaEmporter(Boolean aEmporter) { this.aEmporter = aEmporter; } @Column(nullable = true) - public boolean isSurPlace() { + public Boolean isSurPlace() { return surPlace; } - public void setSurPlace(boolean surPlace) { + public void setSurPlace(Boolean surPlace) { this.surPlace = surPlace; } @Column(nullable = true) - public int getPrix() { + public Integer getPrix() { return prix; } - public void setPrix(int prix) { + public void setPrix(Integer prix) { this.prix = prix; } @Column(nullable = true) - public boolean isAccesPMR() { + public Boolean isAccesPMR() { return accesPMR; } - public void setAccesPMR(boolean accesPMR) { + public void setAccesPMR(Boolean accesPMR) { this.accesPMR = accesPMR; } @Column(nullable = false) diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 669d7b9..6c955fa 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -13,11 +13,50 @@ insert into personne (nom, prenom, email, password) values ('Crick', 'Andris', ' insert into role (id_role, intitule) values (1, 'Admin'); insert into role (id_role, intitule) values (2, 'User'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('L Perrigo Company', '301 Thierer Trail', '3092096786', false, true, 1, false, '2.1961772', '22.4708685'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Sanofi Pasteur Inc.', '9 Barnett Terrace', '6809964349', false, true, 2, false, '31.45571', '34.43719'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('REMEDYREPACK INC.', '3 West Park', '4565542193', true, false, 3, true, '49.817777', '19.785536'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Physicians Total Care, Inc.', '462 Mosinee Lane', '8521719889', false, false, 4, true, '-13.5', '48.86667'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Triweld Industries, Inc.', '2482 Corscot Way', '7513208452', false, true, 2, true, '34.326903', '108.117456'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,1,'Le Jardin de Montreuil','1 Rue du Sergent Godefroy, 93100 Montreuil','01 41 63 92 66','http://www.lejardindemontreuil.fr/','48.853391599999995','2.4347358'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,0,'La CaVe','45 Rue de Paris, 93100 Montreuil','01 42 87 09 48','http://www.lacaveestrestaurant.com/','48.8576152','2.4342148999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (3,0,1,1,'Villa 9 Trois','71 Rue Hoche, 93100 Montreuil','01 48 58 17 37','http://www.villa9trois.com/','48.8638352','2.4331966'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'L''Amourette','54 Rue Robespierre, 93100 Montreuil','01 48 59 99 94','http://www.lamourette.fr/','48.853121599999994','2.4234494'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'La Maison Montreuil','31 Rue du Capitaine Dreyfus, 93100 Montreuil','09 87 18 18 81','https://www.lamaisonmontreuil.com/','48.859359700000006','2.4399254999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'le poulet en feu','63 Rue Danton, 93100 Montreuil','09 87 51 10 90','https://www.pouletenfeu.fr/','48.8653553','2.4514297'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,1,'Les Tonneaux','62 Rue Robespierre, 93100 Montreuil','01 48 58 95 01',NULL,'48.85205','2.4238472'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Les Pianos','26 Rue Robespierre, 93100 Montreuil','09 63 53 85 17','https://www.facebook.com/lespianosmontreuilofficiel/','48.854841799999996','2.4230319'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,1,'M I M','113 Rue Marceau, 93100 Montreuil','01 43 63 31 13',NULL,'48.849849999999996','2.4265312999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'Le Gévaudan','1 Bd Rouget de Lisle, 93100 Montreuil','01 42 87 42 83',NULL,'48.8617445','2.4412374'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Restaurant Filippo','6 Bd Chanzy, 93100 Montreuil','01 48 18 08 16',NULL,'48.8583964','2.4349743'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,0,1,1,'Le Mange Disc','50 Rue de Romainville, 93100 Montreuil','09 83 54 60 27','https://m.facebook.com/Le-Mange-Disc-102557926519195/?locale2=fr_FR','48.8658457','2.4466363'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,NULL,'Restaurant El Kahina','227 Rue de Paris, 93100 Montreuil','01 48 70 95 46',NULL,'48.8550124','2.4195686'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (NULL,1,1,1,'La Baraka','262 Rue de Paris, 93100 Montreuil','01 42 87 19 27','http://www.labarakamontreuil.fr/?lang=fr','48.8549268','2.4177603999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'La Bottega Della Pizza','34 Bd Rouget de Lisle, 93100 Montreuil','01 43 63 04 35','http://www.labottegadellapizza.fr/','48.860204200000005','2.4387626'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,NULL,'Restaurant de la Paix','11 Rue Armand Carrel, 93100 Montreuil','01 73 55 21 72',NULL,'48.853764','2.4177003999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'La Fontaine Bar Restaurant','47 Rue Armand Carrel, 93100 Montreuil','01 48 70 08 84','https://www.facebook.com/pages/la-fontaine-de-montreuil-Restaurant/213852528659590?fref=ts','48.8512132','2.4183881'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (3,1,1,NULL,'La Cantine Arkose Montreuil','33 Rue du Progrès, 93100 Montreuil','01 49 88 45 07','https://lacantine.arkose.com/montreuil/','48.8516335','2.419278'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (3,1,1,NULL,'Kashmir Café.','14 Rue du Capitaine Dreyfus, 93100 Montreuil','01 43 63 33 86','http://www.kashmircafe.fr/','48.8582843','2.4378471999999998'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'W Lounge','37 Rue de Valmy, 93100 Montreuil','01 48 37 61 17','http://wlounge-montreuil.com/?utm_source=gmb&utm_medium=referral','48.8507208','2.4187186'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'L''Oasis','171 Rue de Paris, 93100 Montreuil','01 48 70 70 52','https://loasis-montreuil.fr/fr','48.855555599999995','2.4230556'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Obrigado','8 Av. de la Prte de Montreuil, 75020 Paris','09 84 58 24 21','http://obrigado.paris/','48.8534995','2.4118692'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Le Xanthos','30 Rue du Capitaine Dreyfus, 93100 Montreuil','01 55 86 26 77',NULL,'48.858785','2.4388468999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Thé Vert','43 Rue du Capitaine Dreyfus, 93100 Montreuil','01 42 87 79 57','http://www.thevertenligne.fr/','48.8596741','2.4405049'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Gramophone','1 Rue Pépin, 93100 Montreuil','01 49 88 74 56','http://www.restaurantlegramophone.com/','48.8641275','2.4449753'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,NULL,'La Grosse Mignonne','56 Rue Carnot, 93100 Montreuil','01 42 87 54 51','https://www.facebook.com/LaGrosseMignonne','48.855322','2.4413144'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,NULL,'La Galetiere','126 Rue de Paris, 93100 Montreuil','01 42 87 47 32','http://lagaletiere.eatbu.com/','48.8563999','2.4263293'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (3,1,1,1,'Le Mamaju','36 Rue de Lagny, 93100 Montreuil','01 83 74 02 26','https://mamaju-restaurant-montreuil.eatbu.com/','48.8490247','2.4265491'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'Le Pizzo','15 Rue du Capitaine Dreyfus, 93100 Montreuil','09 88 46 71 29',NULL,'48.8588721','2.4385882999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'L''Olivier','211 Rue de Paris, 93100 Montreuil','06 47 82 43 41',NULL,'48.855081','2.4203481'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Louise','27 Rue du Capitaine Dreyfus, 93100 Montreuil','06 75 32 56 81','https://instagram.com/cafelouisemontreuil?utm_medium=copy_link','48.859237','2.4394462'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'Ô Bar Lié','16 Rue de la République, 93100 Montreuil','01 48 58 71 95','http://www.obarlie.com/','48.8531155','2.4209562'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,NULL,'Gabycook','27 Rue du Progrès, 93100 Montreuil',NULL,NULL,'48.851772999999994','2.4202114'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'L''ALEMBERT','268 Rue de Paris, 93100 Montreuil','01 42 87 29 61','http://www.lalembert.fr/','48.8549126','2.4174881999999998'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'Gujarat','35 Bd Paul Vaillant Couturier, 93100 Montreuil','01 48 58 77 16','http://restaurantgujarat.fr/','48.865111','2.443053'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'L''effiloché Montreuil','5 Rue du Centenaire, 93100 Montreuil',NULL,NULL,'48.8579636','2.4270348'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'Famille-CMC','6 Av. Pasteur, 93100 Montreuil',NULL,NULL,'48.862999300000006','2.441328'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'O''Villagio','28 Rue du Capitaine Dreyfus, 93100 Montreuil','01 57 42 63 82','https://ovillaggio93.wixsite.com/o-villaggio','48.858722','2.4386695'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'La Brasserie des Laitières','38 Rue de Lagny, 93100 Montreuil','01 48 51 50 70','https://le-bl.metro.biz/','48.8490399','2.4262376999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'LE HAVANE','248 Rue de Paris, 93100 Montreuil','01 48 57 17 23',NULL,'48.855091599999994','2.4187965'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Chez Carla','6 Rue Claude Bernard, 93100 Montreuil','01 48 18 00 53','http://www.chezcarla.fr/','48.8699343','2.4507599'); + + + insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 9, 1, false); insert into preference (restau_id_restau, personne_id_personne, note, favori) values (3, 1, 5, false); From 73a352973ee0f555a7b15ef6fc232acf207751e1 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Mon, 14 Feb 2022 23:28:20 +0100 Subject: [PATCH 13/35] acces aux types par restau --- src/main/java/fr/cardon/simpleat/model/Restaurant.java | 1 - src/main/java/fr/cardon/simpleat/model/TypeRestau.java | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/cardon/simpleat/model/Restaurant.java b/src/main/java/fr/cardon/simpleat/model/Restaurant.java index 0a50a79..7f94abe 100644 --- a/src/main/java/fr/cardon/simpleat/model/Restaurant.java +++ b/src/main/java/fr/cardon/simpleat/model/Restaurant.java @@ -144,7 +144,6 @@ public class Restaurant { @JoinTable(name="type_restau", joinColumns = @JoinColumn(name = "id_restau"/*classe en cours*/,referencedColumnName = "id_restau" /*classe reliée*/) , inverseJoinColumns = @JoinColumn(name = "id_type",referencedColumnName = "id_type")) - @JsonBackReference("typerestaus") public Collection getTyperestaus() { return typerestaus; } diff --git a/src/main/java/fr/cardon/simpleat/model/TypeRestau.java b/src/main/java/fr/cardon/simpleat/model/TypeRestau.java index 01f6d51..0d85160 100644 --- a/src/main/java/fr/cardon/simpleat/model/TypeRestau.java +++ b/src/main/java/fr/cardon/simpleat/model/TypeRestau.java @@ -10,6 +10,7 @@ import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.Table; +import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -49,7 +50,7 @@ public class TypeRestau { } @ManyToMany(mappedBy="typerestaus") - @JsonIgnoreProperties("typerestaus") + @JsonBackReference("restaurants") public List getRestaurants() { return restaurants; } From 49694f4bc01de4ea52dd7fcb56ef7ba406a1ecf7 Mon Sep 17 00:00:00 2001 From: Thomas <37211499+thomascardon35@users.noreply.github.com> Date: Tue, 15 Feb 2022 00:03:51 +0100 Subject: [PATCH 14/35] Update build.gradle --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 92a2fa8..1474fba 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' runtimeOnly 'mysql:mysql-connector-java' testImplementation 'org.springframework.boot:spring-boot-starter-test' + developmentOnly 'org.springframework.boot:spring-boot-devtools' } test { From c3ef5f63b312af0ba929fb4a6100ce8ed98b5a02 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Tue, 15 Feb 2022 00:05:55 +0100 Subject: [PATCH 15/35] fin du merge dev->thomas sans bug --- .../fr/cardon/simpleat/model/Personne.java | 11 +-- .../fr/cardon/simpleat/model/Preference.java | 74 +++---------------- .../cardon/simpleat/model/PreferencePK.java | 6 +- src/main/resources/Postman | 6 -- src/main/resources/data.sql | 1 - 5 files changed, 17 insertions(+), 81 deletions(-) diff --git a/src/main/java/fr/cardon/simpleat/model/Personne.java b/src/main/java/fr/cardon/simpleat/model/Personne.java index 520f149..3950856 100644 --- a/src/main/java/fr/cardon/simpleat/model/Personne.java +++ b/src/main/java/fr/cardon/simpleat/model/Personne.java @@ -36,12 +36,6 @@ public class Personne { } - public Personne(int id) { - super(); - this.id = id; - } - - public Personne(String nom, String prenom, String email, String password) { super(); this.nom = nom; @@ -129,7 +123,4 @@ public class Personne { this.preference = preference; } - - - -} +} \ No newline at end of file diff --git a/src/main/java/fr/cardon/simpleat/model/Preference.java b/src/main/java/fr/cardon/simpleat/model/Preference.java index c3b52e3..efab64c 100644 --- a/src/main/java/fr/cardon/simpleat/model/Preference.java +++ b/src/main/java/fr/cardon/simpleat/model/Preference.java @@ -1,20 +1,13 @@ package fr.cardon.simpleat.model; import javax.persistence.Column; +import javax.persistence.EmbeddedId; import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity -@IdClass(PreferencePK.class) public class Preference { - private Personne personne; - private Restaurant restau; + private PreferencePK preferencePK; private int note; private boolean favoris; @@ -26,79 +19,36 @@ public class Preference { } - - public Preference(Personne personne, Restaurant restau) { + public Preference(PreferencePK preferencePK, int note, boolean favoris) { super(); - this.personne = personne; - this.restau = restau; - } - - - - public Preference(Personne personne, Restaurant restau, int note, boolean favoris) { - super(); - this.personne = personne; - this.restau = restau; + this.preferencePK = preferencePK; this.note = note; this.favoris = favoris; } - - @Id - @ManyToOne - @JoinColumn(name="id_personne" ) - @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) - public Personne getPersonne() { - return personne; + @EmbeddedId + public PreferencePK getPreferencePK() { + return preferencePK; } - - - - public void setPersonne(Personne personne) { - this.personne = personne; + public void setPreferencePK(PreferencePK preferencePK) { + this.preferencePK = preferencePK; } - - @Id - @ManyToOne - @JoinColumn(name="id_restau" ) - @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) - public Restaurant getRestau() { - return restau; - } - - - - public void setRestau(Restaurant restau) { - this.restau = restau; - } - - @Column(nullable = true) public int getNote() { return note; } - - - public void setNote(int note) { this.note = note; } - - @Column(nullable = true) - public boolean isFavoris() { + public boolean isFavori() { return favoris; } - - - - public void setFavoris(boolean favoris) { + public void setFavori(boolean favoris) { this.favoris = favoris; } - - -} +} \ No newline at end of file diff --git a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java index 2cd7550..bbde557 100644 --- a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java +++ b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java @@ -3,6 +3,7 @@ package fr.cardon.simpleat.model; import java.io.Serializable; +import javax.persistence.CascadeType; import javax.persistence.Embeddable; import javax.persistence.FetchType; import javax.persistence.JoinColumn; @@ -12,7 +13,7 @@ import javax.persistence.PrimaryKeyJoinColumn; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - +@Embeddable public class PreferencePK implements Serializable { /** @@ -48,6 +49,7 @@ public class PreferencePK implements Serializable { this.personne = personne; } + @ManyToOne // TODO mappedBy preferences dans restaurant @PrimaryKeyJoinColumn(name="id_restau",referencedColumnName ="id_restau" ) @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) @@ -62,4 +64,4 @@ public class PreferencePK implements Serializable { -} +} \ No newline at end of file diff --git a/src/main/resources/Postman b/src/main/resources/Postman index cbee787..a222d5a 100644 --- a/src/main/resources/Postman +++ b/src/main/resources/Postman @@ -169,19 +169,15 @@ } }, "url": { - "raw": "localhost:8080/preference/1/3", - "host": [ "localhost" ], "port": "8080", "path": [ "preference", - "1", "3" - ] } }, @@ -212,9 +208,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"personne\": {\r\n \"id\": 1\r\n },\r\n \"restau\": {\r\n \"id\": 5\r\n },\r\n \"note\": 5,\r\n \"favoris\": true\r\n}", - "options": { "raw": { "language": "json" diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 6615fc2..6c955fa 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -73,7 +73,6 @@ insert into preference (restau_id_restau, personne_id_personne, note, favori) va insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 3, 3, false); insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 8, 3, false); - insert into type (id_type, libelle) values (1, 'Kebab'); insert into type (id_type, libelle) values (2, 'Supermarché'); insert into type (id_type, libelle) values (3, 'Boulangerie'); From fc916ca0b659c2152e68eba03285f36c3efb0714 Mon Sep 17 00:00:00 2001 From: Vincent Ramiere Date: Wed, 16 Feb 2022 15:17:34 +0100 Subject: [PATCH 16/35] Modif app.properties_vincent --- src/main/resources/application.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 875e116..1697a55 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,9 +1,9 @@ # =============================== # base de données MySQL # =============================== -spring.datasource.url=jdbc:mysql://localhost:3308/simpleat?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=CET -spring.datasource.username=root -spring.datasource.password=root +spring.datasource.url=jdbc:mysql://localhost:3306/simpleat?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=CET +spring.datasource.username=simplon +spring.datasource.password=bbLouis1&Noe2 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # log #logging.level.root=INFO From 4899fa8237021193b859dcad311ed8523354f8dc Mon Sep 17 00:00:00 2001 From: Thomas <37211499+thomascardon35@users.noreply.github.com> Date: Wed, 16 Feb 2022 15:25:10 +0100 Subject: [PATCH 17/35] Update .gitignore application.properties --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 1acaf36..4369206 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ build/ !**/src/main/**/build/ !**/src/test/**/build/ +src/main/resources/application.properties + + ### STS ### .apt_generated .classpath @@ -35,5 +38,3 @@ out/ ### VS Code ### .vscode/ - -application.properties From af3a009e4c7c8272a83e2a5e1c4cb559723e0245 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 16 Feb 2022 15:26:40 +0100 Subject: [PATCH 18/35] modif data.sql --- src/main/resources/data.sql | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 6c955fa..b010896 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -93,11 +93,18 @@ insert into type (id_type, libelle) values (17, 'Marocain'); insert into type (id_type, libelle) values (18, 'Fruits de Mer'); insert into type (id_type, libelle) values (19, 'Steack'); insert into type (id_type, libelle) values (20, 'Vietnamien'); +insert into type (id_type, libelle) values (21, 'Bistrot'); +insert into type (id_type, libelle) values (22, 'Poulet'); -insert into type_restau (id_restau, id_type) values (1, 3); -insert into type_restau (id_restau, id_type) values (2, 1); -insert into type_restau (id_restau, id_type) values (3, 1); -insert into type_restau (id_restau, id_type) values (4, 2); -insert into type_restau (id_restau, id_type) values (5, 4); -insert into type_restau (id_restau, id_type) values (1, 2); \ No newline at end of file +insert into type_restau (id_restau, id_type) values (1, 5); +insert into type_restau (id_restau, id_type) values (2, 5); +insert into type_restau (id_restau, id_type) values (3, 5); +insert into type_restau (id_restau, id_type) values (4, 5); +insert into type_restau (id_restau, id_type) values (5, 5); +insert into type_restau (id_restau, id_type) values (6, 8); +insert into type_restau (id_restau, id_type) values (6, 22); +insert into type_restau (id_restau, id_type) values (7, 7); +insert into type_restau (id_restau, id_type) values (8, 5); +insert into type_restau (id_restau, id_type) values (9, 21); +insert into type_restau (id_restau, id_type) values (10, 7); \ No newline at end of file From 3f3e03b4b1bb2b941666bb63adad147ccb847a35 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 16 Feb 2022 15:30:00 +0100 Subject: [PATCH 19/35] test gitignore properties --- src/main/resources/application.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1697a55..875e116 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,9 +1,9 @@ # =============================== # base de données MySQL # =============================== -spring.datasource.url=jdbc:mysql://localhost:3306/simpleat?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=CET -spring.datasource.username=simplon -spring.datasource.password=bbLouis1&Noe2 +spring.datasource.url=jdbc:mysql://localhost:3308/simpleat?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=CET +spring.datasource.username=root +spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # log #logging.level.root=INFO From b6fef494278f1f34ba4f7b761db39611ba5b6413 Mon Sep 17 00:00:00 2001 From: Thomas <37211499+thomascardon35@users.noreply.github.com> Date: Wed, 16 Feb 2022 15:33:53 +0100 Subject: [PATCH 20/35] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4369206..da015e2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ build/ !**/src/main/**/build/ !**/src/test/**/build/ -src/main/resources/application.properties +/src/main/resources/application.properties ### STS ### From 2e4055c08437234cf5dbf51ce651818ea1aef8fc Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 16 Feb 2022 15:35:24 +0100 Subject: [PATCH 21/35] test --- src/main/resources/application.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 875e116..f0196d3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -20,4 +20,5 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDial # Permet d'exécuter le data.sql # =============================== spring.sql.init.mode=always -spring.jpa.defer-datasource-initialization=true \ No newline at end of file +spring.jpa.defer-datasource-initialization=true +#test \ No newline at end of file From 1d92a6986a351ff3ec0607adf760a216b8ca89ee Mon Sep 17 00:00:00 2001 From: Thomas <37211499+thomascardon35@users.noreply.github.com> Date: Wed, 16 Feb 2022 15:48:00 +0100 Subject: [PATCH 22/35] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index da015e2..837418a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ build/ !**/src/main/**/build/ !**/src/test/**/build/ -/src/main/resources/application.properties +*.properties ### STS ### From 098c21df05f7731feb8f2a3cf7b524a62ef3deaf Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 16 Feb 2022 15:51:22 +0100 Subject: [PATCH 23/35] test --- src/main/resources/application.properties | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f0196d3..875e116 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -20,5 +20,4 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDial # Permet d'exécuter le data.sql # =============================== spring.sql.init.mode=always -spring.jpa.defer-datasource-initialization=true -#test \ No newline at end of file +spring.jpa.defer-datasource-initialization=true \ No newline at end of file From 02d767e40e902e5656a4d43dba3f123a669122c6 Mon Sep 17 00:00:00 2001 From: Thomas <37211499+thomascardon35@users.noreply.github.com> Date: Wed, 16 Feb 2022 15:52:44 +0100 Subject: [PATCH 24/35] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 837418a..7abadce 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ build/ !**/src/main/**/build/ !**/src/test/**/build/ -*.properties +application.properties ### STS ### From 18e4d8c76cc7aa31d6dd269f16143aab6a3db0c2 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 16 Feb 2022 16:03:39 +0100 Subject: [PATCH 25/35] test --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 837418a..69bd3ff 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ out/ ### VS Code ### .vscode/ +application.properties From ac43443308d13422277cf2d1881aea1070d3a590 Mon Sep 17 00:00:00 2001 From: Thomas <37211499+thomascardon35@users.noreply.github.com> Date: Wed, 16 Feb 2022 16:46:00 +0100 Subject: [PATCH 26/35] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 337d2bf..7abadce 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,3 @@ out/ ### VS Code ### .vscode/ -application.properties From 25da5fbf5705550eac8952e33220670cd5f34310 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 16 Feb 2022 17:05:40 +0100 Subject: [PATCH 27/35] modif data.sql --- src/main/resources/data.sql | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index b010896..6126ca4 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,14 +1,17 @@ - -insert into personne (nom, prenom, email, password) values ('Harmond', 'Ludvig', 'lharmond0@moonfruit.com', 'pjKxIN'); -insert into personne (nom, prenom, email, password) values ('Fisbey', 'Jammal', 'jfisbey1@apache.org', 'YY0TuY6JH0di'); -insert into personne (nom, prenom, email, password) values ('Scrivener', 'Anatol', 'ascrivener2@jugem.jp', 'C4sfAW4'); -insert into personne (nom, prenom, email, password) values ('Berthelet', 'Oralla', 'oberthelet3@cnbc.com', 'ACdXxMr'); -insert into personne (nom, prenom, email, password) values ('Towe', 'Homerus', 'htowe4@home.pl', 'pQGi41q5JHY'); -insert into personne (nom, prenom, email, password) values ('Viggers', 'Gaby', 'gviggers5@xing.com', 'Gbr2M5UU'); -insert into personne (nom, prenom, email, password) values ('Willshere', 'Sheba', 'swillshere6@tinyurl.com', 'yVJmjda'); -insert into personne (nom, prenom, email, password) values ('Docksey', 'Eula', 'edocksey7@mozilla.com', '6yS7lkFpuY'); -insert into personne (nom, prenom, email, password) values ('Iglesias', 'Christen', 'ciglesias8@ebay.com', 'ottn7Qb'); -insert into personne (nom, prenom, email, password) values ('Crick', 'Andris', 'acrick9@etsy.com', 'nkmUVBeKr'); +insert into personne (nom, prenom, email, password) values ('Cardon', 'Thomas', 'thomas.cardon@gmail.com', 'pjKxIN'); +insert into personne (nom, prenom, email, password) values ('Ramiere', 'Vincent', 'vincent.ramiere@gmail.com', 'YY0TuY6JH0di'); +insert into personne (nom, prenom, email, password) values ('Verger', 'Romain', 'romain.verger@gmail.com', 'C4sfAW4'); +insert into personne (nom, prenom, email, password) values ('Ribardiere', 'Paul-Emmanuel', 'paul.ribardiere@gmail.com', 'ACdXxMr'); +insert into personne (nom, prenom, email, password) values ('Noris', 'William', 'william.noris@gmail.com', 'pjKxIN'); +insert into personne (nom, prenom, email, password) values ('Harmand', 'Isabelle', 'isabelle.harmand@gmail.com', 'YY0TuY6JH0di'); +insert into personne (nom, prenom, email, password) values ('Bajard', 'Blandine', 'blandine.bajard@gmail.com', 'C4sfAW4'); +insert into personne (nom, prenom, email, password) values ('El hiri', 'Sana', 'sana.el-hiri@gmail.com', 'ACdXxMr'); +insert into personne (nom, prenom, email, password) values ('Lucas', 'Cecile', 'cecile.lucas@gmail.com', 'pjKxIN'); +insert into personne (nom, prenom, email, password) values ('Kerkeb', 'Mohamed', 'mohamed.kerkeb@gmail.com', 'YY0TuY6JH0di'); +insert into personne (nom, prenom, email, password) values ('Rinquin', 'Aline', 'aline.rinquin@gmail.com', 'C4sfAW4'); +insert into personne (nom, prenom, email, password) values ('Keddar', 'Noreddine', 'noredinne.keddar@gmail.com', 'ACdXxMr'); +insert into personne (nom, prenom, email, password) values ('Tomczyk', 'Julian', 'julian.tomczyk@gmail.com', 'pjKxIN'); +insert into personne (nom, prenom, email, password) values ('MJID', 'Hedi', 'hedi.mjid@gmail.com', 'YY0TuY6JH0di'); insert into role (id_role, intitule) values (1, 'Admin'); insert into role (id_role, intitule) values (2, 'User'); From c8d9cd4db88d54fc887a49c5e832fadecab7552c Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 28 Feb 2022 14:10:36 +0100 Subject: [PATCH 28/35] secu --- build.gradle | 13 +- settings.gradle | 2 +- .../cardon/simpleat/SimpleatApplication.java | 20 ++ .../controller/PersonneController.java | 36 ++++ .../controller/RestaurantController.java | 3 + .../fr/cardon/simpleat/dto/JsonWebToken.java | 21 ++ .../fr/cardon/simpleat/dto/PersonneDto.java | 55 ++++++ .../exception/ExistingUsernameException.java | 15 ++ .../InvalidCredentialsException.java | 15 ++ .../exception/InvalidJWTException.java | 16 ++ .../fr/cardon/simpleat/model/EnumRole.java | 14 ++ .../fr/cardon/simpleat/model/Personne.java | 46 ++++- .../repository/PersonneRepository.java | 8 + .../simpleat/security/JwtTokenFilter.java | 47 +++++ .../simpleat/security/JwtTokenProvider.java | 184 ++++++++++++++++++ .../simpleat/security/WebSecurityConfig.java | 78 ++++++++ .../simpleat/service/PersonneService.java | 48 +++++ .../simpleat/service/PersonneServiceImpl.java | 74 +++++++ .../service/UserDetailsServiceImpl.java | 42 ++++ src/main/resources/application.properties | 12 +- src/main/resources/data.sql | 44 +++-- 21 files changed, 764 insertions(+), 29 deletions(-) create mode 100644 src/main/java/fr/cardon/simpleat/dto/JsonWebToken.java create mode 100644 src/main/java/fr/cardon/simpleat/dto/PersonneDto.java create mode 100644 src/main/java/fr/cardon/simpleat/exception/ExistingUsernameException.java create mode 100644 src/main/java/fr/cardon/simpleat/exception/InvalidCredentialsException.java create mode 100644 src/main/java/fr/cardon/simpleat/exception/InvalidJWTException.java create mode 100644 src/main/java/fr/cardon/simpleat/model/EnumRole.java create mode 100644 src/main/java/fr/cardon/simpleat/security/JwtTokenFilter.java create mode 100644 src/main/java/fr/cardon/simpleat/security/JwtTokenProvider.java create mode 100644 src/main/java/fr/cardon/simpleat/security/WebSecurityConfig.java create mode 100644 src/main/java/fr/cardon/simpleat/service/PersonneService.java create mode 100644 src/main/java/fr/cardon/simpleat/service/PersonneServiceImpl.java create mode 100644 src/main/java/fr/cardon/simpleat/service/UserDetailsServiceImpl.java diff --git a/build.gradle b/build.gradle index 1474fba..2570a80 100644 --- a/build.gradle +++ b/build.gradle @@ -13,11 +13,14 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'org.springframework.boot:spring-boot-starter-web' - runtimeOnly 'mysql:mysql-connector-java' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - developmentOnly 'org.springframework.boot:spring-boot-devtools' + implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.0' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-security' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + runtimeOnly 'mysql:mysql-connector-java' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.security:spring-security-test' } test { diff --git a/settings.gradle b/settings.gradle index c74741c..e76d701 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'simpleat' +rootProject.name = 'simpleat-back' diff --git a/src/main/java/fr/cardon/simpleat/SimpleatApplication.java b/src/main/java/fr/cardon/simpleat/SimpleatApplication.java index ebaf5a7..37dea51 100644 --- a/src/main/java/fr/cardon/simpleat/SimpleatApplication.java +++ b/src/main/java/fr/cardon/simpleat/SimpleatApplication.java @@ -1,13 +1,33 @@ package fr.cardon.simpleat; +import java.util.ArrayList; +import java.util.Arrays; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +import fr.cardon.simpleat.exception.ExistingUsernameException; +import fr.cardon.simpleat.model.EnumRole; +import fr.cardon.simpleat.model.Personne; +import fr.cardon.simpleat.service.PersonneService; @SpringBootApplication public class SimpleatApplication { + + public static void main(String[] args) { SpringApplication.run(SimpleatApplication.class, args); } + @Bean + public BCryptPasswordEncoder bCryptPasswordEncoder() { + return new BCryptPasswordEncoder(); + } + + + + } diff --git a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java index 57c1eb4..360e75d 100644 --- a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java +++ b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java @@ -5,6 +5,7 @@ import java.util.Collection; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -12,13 +13,18 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; +import fr.cardon.simpleat.dto.JsonWebToken; +import fr.cardon.simpleat.exception.ExistingUsernameException; +import fr.cardon.simpleat.exception.InvalidCredentialsException; import fr.cardon.simpleat.model.Personne; import fr.cardon.simpleat.model.Role; import fr.cardon.simpleat.repository.PersonneRepository; import fr.cardon.simpleat.repository.RoleRepository; +import fr.cardon.simpleat.service.PersonneService; @RestController @CrossOrigin("*") @@ -31,6 +37,11 @@ public class PersonneController { @Autowired private RoleRepository roleRepository; + @Autowired + private PersonneService personneService; + + + @GetMapping("/") @ResponseBody public String home(){ @@ -57,18 +68,21 @@ public class PersonneController { @GetMapping("/users") + @PreAuthorize("hasRole('ROLE_ADMIN')") public Collection findAll(){ return personneRepository.findAll(); } @GetMapping("/user/{id}") + @PreAuthorize("hasRole('ROLE_ADMIN')") public Personne findPersonneById(@PathVariable int id){ return personneRepository.findById(id); } @PostMapping("/add-user") + @PreAuthorize("hasRole('ROLE_ADMIN')") public ResponseEntity ajoutPersonne(@RequestBody Personne personne){ return ResponseEntity.status(HttpStatus.OK).body(personneRepository.save(personne)); } @@ -99,6 +113,28 @@ public class PersonneController { return roleRepository.findCollectionById(idRole); } + @PostMapping("/sign-in") + public ResponseEntity signIn(@RequestBody Personne personne) { + try { + // ici on créé un JWT en passant l'email et le mot de passe + // récupéré de l'objet user passé en paramètre. + return ResponseEntity.ok(new JsonWebToken(personneService.signin(personne.getEmail(), personne.getPassword()))); + } catch (InvalidCredentialsException ex) { + // on renvoie une réponse négative + return ResponseEntity.badRequest().build(); + } + } + + @PostMapping("/sign-up") + public ResponseEntity signUp(@RequestBody Personne personne) { + try { + return ResponseEntity.ok(new JsonWebToken(personneService.signup(personne))); + } catch (ExistingUsernameException ex) { + return ResponseEntity.badRequest().build(); + } + } + + // public Personne findById(int id) { // return personneRepository.getById(id); // } diff --git a/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java b/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java index a5653ae..be17291 100644 --- a/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java +++ b/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java @@ -5,6 +5,7 @@ import java.util.Collection; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -37,12 +38,14 @@ public class RestaurantController { } @PostMapping("/add-restaurant") + @PreAuthorize("hasRole('ROLE_ADMIN')") public ResponseEntity ajoutRestaurant(@RequestBody Restaurant personne){ return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne)); } @PutMapping(value = "/update-restaurant/{id}") + public ResponseEntity modifRestaurant(@PathVariable int id, @RequestBody Restaurant personne){ return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne)); } diff --git a/src/main/java/fr/cardon/simpleat/dto/JsonWebToken.java b/src/main/java/fr/cardon/simpleat/dto/JsonWebToken.java new file mode 100644 index 0000000..021837a --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/dto/JsonWebToken.java @@ -0,0 +1,21 @@ +package fr.cardon.simpleat.dto; + +/** + * Classe spécifique DTO (Data Transfer Object) qui retourne un Jeton au format JSON (REST response) + * + */ + +public class JsonWebToken { + + private final String token; + + public JsonWebToken(String token) { + this.token = token; + } + + public String getToken() { + return token; + } +} + + diff --git a/src/main/java/fr/cardon/simpleat/dto/PersonneDto.java b/src/main/java/fr/cardon/simpleat/dto/PersonneDto.java new file mode 100644 index 0000000..c078b59 --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/dto/PersonneDto.java @@ -0,0 +1,55 @@ +package fr.cardon.simpleat.dto; + +import java.util.List; + + +import com.sun.istack.NotNull; + +import fr.cardon.simpleat.model.Role; + +/** + * Specifique : AppUser DTO permet de renvoyer un User sans le mot de passe (REST response). + */ +public class PersonneDto { + + private Long id; + private String email; + private List roleList; + + public PersonneDto() { } + + public PersonneDto(@NotNull String email) { + this(email,null); + } + + public PersonneDto(@NotNull String email, List roleList) { + this.email = email; + this.roleList = roleList; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public List getRoleList() { + return roleList; + } + + public void setRoleList(List roleList) { + this.roleList = roleList; + } + + +} diff --git a/src/main/java/fr/cardon/simpleat/exception/ExistingUsernameException.java b/src/main/java/fr/cardon/simpleat/exception/ExistingUsernameException.java new file mode 100644 index 0000000..4ca7c65 --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/exception/ExistingUsernameException.java @@ -0,0 +1,15 @@ +package fr.cardon.simpleat.exception; + +/** + * Classe personnalisée pour gérer un message si l'utilisateur (User) existe en Base de données + */ +public class ExistingUsernameException extends Exception { + + private static final long serialVersionUID = 1L; + + @Override + public String getMessage() + { + return "Désolé, l'utilisateur existe déjà en Base de données !"; + } +} diff --git a/src/main/java/fr/cardon/simpleat/exception/InvalidCredentialsException.java b/src/main/java/fr/cardon/simpleat/exception/InvalidCredentialsException.java new file mode 100644 index 0000000..82cf0cc --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/exception/InvalidCredentialsException.java @@ -0,0 +1,15 @@ +package fr.cardon.simpleat.exception; + +/** + * Specific exception that should be thrown when user credentials are not valid. + */ +public class InvalidCredentialsException extends Exception { + + private static final long serialVersionUID = -6483691380297851921L; + + @Override + public String getMessage() + { + return "L'accréditation est invalide !"; + } +} diff --git a/src/main/java/fr/cardon/simpleat/exception/InvalidJWTException.java b/src/main/java/fr/cardon/simpleat/exception/InvalidJWTException.java new file mode 100644 index 0000000..82036fc --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/exception/InvalidJWTException.java @@ -0,0 +1,16 @@ +package fr.cardon.simpleat.exception; + +/** + * Specific exception that should be thrown when a JWT has an invalid format. + */ +public class InvalidJWTException extends Exception { + + private static final long serialVersionUID = -6546999838071338632L; + + @Override + public String getMessage() + { + return "Le format JWT est invalide !"; + } + +} diff --git a/src/main/java/fr/cardon/simpleat/model/EnumRole.java b/src/main/java/fr/cardon/simpleat/model/EnumRole.java new file mode 100644 index 0000000..29efe61 --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/model/EnumRole.java @@ -0,0 +1,14 @@ +package fr.cardon.simpleat.model; + +import org.springframework.security.core.GrantedAuthority; + +public enum EnumRole implements GrantedAuthority { + + ROLE_ADMIN, ROLE_CREATOR, ROLE_READER; + + @Override + public String getAuthority() { + return name(); + } + +} diff --git a/src/main/java/fr/cardon/simpleat/model/Personne.java b/src/main/java/fr/cardon/simpleat/model/Personne.java index 68c58a8..d0534bc 100644 --- a/src/main/java/fr/cardon/simpleat/model/Personne.java +++ b/src/main/java/fr/cardon/simpleat/model/Personne.java @@ -3,10 +3,15 @@ package fr.cardon.simpleat.model; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.ElementCollection; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -18,6 +23,8 @@ import javax.persistence.OneToMany; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + + @Entity public class Personne { @@ -28,6 +35,7 @@ public class Personne { private String password; private Collection roles = new ArrayList(); private Collection preference = new ArrayList(); + private List roleList; public Personne() { @@ -35,6 +43,18 @@ public class Personne { // TODO Auto-generated constructor stub } + + + +public Personne(String email, String password, List roleList) { + super(); + this.email = email; + this.password = password; + this.roleList = roleList; + } + + + public Personne(String nom, String prenom, String email, String password) { super(); @@ -45,17 +65,20 @@ public class Personne { } - - - public Personne(String nom, String prenom, String email, String password, Collection roles) { + public Personne(String nom, String prenom, String email, String password, + Collection roles, Collection preference, + List roleList) { super(); this.nom = nom; this.prenom = prenom; this.email = email; this.password = password; this.roles = roles; + this.preference = preference; + this.roleList = roleList; } + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id_personne") @@ -123,4 +146,21 @@ public class Personne { this.preference = preference; } + @ElementCollection(fetch = FetchType.EAGER) + @Enumerated(EnumType.STRING) + public List getRoleList() { + return roleList; + } + + + public void setRoleList(List roleList) { + this.roleList = roleList; + } + + + + + + + } diff --git a/src/main/java/fr/cardon/simpleat/repository/PersonneRepository.java b/src/main/java/fr/cardon/simpleat/repository/PersonneRepository.java index 3089bd7..0df6572 100644 --- a/src/main/java/fr/cardon/simpleat/repository/PersonneRepository.java +++ b/src/main/java/fr/cardon/simpleat/repository/PersonneRepository.java @@ -1,5 +1,7 @@ package fr.cardon.simpleat.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -9,5 +11,11 @@ import fr.cardon.simpleat.model.Personne; public interface PersonneRepository extends JpaRepository { Personne findById(int id); + + Optional findByEmail(String email); + + boolean existsByEmail(String email); + + } diff --git a/src/main/java/fr/cardon/simpleat/security/JwtTokenFilter.java b/src/main/java/fr/cardon/simpleat/security/JwtTokenFilter.java new file mode 100644 index 0000000..bd0e495 --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/security/JwtTokenFilter.java @@ -0,0 +1,47 @@ +package fr.cardon.simpleat.security; + +import java.io.IOException; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.http.HttpStatus; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.filter.OncePerRequestFilter; + +import fr.cardon.simpleat.exception.InvalidJWTException; + + + +/** + * Filtre specifique en charge d'analyser la requête HTTP qui arrive vers notre Serveur et qui doit + * contenir un JWT valide. + */ +public class JwtTokenFilter extends OncePerRequestFilter { + private JwtTokenProvider jwtTokenProvider; + + public JwtTokenFilter(JwtTokenProvider jwtTokenProvider) { + this.jwtTokenProvider = jwtTokenProvider; + } + + @Override + protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { + String token = jwtTokenProvider.resolveToken(httpServletRequest); + try { + if (token != null && jwtTokenProvider.validateToken(token)) { + Authentication auth = jwtTokenProvider.getAuthentication(token); + SecurityContextHolder.getContext().setAuthentication(auth); + } + } catch (InvalidJWTException ex) { + // permet de garantir que le AppUser n'est pas authentifié + SecurityContextHolder.clearContext(); + httpServletResponse.sendError(HttpStatus.BAD_REQUEST.value(), "JWT invalide !"); + return; + } + + filterChain.doFilter(httpServletRequest, httpServletResponse); + } +} diff --git a/src/main/java/fr/cardon/simpleat/security/JwtTokenProvider.java b/src/main/java/fr/cardon/simpleat/security/JwtTokenProvider.java new file mode 100644 index 0000000..2e39ba4 --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/security/JwtTokenProvider.java @@ -0,0 +1,184 @@ +package fr.cardon.simpleat.security; + +import java.util.Base64; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import javax.annotation.PostConstruct; +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import fr.cardon.simpleat.exception.InvalidJWTException; +import fr.cardon.simpleat.model.EnumRole; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.JwtException; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +/** + * JWT : classe utilitaire chargée de fournir le Jeton (Token) et les vérifications + */ +@Component +public class JwtTokenProvider { + + // on récupère le secret dans notre fichier application.properties + @Value("${security.jwt.token.secret-key:secret-key}") + private String secretKey; + + // ici on met la valeur par défaut + @Value("${security.jwt.token.expire-length:3600000}") + private long validityInMilliseconds = 3600000; // 1h pour être pénard + + @Autowired + private UserDetailsService userDetailsService; + + /** + * Cette méthode d'initialisation s'exécute avant le constructeur + * Elle encode notre code secret en base64 pour la transmission dans le header + */ + @PostConstruct + protected void init() { + secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes()); + } + + /** + * Methode qui crée le Token avec : + * username comme un champ "sub", + * User Role comme champ "auth" + * "iat" comme date du jour , + * "exp" as now date + validity time. + * claims = les droits + struture : + HEADER : Algo + Type de Token + { + "alg": "HS256", + "typ": "JWT" + } + + PAYLOAD : data + { + "sub": "pbouget", + "auth": [ + "ROLE_ADMIN", + "ROLE_CREATOR", + "ROLE_READER" + ], + "iat": 1589817421, + "exp": 1589821021 + } + + Signature : + + Signature avec code secret : + + HMACSHA256( + base64UrlEncode(header) + "." + + base64UrlEncode(payload), + 03888dd6ceb88c3fee410a70802fb93d483fd52d70349d8f7e7581ae346cf658 + ) + + JWT génèrer avec cette info : + header = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. + payload = eyJzdWIiOiJwYm91Z2V0IiwiYXV0aCI6WyJST0xFX0FETUlOIiwiUk9MRV9DUkVBVE9SIiwiUk9MRV9SRUFERVIiXSwiaWF0IjoxNTg5ODE3NDIxLCJleHAiOjE1ODk4MjEwMjF9. + signature = lrKQIkrCzNMwzTN-hs_EdoYYxrb59sAlku7nmaml0vk + + vérifier sur https://jwt.io + + * @param username the user username. + * @param roles the user roles. + * @return the created JWT as String. + * @throws JsonProcessingException + */ + public String createToken(String email, List roleList){ + + Claims claims = Jwts.claims().setSubject(email); + claims.put("auth", roleList.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList())); + + System.out.println("claims = "+claims); + // claims = {sub=pbouget, auth=[ROLE_ADMIN, ROLE_CREATOR, ROLE_READER]} + Date now = new Date(); + Date validity = new Date(now.getTime() + validityInMilliseconds); + + String leToken = Jwts.builder()// + .setClaims(claims)// le username avec les roles ou setPayload() + .setIssuedAt(now)// 1589817421 pour le 18 mai 2020 à 17 heure 57 + .setExpiration(validity)// 1589821021 même date avec 1 heure de plus + .signWith(SignatureAlgorithm.HS256, secretKey) // la signature avec la clef secrête. + .compact(); // concatène l'ensemble pour construire une chaîne + System.out.println(leToken); // pour test cela donne ceci + /* + site pour convertir une date en millisecondes : http://timestamp.fr/? + site structure du jeton : https://www.vaadata.com/blog/fr/jetons-jwt-et-securite-principes-et-cas-dutilisation/ + site jwt encoder / décoder : https://jwt.io/ + eyJhbGciOiJIUzI1NiJ9. + eyJzdWIiOiJwYm91Z2V0IiwiYXV0aCI6W3siYXV0aG9yaXR5IjoiUk9MRV9BRE1JTiJ9LHsiYXV0aG9yaXR5IjoiUk9MRV9DUkVBVE9SIn0seyJhdXRob3JpdHkiOiJST0xFX1JFQURFUiJ9XSwiaWF0IjoxNTg5ODE2OTIyLCJleHAiOjE1ODk4MjA1MjJ9. + Cn4_UTjZ2UpJ32FVT3Bd1-VN8K62DVBHQbWiK6MNZ04 + + */ + // https://www.codeflow.site/fr/article/java__how-to-convert-java-object-to-from-json-jackson + + return leToken; + } + + /** + * Methode qui retourne un objet Authentication basé sur JWT. + * @param token : le token pour l'authentification. + * @return the authentication si Username est trouvé. + */ + public Authentication getAuthentication(String token) { + UserDetails userDetails = userDetailsService.loadUserByUsername(getUsername(token)); + return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities()); + } + + /** + * Methode qui extrait le userName du JWT. + * @param token : Token a analyser. + * @return le UserName comme chaîne de caractères. + */ + public String getUsername(String token) { + + return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody().getSubject(); + } + + /** + * Méthode qui récupère la requete HTTP. + * L'entête doit contenir un champ d'autorisation ou JWT ajoute le token après le mot clef Bearer. + * @param requete : la requête à tester. + * @return le JWT depuis l'entête HTTP. + */ + public String resolveToken(HttpServletRequest requeteHttp) { + String bearerToken = requeteHttp.getHeader("Authorization"); + if (bearerToken != null && bearerToken.startsWith("Bearer ")) { + return bearerToken.substring(7); + } + return null; + } + + /** + * Methode qui v�rifie que JWT est valide. + * La signature doit �tre correcte et la dur�e de validit� du Token doit �tre apr�s "now" (maintenant) + * @param token : Token � valider + * @return True si le Token est valide sinon on lance l'exception InvalidJWTException. + * @throws InvalidJWTException + */ + public boolean validateToken(String token) throws InvalidJWTException { + try { + Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token); + return true; + } catch (JwtException | IllegalArgumentException e) { + throw new InvalidJWTException(); + } + } +} diff --git a/src/main/java/fr/cardon/simpleat/security/WebSecurityConfig.java b/src/main/java/fr/cardon/simpleat/security/WebSecurityConfig.java new file mode 100644 index 0000000..07a43c4 --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/security/WebSecurityConfig.java @@ -0,0 +1,78 @@ +package fr.cardon.simpleat.security; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.BeanIds; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +/** + * Configuration de Sécurité globale pour notre REST API. + */ +@Configuration +@EnableGlobalMethodSecurity(prePostEnabled = true) +@EnableWebSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private JwtTokenProvider jwtTokenProvider; + + @Bean(name = BeanIds.AUTHENTICATION_MANAGER) + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + /** + * Methode qui configure la sécurité HTTP. + * @param http the HttpSecurity object to configure. + * @throws Exception + */ + @Override + protected void configure(HttpSecurity http) throws Exception { + + // Disable CSRF (Cross Site Request Forgery comme votre Token sera stocké dans le session storage) + http.cors(); + + http.csrf().disable() + .sessionManagement() + // Les sessions sont sans états et non créés ni utilisées par Spring security + .sessionCreationPolicy(SessionCreationPolicy.STATELESS) + .and() + // nos endpoints (points d'entrée de notre API) + .authorizeRequests() + // .anyRequest().authenticated() + .antMatchers("/v2/api-docs", "/configuration/**", "/swagger*/**", "/webjars/**") + .permitAll() + .antMatchers("**").permitAll() // se connecter + .antMatchers("**").permitAll() // s'inscrire + .antMatchers("api/user/all").hasAuthority("ROLE_ADMIN") // que pour le rôle admin + .antMatchers("/v2/api-docs", "/webjars/**", "/swagger-resources/**", "/configuration/**", "/swagger-ui.html/**").permitAll() + // .antMatchers("/api/admin/**").hasAuthority("ROLE_ADMIN") // que pour le rôle admin + // on désactive le reste... + .anyRequest().authenticated(); // tout le reste est autorisé. + // Appliquer JWT + http.addFilterBefore(new JwtTokenFilter(jwtTokenProvider), UsernamePasswordAuthenticationFilter.class); + + } + + /** + * Methode qui configure la sécurité web. + * Utilisé pour interdire l'accès à certains répertoires. + * @param web : WebSecurity + * @throws Exception + */ + @Override + public void configure(WebSecurity web) throws Exception { + web.ignoring().antMatchers("/resources/**"); + } +} + + diff --git a/src/main/java/fr/cardon/simpleat/service/PersonneService.java b/src/main/java/fr/cardon/simpleat/service/PersonneService.java new file mode 100644 index 0000000..99a7a4f --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/service/PersonneService.java @@ -0,0 +1,48 @@ +package fr.cardon.simpleat.service; + +import java.util.List; +import java.util.Optional; + +import org.springframework.stereotype.Service; + +import fr.cardon.simpleat.exception.ExistingUsernameException; +import fr.cardon.simpleat.exception.InvalidCredentialsException; +import fr.cardon.simpleat.model.Personne; + + + +@Service +public interface PersonneService { + + /** + * Methode qui permet à un utilisateur de se connecter. + * @param email : mail de l'utilisateur. + * @param password : mot de passe de l'utilisateur. + * @returnun JWT si credentials est valide, throws InvalidCredentialsException otherwise. + * @throws InvalidCredentialsException + */ + String signin(String email, String password) throws InvalidCredentialsException; + + /** + * Methode qui permet de s'inscrire. + * @param user nouvel utilisateur. + * @return un JWT si user n'existe pas déjà ! + * @throws ExistingUsernameException + */ + String signup(Personne personne) throws ExistingUsernameException; + + /** + * Methode qui retourne tous les utilisateurs de la bd + * @return the list of all application users. + */ + List findAllUsers(); + + /** + * Methode qui retourne un utilisateur à partir de son username + * @param username the username to look for. + * @return an Optional object containing user if found, empty otherwise. + */ + + + Optional findUserByEmail(String email); +} diff --git a/src/main/java/fr/cardon/simpleat/service/PersonneServiceImpl.java b/src/main/java/fr/cardon/simpleat/service/PersonneServiceImpl.java new file mode 100644 index 0000000..e569d34 --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/service/PersonneServiceImpl.java @@ -0,0 +1,74 @@ +package fr.cardon.simpleat.service; + +import java.util.List; +import java.util.Optional; + + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Service; + + + +import fr.cardon.simpleat.exception.ExistingUsernameException; +import fr.cardon.simpleat.exception.InvalidCredentialsException; +import fr.cardon.simpleat.model.Personne; +import fr.cardon.simpleat.repository.PersonneRepository; +import fr.cardon.simpleat.security.JwtTokenProvider; + + + +@Service +public class PersonneServiceImpl implements PersonneService { + + @Autowired + private PersonneRepository personneRepository; // permet communication avec la BD + + @Autowired + private BCryptPasswordEncoder passwordEncoder; // permet l'encodage du mot de passe + + @Autowired + private JwtTokenProvider jwtTokenProvider; // permet la fourniture du Jeton (Token) + + @Autowired + private AuthenticationManager authenticationManager; // gestionnaire d'authentification + + + /** + * Permet de se connecter en encodant le mot de passe avec génération du token. + */ + @Override + public String signin(String email, String password) throws InvalidCredentialsException { + try { + authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(email, password)); + return jwtTokenProvider.createToken(email, personneRepository.findByEmail(email).get().getRoleList()); + } catch (AuthenticationException e) { + throw new InvalidCredentialsException(); + } + } + + @Override + public String signup(Personne personne) throws ExistingUsernameException { + if (!personneRepository.existsByEmail(personne.getEmail())) { + Personne personneToSave = new Personne(personne.getEmail(), passwordEncoder.encode(personne.getPassword()), personne.getRoleList()); + personneRepository.save(personneToSave); + return jwtTokenProvider.createToken(personne.getEmail(), personne.getRoleList()); + } else { + throw new ExistingUsernameException(); + } + } + + @Override + public List findAllUsers() { + return personneRepository.findAll(); + } + + @Override + public Optional findUserByEmail(String email) { + return personneRepository.findByEmail(email); + } +} diff --git a/src/main/java/fr/cardon/simpleat/service/UserDetailsServiceImpl.java b/src/main/java/fr/cardon/simpleat/service/UserDetailsServiceImpl.java new file mode 100644 index 0000000..25129e1 --- /dev/null +++ b/src/main/java/fr/cardon/simpleat/service/UserDetailsServiceImpl.java @@ -0,0 +1,42 @@ +package fr.cardon.simpleat.service; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import fr.cardon.simpleat.model.Personne; + +import fr.cardon.simpleat.repository.PersonneRepository; + + +@Service +public class UserDetailsServiceImpl implements UserDetailsService { + + @Autowired + private PersonneRepository personneRepository; + + @Override + public UserDetails loadUserByUsername(String email) { + final Optional personne = personneRepository.findByEmail(email); + + if (!personne.isPresent()) { + throw new UsernameNotFoundException("utilisateur '" + email + "' introuvable"); + } + + return User + .withUsername(email) + .password(personne.get().getPassword()) + .authorities(personne.get().getRoleList()) + .accountExpired(false) + .accountLocked(false) + .credentialsExpired(false) + .disabled(false) + .build(); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 875e116..30cfcf0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,9 +1,14 @@ +#security.jwt.token.secret-key=03888dd6ceb88c3fee410a70802fb93d483fd52d70349d8f7e7581ae346cf658 +security.jwt.token.secret-key=simpleat +spring.main.allow-circular-references=true +# pour comprendre le but de cette ligne ci-dessus : https://www.baeldung.com/circular-dependencies-in-spring +# =============================== # =============================== # base de données MySQL # =============================== -spring.datasource.url=jdbc:mysql://localhost:3308/simpleat?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=CET +spring.datasource.url=jdbc:mysql://localhost:3306/simpleat?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=CET spring.datasource.username=root -spring.datasource.password=root +spring.datasource.password=BOHmilaresol02 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # log #logging.level.root=INFO @@ -20,4 +25,5 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDial # Permet d'exécuter le data.sql # =============================== spring.sql.init.mode=always -spring.jpa.defer-datasource-initialization=true \ No newline at end of file +spring.jpa.defer-datasource-initialization=true +server.port=8081 \ No newline at end of file diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 6c955fa..6126ca4 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,14 +1,17 @@ - -insert into personne (nom, prenom, email, password) values ('Harmond', 'Ludvig', 'lharmond0@moonfruit.com', 'pjKxIN'); -insert into personne (nom, prenom, email, password) values ('Fisbey', 'Jammal', 'jfisbey1@apache.org', 'YY0TuY6JH0di'); -insert into personne (nom, prenom, email, password) values ('Scrivener', 'Anatol', 'ascrivener2@jugem.jp', 'C4sfAW4'); -insert into personne (nom, prenom, email, password) values ('Berthelet', 'Oralla', 'oberthelet3@cnbc.com', 'ACdXxMr'); -insert into personne (nom, prenom, email, password) values ('Towe', 'Homerus', 'htowe4@home.pl', 'pQGi41q5JHY'); -insert into personne (nom, prenom, email, password) values ('Viggers', 'Gaby', 'gviggers5@xing.com', 'Gbr2M5UU'); -insert into personne (nom, prenom, email, password) values ('Willshere', 'Sheba', 'swillshere6@tinyurl.com', 'yVJmjda'); -insert into personne (nom, prenom, email, password) values ('Docksey', 'Eula', 'edocksey7@mozilla.com', '6yS7lkFpuY'); -insert into personne (nom, prenom, email, password) values ('Iglesias', 'Christen', 'ciglesias8@ebay.com', 'ottn7Qb'); -insert into personne (nom, prenom, email, password) values ('Crick', 'Andris', 'acrick9@etsy.com', 'nkmUVBeKr'); +insert into personne (nom, prenom, email, password) values ('Cardon', 'Thomas', 'thomas.cardon@gmail.com', 'pjKxIN'); +insert into personne (nom, prenom, email, password) values ('Ramiere', 'Vincent', 'vincent.ramiere@gmail.com', 'YY0TuY6JH0di'); +insert into personne (nom, prenom, email, password) values ('Verger', 'Romain', 'romain.verger@gmail.com', 'C4sfAW4'); +insert into personne (nom, prenom, email, password) values ('Ribardiere', 'Paul-Emmanuel', 'paul.ribardiere@gmail.com', 'ACdXxMr'); +insert into personne (nom, prenom, email, password) values ('Noris', 'William', 'william.noris@gmail.com', 'pjKxIN'); +insert into personne (nom, prenom, email, password) values ('Harmand', 'Isabelle', 'isabelle.harmand@gmail.com', 'YY0TuY6JH0di'); +insert into personne (nom, prenom, email, password) values ('Bajard', 'Blandine', 'blandine.bajard@gmail.com', 'C4sfAW4'); +insert into personne (nom, prenom, email, password) values ('El hiri', 'Sana', 'sana.el-hiri@gmail.com', 'ACdXxMr'); +insert into personne (nom, prenom, email, password) values ('Lucas', 'Cecile', 'cecile.lucas@gmail.com', 'pjKxIN'); +insert into personne (nom, prenom, email, password) values ('Kerkeb', 'Mohamed', 'mohamed.kerkeb@gmail.com', 'YY0TuY6JH0di'); +insert into personne (nom, prenom, email, password) values ('Rinquin', 'Aline', 'aline.rinquin@gmail.com', 'C4sfAW4'); +insert into personne (nom, prenom, email, password) values ('Keddar', 'Noreddine', 'noredinne.keddar@gmail.com', 'ACdXxMr'); +insert into personne (nom, prenom, email, password) values ('Tomczyk', 'Julian', 'julian.tomczyk@gmail.com', 'pjKxIN'); +insert into personne (nom, prenom, email, password) values ('MJID', 'Hedi', 'hedi.mjid@gmail.com', 'YY0TuY6JH0di'); insert into role (id_role, intitule) values (1, 'Admin'); insert into role (id_role, intitule) values (2, 'User'); @@ -93,11 +96,18 @@ insert into type (id_type, libelle) values (17, 'Marocain'); insert into type (id_type, libelle) values (18, 'Fruits de Mer'); insert into type (id_type, libelle) values (19, 'Steack'); insert into type (id_type, libelle) values (20, 'Vietnamien'); +insert into type (id_type, libelle) values (21, 'Bistrot'); +insert into type (id_type, libelle) values (22, 'Poulet'); -insert into type_restau (id_restau, id_type) values (1, 3); -insert into type_restau (id_restau, id_type) values (2, 1); -insert into type_restau (id_restau, id_type) values (3, 1); -insert into type_restau (id_restau, id_type) values (4, 2); -insert into type_restau (id_restau, id_type) values (5, 4); -insert into type_restau (id_restau, id_type) values (1, 2); \ No newline at end of file +insert into type_restau (id_restau, id_type) values (1, 5); +insert into type_restau (id_restau, id_type) values (2, 5); +insert into type_restau (id_restau, id_type) values (3, 5); +insert into type_restau (id_restau, id_type) values (4, 5); +insert into type_restau (id_restau, id_type) values (5, 5); +insert into type_restau (id_restau, id_type) values (6, 8); +insert into type_restau (id_restau, id_type) values (6, 22); +insert into type_restau (id_restau, id_type) values (7, 7); +insert into type_restau (id_restau, id_type) values (8, 5); +insert into type_restau (id_restau, id_type) values (9, 21); +insert into type_restau (id_restau, id_type) values (10, 7); \ No newline at end of file From d3b7a9bb8885c28e99be235a4f0f949e21ebbdff Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Mon, 28 Feb 2022 14:11:10 +0100 Subject: [PATCH 29/35] qq datas en + --- src/main/resources/data.sql | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 6126ca4..e31e999 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -110,4 +110,19 @@ insert into type_restau (id_restau, id_type) values (6, 22); insert into type_restau (id_restau, id_type) values (7, 7); insert into type_restau (id_restau, id_type) values (8, 5); insert into type_restau (id_restau, id_type) values (9, 21); -insert into type_restau (id_restau, id_type) values (10, 7); \ No newline at end of file +insert into type_restau (id_restau, id_type) values (10, 7); + +insert into role_personne (id_perso, roles_id_role) values (1, 1); +insert into role_personne (id_perso, roles_id_role) values (2, 1); +insert into role_personne (id_perso, roles_id_role) values (3, 1); +insert into role_personne (id_perso, roles_id_role) values (4, 1); +insert into role_personne (id_perso, roles_id_role) values (5, 2); +insert into role_personne (id_perso, roles_id_role) values (6, 2); +insert into role_personne (id_perso, roles_id_role) values (7, 2); +insert into role_personne (id_perso, roles_id_role) values (8, 2); +insert into role_personne (id_perso, roles_id_role) values (9, 2); +insert into role_personne (id_perso, roles_id_role) values (10, 2); +insert into role_personne (id_perso, roles_id_role) values (11, 2); +insert into role_personne (id_perso, roles_id_role) values (12, 2); +insert into role_personne (id_perso, roles_id_role) values (13, 2); +insert into role_personne (id_perso, roles_id_role) values (14, 2); \ No newline at end of file From 820aabcaa1d8c93e591fc87d7d0d853bd0dd09b5 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Mon, 28 Feb 2022 15:30:49 +0100 Subject: [PATCH 30/35] token = ok --- settings.gradle | 2 +- .../simpleat/controller/PersonneController.java | 4 ++-- src/main/java/fr/cardon/simpleat/model/Personne.java | 12 ++++++++++++ .../cardon/simpleat/service/PersonneServiceImpl.java | 7 ++++--- src/main/resources/application.properties | 7 +++---- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/settings.gradle b/settings.gradle index e76d701..c74741c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'simpleat-back' +rootProject.name = 'simpleat' diff --git a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java index 360e75d..4e2ee3b 100644 --- a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java +++ b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java @@ -68,7 +68,7 @@ public class PersonneController { @GetMapping("/users") - @PreAuthorize("hasRole('ROLE_ADMIN')") + //@PreAuthorize("hasRole('ROLE_ADMIN')") public Collection findAll(){ return personneRepository.findAll(); @@ -82,7 +82,7 @@ public class PersonneController { } @PostMapping("/add-user") - @PreAuthorize("hasRole('ROLE_ADMIN')") + //@PreAuthorize("hasRole('ROLE_ADMIN')") public ResponseEntity ajoutPersonne(@RequestBody Personne personne){ return ResponseEntity.status(HttpStatus.OK).body(personneRepository.save(personne)); } diff --git a/src/main/java/fr/cardon/simpleat/model/Personne.java b/src/main/java/fr/cardon/simpleat/model/Personne.java index d0534bc..425662f 100644 --- a/src/main/java/fr/cardon/simpleat/model/Personne.java +++ b/src/main/java/fr/cardon/simpleat/model/Personne.java @@ -46,6 +46,18 @@ public class Personne { +public Personne(String nom, String prenom, String email, String password, List roleList) { + super(); + this.nom = nom; + this.prenom = prenom; + this.email = email; + this.password = password; + this.roleList = roleList; + } + + + + public Personne(String email, String password, List roleList) { super(); this.email = email; diff --git a/src/main/java/fr/cardon/simpleat/service/PersonneServiceImpl.java b/src/main/java/fr/cardon/simpleat/service/PersonneServiceImpl.java index e569d34..8371fa5 100644 --- a/src/main/java/fr/cardon/simpleat/service/PersonneServiceImpl.java +++ b/src/main/java/fr/cardon/simpleat/service/PersonneServiceImpl.java @@ -3,8 +3,7 @@ package fr.cardon.simpleat.service; import java.util.List; import java.util.Optional; - - +import org.hibernate.internal.build.AllowSysOut; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -53,8 +52,10 @@ public class PersonneServiceImpl implements PersonneService { @Override public String signup(Personne personne) throws ExistingUsernameException { + System.out.println(personne .getNom()); if (!personneRepository.existsByEmail(personne.getEmail())) { - Personne personneToSave = new Personne(personne.getEmail(), passwordEncoder.encode(personne.getPassword()), personne.getRoleList()); + System.out.println(personne .getEmail()); + Personne personneToSave = new Personne(personne.getNom(),personne.getPrenom(),personne.getEmail(), passwordEncoder.encode(personne.getPassword()), personne.getRoleList()); personneRepository.save(personneToSave); return jwtTokenProvider.createToken(personne.getEmail(), personne.getRoleList()); } else { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 30cfcf0..19011c0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,9 +6,9 @@ spring.main.allow-circular-references=true # =============================== # base de données MySQL # =============================== -spring.datasource.url=jdbc:mysql://localhost:3306/simpleat?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=CET +spring.datasource.url=jdbc:mysql://localhost:3308/simpleat?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=CET spring.datasource.username=root -spring.datasource.password=BOHmilaresol02 +spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # log #logging.level.root=INFO @@ -25,5 +25,4 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDial # Permet d'exécuter le data.sql # =============================== spring.sql.init.mode=always -spring.jpa.defer-datasource-initialization=true -server.port=8081 \ No newline at end of file +spring.jpa.defer-datasource-initialization=true \ No newline at end of file From 656899ea4c43f7f0d47686aa8841f5ed9c2a7a4f Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 2 Mar 2022 14:05:02 +0100 Subject: [PATCH 31/35] atteindre Preferences dans Personne --- .../fr/cardon/simpleat/controller/PersonneController.java | 4 ++-- .../fr/cardon/simpleat/controller/RestaurantController.java | 2 +- src/main/java/fr/cardon/simpleat/model/Personne.java | 2 +- src/main/java/fr/cardon/simpleat/model/PreferencePK.java | 3 ++- src/main/resources/data.sql | 3 +++ 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java index 4e2ee3b..7a27fd8 100644 --- a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java +++ b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java @@ -75,7 +75,7 @@ public class PersonneController { } @GetMapping("/user/{id}") - @PreAuthorize("hasRole('ROLE_ADMIN')") + //@PreAuthorize("hasRole('ROLE_ADMIN')") public Personne findPersonneById(@PathVariable int id){ return personneRepository.findById(id); @@ -113,7 +113,7 @@ public class PersonneController { return roleRepository.findCollectionById(idRole); } - @PostMapping("/sign-in") + @PostMapping("/signin") public ResponseEntity signIn(@RequestBody Personne personne) { try { // ici on créé un JWT en passant l'email et le mot de passe diff --git a/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java b/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java index be17291..6891144 100644 --- a/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java +++ b/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java @@ -38,7 +38,7 @@ public class RestaurantController { } @PostMapping("/add-restaurant") - @PreAuthorize("hasRole('ROLE_ADMIN')") + //@PreAuthorize("hasRole('ROLE_ADMIN')") public ResponseEntity ajoutRestaurant(@RequestBody Restaurant personne){ return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne)); } diff --git a/src/main/java/fr/cardon/simpleat/model/Personne.java b/src/main/java/fr/cardon/simpleat/model/Personne.java index 425662f..3296515 100644 --- a/src/main/java/fr/cardon/simpleat/model/Personne.java +++ b/src/main/java/fr/cardon/simpleat/model/Personne.java @@ -148,7 +148,7 @@ public Personne(String email, String password, List roleList) { @OneToMany(mappedBy = "preferencePK.personne", cascade = CascadeType.REMOVE) - @JsonIgnore + //@JsonIgnore public Collection getPreference() { return preference; } diff --git a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java index ed364ae..953ddb2 100644 --- a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java +++ b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java @@ -10,6 +10,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.PrimaryKeyJoinColumn; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -39,7 +40,7 @@ public class PreferencePK implements Serializable { @ManyToOne @PrimaryKeyJoinColumn(name="id_personne", referencedColumnName ="id_personne" ) - @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) + @JsonIgnore public Personne getPersonne() { return personne; } diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 6126ca4..07cd1c8 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -12,6 +12,7 @@ insert into personne (nom, prenom, email, password) values ('Rinquin', 'Aline', insert into personne (nom, prenom, email, password) values ('Keddar', 'Noreddine', 'noredinne.keddar@gmail.com', 'ACdXxMr'); insert into personne (nom, prenom, email, password) values ('Tomczyk', 'Julian', 'julian.tomczyk@gmail.com', 'pjKxIN'); insert into personne (nom, prenom, email, password) values ('MJID', 'Hedi', 'hedi.mjid@gmail.com', 'YY0TuY6JH0di'); +insert into personne (nom, prenom, email, password) values ('BIDEN', 'Joe', 'joe@biden.fr', '$2a$10$NNfAnATNZf/MzIjrUFi5K.xqWizxv1Hil4/PyRAabKWK5DxsLPE6.'); insert into role (id_role, intitule) values (1, 'Admin'); insert into role (id_role, intitule) values (2, 'User'); @@ -75,6 +76,8 @@ insert into preference (restau_id_restau, personne_id_personne, note, favori) va insert into preference (restau_id_restau, personne_id_personne, note, favori) values (3, 3, 4, true); insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 3, 3, false); insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 8, 3, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (5, 15, 3, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (8, 15, 3, false); insert into type (id_type, libelle) values (1, 'Kebab'); insert into type (id_type, libelle) values (2, 'Supermarché'); From 1b0c6b29f8b56cb476092069a3cd34087ec74789 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 4 Mar 2022 11:20:20 +0100 Subject: [PATCH 32/35] ajout data.sql --- .../controller/PersonneController.java | 2 +- .../simpleat/security/JwtTokenProvider.java | 5 ++ src/main/resources/data.sql | 46 +++++++++++++------ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java index 7a27fd8..a7769dc 100644 --- a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java +++ b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java @@ -27,7 +27,7 @@ import fr.cardon.simpleat.repository.RoleRepository; import fr.cardon.simpleat.service.PersonneService; @RestController -@CrossOrigin("*") +@CrossOrigin("http://localhost:4200") public class PersonneController { diff --git a/src/main/java/fr/cardon/simpleat/security/JwtTokenProvider.java b/src/main/java/fr/cardon/simpleat/security/JwtTokenProvider.java index 2e39ba4..551d565 100644 --- a/src/main/java/fr/cardon/simpleat/security/JwtTokenProvider.java +++ b/src/main/java/fr/cardon/simpleat/security/JwtTokenProvider.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import fr.cardon.simpleat.exception.InvalidJWTException; import fr.cardon.simpleat.model.EnumRole; +import fr.cardon.simpleat.repository.PersonneRepository; import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtException; import io.jsonwebtoken.Jwts; @@ -43,6 +44,9 @@ public class JwtTokenProvider { @Autowired private UserDetailsService userDetailsService; + + @Autowired + private PersonneRepository personneRepository; /** * Cette méthode d'initialisation s'exécute avant le constructeur @@ -104,6 +108,7 @@ public class JwtTokenProvider { public String createToken(String email, List roleList){ Claims claims = Jwts.claims().setSubject(email); + claims.put("userId", personneRepository.findByEmail(email).get().getId()); claims.put("auth", roleList.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList())); System.out.println("claims = "+claims); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 3499c17..2549860 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,19 +1,37 @@ -insert into personne (nom, prenom, email, password) values ('Cardon', 'Thomas', 'thomas.cardon@gmail.com', 'pjKxIN'); -insert into personne (nom, prenom, email, password) values ('Ramiere', 'Vincent', 'vincent.ramiere@gmail.com', 'YY0TuY6JH0di'); -insert into personne (nom, prenom, email, password) values ('Verger', 'Romain', 'romain.verger@gmail.com', 'C4sfAW4'); -insert into personne (nom, prenom, email, password) values ('Ribardiere', 'Paul-Emmanuel', 'paul.ribardiere@gmail.com', 'ACdXxMr'); -insert into personne (nom, prenom, email, password) values ('Noris', 'William', 'william.noris@gmail.com', 'pjKxIN'); -insert into personne (nom, prenom, email, password) values ('Harmand', 'Isabelle', 'isabelle.harmand@gmail.com', 'YY0TuY6JH0di'); -insert into personne (nom, prenom, email, password) values ('Bajard', 'Blandine', 'blandine.bajard@gmail.com', 'C4sfAW4'); -insert into personne (nom, prenom, email, password) values ('El hiri', 'Sana', 'sana.el-hiri@gmail.com', 'ACdXxMr'); -insert into personne (nom, prenom, email, password) values ('Lucas', 'Cecile', 'cecile.lucas@gmail.com', 'pjKxIN'); -insert into personne (nom, prenom, email, password) values ('Kerkeb', 'Mohamed', 'mohamed.kerkeb@gmail.com', 'YY0TuY6JH0di'); -insert into personne (nom, prenom, email, password) values ('Rinquin', 'Aline', 'aline.rinquin@gmail.com', 'C4sfAW4'); -insert into personne (nom, prenom, email, password) values ('Keddar', 'Noreddine', 'noredinne.keddar@gmail.com', 'ACdXxMr'); -insert into personne (nom, prenom, email, password) values ('Tomczyk', 'Julian', 'julian.tomczyk@gmail.com', 'pjKxIN'); -insert into personne (nom, prenom, email, password) values ('MJID', 'Hedi', 'hedi.mjid@gmail.com', 'YY0TuY6JH0di'); +insert into personne (nom, prenom, email, password) values ('Cardon', 'Thomas', 'thomas.cardon@gmail.com', '$2a$10$724bLjLyGOEKTBbHy.s3C.ETc.HuBnhEoCOuoO7.Ts7kyPbz6hkme'); +insert into personne (nom, prenom, email, password) values ('Ramiere', 'Vincent', 'vincent.ramiere@gmail.com', '$2a$10$x6.VyO9PCMXSPsi5/m/Hze9xOP.IUdYbaye7cNFc.PfyuRuVLbG7e'); +insert into personne (nom, prenom, email, password) values ('Verger', 'Romain', 'romain.verger@gmail.com', '$2a$10$oe/h0ZDpi6xFmTj8CvDMDe13hoEGv0DhHziY7GUatbb9ETcRw/8RG'); +insert into personne (nom, prenom, email, password) values ('Ribardiere', 'Paul-Emmanuel', 'paul.ribardiere@gmail.com', '$2a$10$ArSe7TSUapTs9oGE8824fOv4PM6NJwu7mzcg72cSmHy0.ds585Oke'); +insert into personne (nom, prenom, email, password) values ('Noris', 'William', 'william.noris@gmail.com', '$2a$10$6UbvPYBR2Ql09M1kgK0.HuoX3X1gxScmaOxI242EB2U7cXiylX3z.'); +insert into personne (nom, prenom, email, password) values ('Harmand', 'Isabelle', 'isabelle.harmand@gmail.com', '$2a$10$at1EZABxNN32M5pCttV36OvzbUWx1myGisa36i3..vveO6j0Lk2Da'); +insert into personne (nom, prenom, email, password) values ('Bajard', 'Blandine', 'blandine.bajard@gmail.com', '$2a$10$koeHn0Wg54MTc7iDb9hbsujy/Opfrhhu0uuhhBNA00rMXLeMpSl.m'); +insert into personne (nom, prenom, email, password) values ('El Hiri', 'Sana', 'sana.el-hiri@gmail.com', '$2a$10$jBBk1RQrl5XOeSQYz3xdJ.Xl8hBIu/x3mqHpYyL10m6KjwfDsWGEW'); +insert into personne (nom, prenom, email, password) values ('Lucas', 'Cecile', 'cecile.lucas@gmail.com', '$2a$10$HAUg8vlmtvS/YphJzWAPfuGJdLd/3SeSZ48JVvybK6Wh/AY3QirGG'); +insert into personne (nom, prenom, email, password) values ('Kerkeb', 'Mohamed', 'mohamed.kerkeb@gmail.com', '$2a$10$BpWZMlDLKXA2qGMo9t6cxeS6G/6mvjdsdN4nIUOAjE2sr/0sJNiCW'); +insert into personne (nom, prenom, email, password) values ('Rinquin', 'Aline', 'aline.rinquin@gmail.com', '$2a$10$FJKDTcipj/8PKos7AcCnZ.HHAmdDh6EjknpUWPLDcVfSXWPcHZI5O'); +insert into personne (nom, prenom, email, password) values ('Keddar', 'Noreddine', 'noredinne.keddar@gmail.com', '$2a$10$5iowOIUv72hFVsT9B8K.nerA3YTPAyyUiqOAwKR55ZZcpiHT96LhG'); +insert into personne (nom, prenom, email, password) values ('Tomczyk', 'Julian', 'julian.tomczyk@gmail.com', '$2a$10$vJ89S5CXjtO01NsYrwfLyudU/p2Cz1QNDm1dGUkfKD60Z23HLZM2.'); +insert into personne (nom, prenom, email, password) values ('Mjid', 'Hedi', 'hedi.mjid@gmail.com', '$10$vJ89S5CXjtO01NsYrwfLyudU/p2Cz1QNDm1dGUkfKD60Z23HLZM2.'); insert into personne (nom, prenom, email, password) values ('BIDEN', 'Joe', 'joe@biden.fr', '$2a$10$NNfAnATNZf/MzIjrUFi5K.xqWizxv1Hil4/PyRAabKWK5DxsLPE6.'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (1,'ROLE_ADMIN'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (2,'ROLE_ADMIN'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (3,'ROLE_ADMIN'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (4,'ROLE_ADMIN'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (5,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (6,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (7,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (8,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (9,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (10,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (11,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (12,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (13,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (14,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_ADMIN'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_CREATOR'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_READER'); + insert into role (id_role, intitule) values (1, 'Admin'); insert into role (id_role, intitule) values (2, 'User'); From ced6a29d82450e7cdd0bb8332a1f2e6d06e433dd Mon Sep 17 00:00:00 2001 From: Vincent Ramiere Date: Fri, 4 Mar 2022 14:30:13 +0100 Subject: [PATCH 33/35] modif settings.gradle --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index c74741c..e76d701 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'simpleat' +rootProject.name = 'simpleat-back' From b9ad367ed358364dca2129140bf7aea63f9bf30f Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 9 Mar 2022 14:03:46 +0100 Subject: [PATCH 34/35] modif preferencePK + preferenceController --- settings.gradle | 2 +- .../simpleat/controller/PersonneController.java | 2 +- .../simpleat/controller/PreferenceController.java | 15 ++++++++++++--- .../simpleat/controller/RestaurantController.java | 2 +- .../java/fr/cardon/simpleat/model/Preference.java | 7 +++++++ .../fr/cardon/simpleat/model/PreferencePK.java | 3 ++- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/settings.gradle b/settings.gradle index e76d701..c74741c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'simpleat-back' +rootProject.name = 'simpleat' diff --git a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java index a7769dc..a20bf9f 100644 --- a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java +++ b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java @@ -125,7 +125,7 @@ public class PersonneController { } } - @PostMapping("/sign-up") + @PostMapping("/signup") public ResponseEntity signUp(@RequestBody Personne personne) { try { return ResponseEntity.ok(new JsonWebToken(personneService.signup(personne))); diff --git a/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java b/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java index b1659e7..e7d637f 100644 --- a/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java +++ b/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java @@ -49,8 +49,17 @@ public class PreferenceController { } - @PostMapping("/add-preference") - public ResponseEntity ajoutPreference(@RequestBody Preference preference){ +// @PostMapping("/add-preference") +// public ResponseEntity ajoutPreference(@RequestBody Preference preference){ +// System.out.println(preference); +// return ResponseEntity.status(HttpStatus.OK).body(preferenceRepository.save(preference)); +// } + + @PostMapping("/add-preference/{iduser}/{idrestau}") + public ResponseEntity ajoutPreference(@PathVariable int iduser, @PathVariable int idrestau ){ + System.out.println("hello"); + Preference preference = new Preference(new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau))); + return ResponseEntity.status(HttpStatus.OK).body(preferenceRepository.save(preference)); } @@ -60,7 +69,7 @@ public class PreferenceController { // return ResponseEntity.status(HttpStatus.OK).body(preferenceRepository.save(personne)); // } // - @DeleteMapping("/delete-preference/{idrestau}/{iduser}") + @DeleteMapping("/delete-preference/{iduser}/{idrestau}") public void deletePreferenceById(@PathVariable int iduser, @PathVariable int idrestau ){ PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau)); preferenceRepository.deleteById(id); diff --git a/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java b/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java index 6891144..94a320f 100644 --- a/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java +++ b/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java @@ -45,7 +45,7 @@ public class RestaurantController { @PutMapping(value = "/update-restaurant/{id}") - + @PreAuthorize("hasRole('ROLE_ADMIN')") public ResponseEntity modifRestaurant(@PathVariable int id, @RequestBody Restaurant personne){ return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne)); } diff --git a/src/main/java/fr/cardon/simpleat/model/Preference.java b/src/main/java/fr/cardon/simpleat/model/Preference.java index efab64c..ba10672 100644 --- a/src/main/java/fr/cardon/simpleat/model/Preference.java +++ b/src/main/java/fr/cardon/simpleat/model/Preference.java @@ -19,6 +19,13 @@ public class Preference { } + + + public Preference(PreferencePK preferencePK) { + super(); + this.preferencePK = preferencePK; + } + public Preference(PreferencePK preferencePK, int note, boolean favoris) { super(); this.preferencePK = preferencePK; diff --git a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java index 7db9135..65bb12c 100644 --- a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java +++ b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java @@ -10,6 +10,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.PrimaryKeyJoinColumn; +import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -40,7 +41,7 @@ public class PreferencePK implements Serializable { @ManyToOne @PrimaryKeyJoinColumn(name="id_personne", referencedColumnName ="id_personne" ) - @JsonIgnore + @JsonBackReference("personne") public Personne getPersonne() { return personne; } From b1e1952da83d0a17d408ca5bee682bb5bcfd469a Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 11 Mar 2022 14:34:22 +0100 Subject: [PATCH 35/35] Model Role OUT + data.sql a jour --- .../controller/PersonneController.java | 47 ++-- .../controller/PreferenceController.java | 5 + .../controller/RestaurantController.java | 5 +- .../controller/TypeRestauController.java | 7 + .../fr/cardon/simpleat/dto/PersonneDto.java | 19 -- .../fr/cardon/simpleat/model/EnumRole.java | 2 +- .../fr/cardon/simpleat/model/Personne.java | 27 -- .../java/fr/cardon/simpleat/model/Role.java | 41 ---- .../simpleat/repository/RoleRepository.java | 16 -- src/main/resources/{Postman => PostmanV2} | 80 +++++- src/main/resources/data.sql | 70 +++--- src/main/resources/script-simpleat.sql | 230 ++++++++++++++++++ 12 files changed, 373 insertions(+), 176 deletions(-) delete mode 100644 src/main/java/fr/cardon/simpleat/model/Role.java delete mode 100644 src/main/java/fr/cardon/simpleat/repository/RoleRepository.java rename src/main/resources/{Postman => PostmanV2} (85%) create mode 100644 src/main/resources/script-simpleat.sql diff --git a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java index a20bf9f..29a9c7d 100644 --- a/src/main/java/fr/cardon/simpleat/controller/PersonneController.java +++ b/src/main/java/fr/cardon/simpleat/controller/PersonneController.java @@ -21,9 +21,7 @@ import fr.cardon.simpleat.dto.JsonWebToken; import fr.cardon.simpleat.exception.ExistingUsernameException; import fr.cardon.simpleat.exception.InvalidCredentialsException; import fr.cardon.simpleat.model.Personne; -import fr.cardon.simpleat.model.Role; import fr.cardon.simpleat.repository.PersonneRepository; -import fr.cardon.simpleat.repository.RoleRepository; import fr.cardon.simpleat.service.PersonneService; @RestController @@ -34,9 +32,6 @@ public class PersonneController { @Autowired private PersonneRepository personneRepository; - @Autowired - private RoleRepository roleRepository; - @Autowired private PersonneService personneService; @@ -51,7 +46,6 @@ public class PersonneController { p1.setPrenom("pouet"); p1.setEmail("pouetcoco@gmail.com"); p1.setPassword("hjfdzov"); - p1.setRoles(findRoleById(2)); //ajoutPersonne(p1); @@ -68,27 +62,28 @@ public class PersonneController { @GetMapping("/users") - //@PreAuthorize("hasRole('ROLE_ADMIN')") + @PreAuthorize("hasRole('ROLE_ADMIN')") public Collection findAll(){ return personneRepository.findAll(); } @GetMapping("/user/{id}") - //@PreAuthorize("hasRole('ROLE_ADMIN')") + @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_READER')") public Personne findPersonneById(@PathVariable int id){ return personneRepository.findById(id); } - @PostMapping("/add-user") - //@PreAuthorize("hasRole('ROLE_ADMIN')") - public ResponseEntity ajoutPersonne(@RequestBody Personne personne){ - return ResponseEntity.status(HttpStatus.OK).body(personneRepository.save(personne)); - } +// @PostMapping("/add-user") +// @PreAuthorize("hasRole('ROLE_ADMIN')") +// public ResponseEntity ajoutPersonne(@RequestBody Personne personne){ +// return ResponseEntity.status(HttpStatus.OK).body(personneRepository.save(personne)); +// } @PutMapping(value = "/update-user/{id}") + @PreAuthorize("hasRole('ROLE_ADMIN')") public ResponseEntity modifPerso(@PathVariable int id, @RequestBody Personne personne){ // Personne persoAModif= null; @@ -101,6 +96,7 @@ public class PersonneController { } @DeleteMapping(value = "/delete-user/{id}") + @PreAuthorize("hasRole('ROLE_ADMIN')") public void suppressionPerso(@PathVariable int id){ // Personne persoASuppr= new Personne(); // persoASuppr = findById(id); @@ -109,23 +105,20 @@ public class PersonneController { } - public Collection findRoleById(int idRole){ - return roleRepository.findCollectionById(idRole); - } - @PostMapping("/signin") - public ResponseEntity signIn(@RequestBody Personne personne) { - try { - // ici on créé un JWT en passant l'email et le mot de passe - // récupéré de l'objet user passé en paramètre. - return ResponseEntity.ok(new JsonWebToken(personneService.signin(personne.getEmail(), personne.getPassword()))); - } catch (InvalidCredentialsException ex) { - // on renvoie une réponse négative - return ResponseEntity.badRequest().build(); - } - } + public ResponseEntity signIn(@RequestBody Personne personne) { + try { + // ici on créé un JWT en passant l'email et le mot de passe + // récupéré de l'objet user passé en paramètre. + return ResponseEntity.ok(new JsonWebToken(personneService.signin(personne.getEmail(), personne.getPassword()))); + } catch (InvalidCredentialsException ex) { + // on renvoie une réponse négative + return ResponseEntity.badRequest().build(); + } + } @PostMapping("/signup") + @PreAuthorize("hasRole('ROLE_ADMIN')") public ResponseEntity signUp(@RequestBody Personne personne) { try { return ResponseEntity.ok(new JsonWebToken(personneService.signup(personne))); diff --git a/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java b/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java index e7d637f..2869041 100644 --- a/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java +++ b/src/main/java/fr/cardon/simpleat/controller/PreferenceController.java @@ -6,6 +6,7 @@ import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -35,6 +36,7 @@ public class PreferenceController { private RestaurantRepository restaurantRepository; @GetMapping("/preferences") + @PreAuthorize("hasRole('ROLE_ADMIN')") public Collection findAll(){ return preferenceRepository.findAll(); @@ -42,6 +44,7 @@ public class PreferenceController { @GetMapping("/preference/{iduser}/{idrestau}") + @PreAuthorize("hasRole('ROLE_ADMIN')") public Optional findPreferenceById(@PathVariable int iduser, @PathVariable int idrestau ){ PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau)); System.out.println(iduser); @@ -56,6 +59,7 @@ public class PreferenceController { // } @PostMapping("/add-preference/{iduser}/{idrestau}") + @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_READER')") public ResponseEntity ajoutPreference(@PathVariable int iduser, @PathVariable int idrestau ){ System.out.println("hello"); Preference preference = new Preference(new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau))); @@ -70,6 +74,7 @@ public class PreferenceController { // } // @DeleteMapping("/delete-preference/{iduser}/{idrestau}") + @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_READER')") public void deletePreferenceById(@PathVariable int iduser, @PathVariable int idrestau ){ PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau)); preferenceRepository.deleteById(id); diff --git a/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java b/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java index 94a320f..65ec55b 100644 --- a/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java +++ b/src/main/java/fr/cardon/simpleat/controller/RestaurantController.java @@ -27,18 +27,20 @@ public class RestaurantController { private RestaurantRepository restaurantRepository; @GetMapping("/restaurants") + @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_READER')") public Collection findAll(){ return restaurantRepository.findAll(); } @GetMapping("/restaurant/{id}") + @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_READER')") public Restaurant findRestaurantById(@PathVariable int id){ return restaurantRepository.findById(id); } @PostMapping("/add-restaurant") - //@PreAuthorize("hasRole('ROLE_ADMIN')") + @PreAuthorize("hasRole('ROLE_ADMIN')") public ResponseEntity ajoutRestaurant(@RequestBody Restaurant personne){ return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne)); } @@ -51,6 +53,7 @@ public class RestaurantController { } @DeleteMapping(value = "/delete-restaurant/{id}") + @PreAuthorize("hasRole('ROLE_ADMIN')") public void suppressionRestaurant(@PathVariable int id){ restaurantRepository.deleteById(id); diff --git a/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java b/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java index 4aa388e..e44be43 100644 --- a/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java +++ b/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java @@ -7,6 +7,7 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -28,33 +29,39 @@ public class TypeRestauController { private TypeRestauRepository typeRestauRepository; @GetMapping("/types") + @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_READER')") public Collection findAll(){ return typeRestauRepository.findAll(); } @GetMapping("/type/{id}") + @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_READER')") public TypeRestau findTypetById(@PathVariable int id){ return typeRestauRepository.findById(id); } @GetMapping("/restaurantbytype/{id}") + @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_READER')") public List findRestauByType(@PathVariable int id){ return findTypetById(id).getRestaurants(); } @PostMapping("/add-type") + @PreAuthorize("hasRole('ROLE_ADMIN')") public ResponseEntity ajoutType(@RequestBody TypeRestau type){ return ResponseEntity.status(HttpStatus.OK).body(typeRestauRepository.save(type)); } @PutMapping(value = "/update-type/{id}") + @PreAuthorize("hasRole('ROLE_ADMIN')") public ResponseEntity modifType(@PathVariable int id, @RequestBody TypeRestau type){ return ResponseEntity.status(HttpStatus.OK).body(typeRestauRepository.save(type)); } @DeleteMapping(value = "/delete-type/{id}") + @PreAuthorize("hasRole('ROLE_ADMIN')") public void suppressionType(@PathVariable int id){ typeRestauRepository.deleteById(id); diff --git a/src/main/java/fr/cardon/simpleat/dto/PersonneDto.java b/src/main/java/fr/cardon/simpleat/dto/PersonneDto.java index c078b59..7c68180 100644 --- a/src/main/java/fr/cardon/simpleat/dto/PersonneDto.java +++ b/src/main/java/fr/cardon/simpleat/dto/PersonneDto.java @@ -5,7 +5,6 @@ import java.util.List; import com.sun.istack.NotNull; -import fr.cardon.simpleat.model.Role; /** * Specifique : AppUser DTO permet de renvoyer un User sans le mot de passe (REST response). @@ -14,18 +13,9 @@ public class PersonneDto { private Long id; private String email; - private List roleList; public PersonneDto() { } - public PersonneDto(@NotNull String email) { - this(email,null); - } - - public PersonneDto(@NotNull String email, List roleList) { - this.email = email; - this.roleList = roleList; - } public Long getId() { return id; @@ -43,13 +33,4 @@ public class PersonneDto { this.email = email; } - public List getRoleList() { - return roleList; - } - - public void setRoleList(List roleList) { - this.roleList = roleList; - } - - } diff --git a/src/main/java/fr/cardon/simpleat/model/EnumRole.java b/src/main/java/fr/cardon/simpleat/model/EnumRole.java index 29efe61..436033d 100644 --- a/src/main/java/fr/cardon/simpleat/model/EnumRole.java +++ b/src/main/java/fr/cardon/simpleat/model/EnumRole.java @@ -4,7 +4,7 @@ import org.springframework.security.core.GrantedAuthority; public enum EnumRole implements GrantedAuthority { - ROLE_ADMIN, ROLE_CREATOR, ROLE_READER; + ROLE_ADMIN, ROLE_READER; @Override public String getAuthority() { diff --git a/src/main/java/fr/cardon/simpleat/model/Personne.java b/src/main/java/fr/cardon/simpleat/model/Personne.java index 57b4999..7d2ed29 100644 --- a/src/main/java/fr/cardon/simpleat/model/Personne.java +++ b/src/main/java/fr/cardon/simpleat/model/Personne.java @@ -33,7 +33,6 @@ public class Personne { private String prenom; private String email; private String password; - private Collection roles = new ArrayList(); private Collection preference = new ArrayList(); private List roleList; @@ -77,19 +76,6 @@ public Personne(String email, String password, List roleList) { } - public Personne(String nom, String prenom, String email, String password, - Collection roles, Collection preference, - List roleList) { - super(); - this.nom = nom; - this.prenom = prenom; - this.email = email; - this.password = password; - this.roles = roles; - this.preference = preference; - this.roleList = roleList; - } - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -132,19 +118,6 @@ public Personne(String email, String password, List roleList) { public void setPassword(String password) { this.password = password; } - - @ManyToMany - @JoinTable(name="role_personne", - joinColumns = @JoinColumn(name = "id_perso"/*nom créé dans table asso*/,referencedColumnName = "id_personne" /*classe en cours*/) ) - @JsonIgnoreProperties("roles") - public Collection getRoles() { - return roles; - } - - - public void setRoles(Collection roles) { - this.roles = roles; - } @OneToMany(mappedBy = "preferencePK.personne", cascade = CascadeType.REMOVE) diff --git a/src/main/java/fr/cardon/simpleat/model/Role.java b/src/main/java/fr/cardon/simpleat/model/Role.java deleted file mode 100644 index 2d012ce..0000000 --- a/src/main/java/fr/cardon/simpleat/model/Role.java +++ /dev/null @@ -1,41 +0,0 @@ -package fr.cardon.simpleat.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -public class Role { - - private int id; - private String intitule; - - - public Role() { - super(); - // TODO Auto-generated constructor stub - } - - public Role(int id, String intitule) { - super(); - this.id = id; - this.intitule = intitule; - } - - @Id - @Column(name = "id_role") - public int getId() { - return id; - } - public void setId(int id) { - this.id = id; - } - @Column(nullable = false) - public String getIntitule() { - return intitule; - } - public void setIntitule(String intitule) { - this.intitule = intitule; - } - -} diff --git a/src/main/java/fr/cardon/simpleat/repository/RoleRepository.java b/src/main/java/fr/cardon/simpleat/repository/RoleRepository.java deleted file mode 100644 index 6172577..0000000 --- a/src/main/java/fr/cardon/simpleat/repository/RoleRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package fr.cardon.simpleat.repository; - -import java.util.Collection; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import fr.cardon.simpleat.model.Role; - -@Repository -public interface RoleRepository extends JpaRepository { - - - Collection findCollectionById(int id); - -} diff --git a/src/main/resources/Postman b/src/main/resources/PostmanV2 similarity index 85% rename from src/main/resources/Postman rename to src/main/resources/PostmanV2 index a222d5a..8f1d50c 100644 --- a/src/main/resources/Postman +++ b/src/main/resources/PostmanV2 @@ -77,7 +77,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"nom\": \"nouvel\",\r\n \"prenom\": \"ajout\",\r\n \"email\": \"role@ajout.fr\",\r\n \"password\": \"root\",\r\n \"roles\": [\r\n {\r\n \"id\": 2\r\n }\r\n ]\r\n}", + "raw": "{\r\n \"nom\": \"Cardon\",\r\n \"prenom\": \"Thomas\",\r\n \"email\": \"thomas.cardon@gmail.com\",\r\n \"password\": \"SimplonTC\",\r\n \"roleList\": [\"ROLE_ADMIN\"]\r\n \r\n}", "options": { "raw": { "language": "json" @@ -145,6 +145,60 @@ } }, "response": [] + }, + { + "name": "Sign-up", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"nom\": \"Cardon\",\r\n \"prenom\": \"Thomas\",\r\n \"email\": \"thomas.cardon@gmail.com\",\r\n \"password\": \"SimplonTC\",\r\n \"roleList\": [\"ROLE_ADMIN\"]\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/sign-up", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "sign-up" + ] + } + }, + "response": [] + }, + { + "name": "Sign-in", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"email\": \"thomas.cardon@gmail.com\",\r\n \"password\": \"SimplonTC\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8080/signin", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "signin" + ] + } + }, + "response": [] } ] }, @@ -208,7 +262,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"personne\": {\r\n \"id\": 1\r\n },\r\n \"restau\": {\r\n \"id\": 5\r\n },\r\n \"note\": 5,\r\n \"favoris\": true\r\n}", + "raw": "{\r\n \"preferencePK\":{\r\n \"personne\": {\r\n \"id\": 1\r\n },\r\n \"restau\": {\r\n \"id\": 1\r\n }},\r\n \"note\": 5,\r\n \"favoris\": true\r\n}", "options": { "raw": { "language": "json" @@ -234,24 +288,24 @@ "method": "DELETE", "header": [], "url": { - "raw": "localhost:8080/delete-preference/:idrestau/:iduser", + "raw": "localhost:8080/delete-preference/:iduser/:idrestau", "host": [ "localhost" ], "port": "8080", "path": [ "delete-preference", - ":idrestau", - ":iduser" + ":iduser", + ":idrestau" ], "variable": [ - { - "key": "idrestau", - "value": "3" - }, { "key": "iduser", "value": "1" + }, + { + "key": "idrestau", + "value": null } ] } @@ -338,6 +392,14 @@ }, "response": [] }, + { + "name": "New Request", + "request": { + "method": "GET", + "header": [] + }, + "response": [] + }, { "name": "AjoutRestaurant", "request": { diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 2549860..88426d8 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -29,13 +29,9 @@ INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (12 INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (13,'ROLE_READER'); INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (14,'ROLE_READER'); INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_ADMIN'); -INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_CREATOR'); INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_READER'); -insert into role (id_role, intitule) values (1, 'Admin'); -insert into role (id_role, intitule) values (2, 'User'); - INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,1,'Le Jardin de Montreuil','1 Rue du Sergent Godefroy, 93100 Montreuil','01 41 63 92 66','http://www.lejardindemontreuil.fr/','48.853391599999995','2.4347358'); INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,0,'La CaVe','45 Rue de Paris, 93100 Montreuil','01 42 87 09 48','http://www.lacaveestrestaurant.com/','48.8576152','2.4342148999999997'); INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (3,0,1,1,'Villa 9 Trois','71 Rue Hoche, 93100 Montreuil','01 48 58 17 37','http://www.villa9trois.com/','48.8638352','2.4331966'); @@ -77,7 +73,18 @@ INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone, INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'La Brasserie des Laitières','38 Rue de Lagny, 93100 Montreuil','01 48 51 50 70','https://le-bl.metro.biz/','48.8490399','2.4262376999999997'); INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'LE HAVANE','248 Rue de Paris, 93100 Montreuil','01 48 57 17 23',NULL,'48.855091599999994','2.4187965'); INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Chez Carla','6 Rue Claude Bernard, 93100 Montreuil','01 48 18 00 53','http://www.chezcarla.fr/','48.8699343','2.4507599'); - +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'2 Bd Chanzy, 93100 Montreuil','48.85847716355682','2.4358987134859515','Le Sultan',1,1,'0148180475',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'19 Av. de la Résistance, 93100 Montreuil','48.85945630168561','2.436446504305728','Monoprix',1,0,'0141720580','monoprix.fr'); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,' 20, Avenue De La Resistance','48.859572881535506','2.43723868323233','Fournil du Perche',1,0,'',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'Place Jacques Duclot','48.85763987017326','2.4357752878301313','Street Wok',1,0,'',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,'18 Bd Rouget de Lisle, 93100 Montreuil','48.86127664908431','2.440266447738863','La Casa',2,1,'0187004594','www.lacasa-pizza.fr/'); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'31 Rue Franklin, 93100 Montreuil','48.86373425237411','2.444081609130601','New Kyoto',2,1,'0142877365','https://newkyoto93.fr/'); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'86 Bd Henri Barbusse, 93100 Montreuil','48.868535950518506','2.4415787173758625','Cosa C E Da Mangiare',2,1,'0148510777',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'8 Av. Walwein, 93100 Montreuil','48.86227215595597','2.443526611143298','Bamboo & Sum',2,1,'0987366393',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,'78 Av. de la Résistance, 93100 Montreuil','48.86260826926845','2.4370469579964404','O Bon Coin',1,1,'0953523586',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,'14 Rue du Capitaine Dreyfus, 93100 Montreuil','48.85828992238344','2.437848545198565','Kashmir Café',2,1,'0143633386','http://www.kashmircafe.fr/'); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,'45 Bd Paul Vaillant Couturier, 93100 Montreuil','48.86615467929139','2.4442899980905284','Le Marrakech',3,1,'0148589402',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,'7 Bd Rouget de Lisle, 93100 Montreuil','48.86133951184523','2.4407883330629856','BOLKIRI Montreuil Street Food Viêt',2,1,'0184671708','http://bolkiri.fr/'); @@ -107,44 +114,37 @@ insert into type (id_type, libelle) values (6, 'Pizza'); insert into type (id_type, libelle) values (7, 'Brasserie'); insert into type (id_type, libelle) values (8, 'Americain'); insert into type (id_type, libelle) values (9, 'Japonais'); -insert into type (id_type, libelle) values (10, 'Asiatique'); insert into type (id_type, libelle) values (11, 'Italien'); -insert into type (id_type, libelle) values (12, 'Sushis'); insert into type (id_type, libelle) values (13, 'Chinois'); -insert into type (id_type, libelle) values (14, 'Crêperie'); insert into type (id_type, libelle) values (15, 'Hamburger'); insert into type (id_type, libelle) values (16, 'Indien'); insert into type (id_type, libelle) values (17, 'Marocain'); -insert into type (id_type, libelle) values (18, 'Fruits de Mer'); -insert into type (id_type, libelle) values (19, 'Steack'); insert into type (id_type, libelle) values (20, 'Vietnamien'); insert into type (id_type, libelle) values (21, 'Bistrot'); insert into type (id_type, libelle) values (22, 'Poulet'); -insert into type_restau (id_restau, id_type) values (1, 5); -insert into type_restau (id_restau, id_type) values (2, 5); -insert into type_restau (id_restau, id_type) values (3, 5); -insert into type_restau (id_restau, id_type) values (4, 5); -insert into type_restau (id_restau, id_type) values (5, 5); -insert into type_restau (id_restau, id_type) values (6, 8); -insert into type_restau (id_restau, id_type) values (6, 22); -insert into type_restau (id_restau, id_type) values (7, 7); -insert into type_restau (id_restau, id_type) values (8, 5); -insert into type_restau (id_restau, id_type) values (9, 21); -insert into type_restau (id_restau, id_type) values (10, 7); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (1,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (2,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (3,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (4,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (5,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (6,8); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (6,22); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (7,7); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (8,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (9,21); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (10,7); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (42,1); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (43,2); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (44,3); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (45,4); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (46,6); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (47,9); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (48,11); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (49,13); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (50,15); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (51,16); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (52,17); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (53,20); -insert into role_personne (id_perso, roles_id_role) values (1, 1); -insert into role_personne (id_perso, roles_id_role) values (2, 1); -insert into role_personne (id_perso, roles_id_role) values (3, 1); -insert into role_personne (id_perso, roles_id_role) values (4, 1); -insert into role_personne (id_perso, roles_id_role) values (5, 2); -insert into role_personne (id_perso, roles_id_role) values (6, 2); -insert into role_personne (id_perso, roles_id_role) values (7, 2); -insert into role_personne (id_perso, roles_id_role) values (8, 2); -insert into role_personne (id_perso, roles_id_role) values (9, 2); -insert into role_personne (id_perso, roles_id_role) values (10, 2); -insert into role_personne (id_perso, roles_id_role) values (11, 2); -insert into role_personne (id_perso, roles_id_role) values (12, 2); -insert into role_personne (id_perso, roles_id_role) values (13, 2); -insert into role_personne (id_perso, roles_id_role) values (14, 2); diff --git a/src/main/resources/script-simpleat.sql b/src/main/resources/script-simpleat.sql new file mode 100644 index 0000000..1066505 --- /dev/null +++ b/src/main/resources/script-simpleat.sql @@ -0,0 +1,230 @@ +DROP SCHEMA IF EXISTS `simpleat`; + +CREATE SCHEMA IF NOT EXISTS `simpleat` DEFAULT CHARACTER SET utf8mb4 ; +USE `simpleat` ; + +CREATE TABLE IF NOT EXISTS `simpleat`.`personne` ( + `id_personne` INT NOT NULL AUTO_INCREMENT, + `email` VARCHAR(255) NOT NULL, + `nom` VARCHAR(255) NOT NULL, + `password` VARCHAR(255) NOT NULL, + `prenom` VARCHAR(255) NOT NULL, + PRIMARY KEY (`id_personne`) +); + +CREATE TABLE IF NOT EXISTS `simpleat`.`personne_role_list` ( + `personne_id_personne` INT NOT NULL, + `role_list` VARCHAR(255) NULL DEFAULT NULL, + INDEX (`personne_id_personne`), + FOREIGN KEY (`personne_id_personne`) + REFERENCES `simpleat`.`personne` (`id_personne`) +); + +CREATE TABLE IF NOT EXISTS `simpleat`.`restaurant` ( + `id_restau` INT NOT NULL AUTO_INCREMENT, + `a_emporter` BOOLEAN NULL DEFAULT NULL, + `accespmr` BOOLEAN NULL DEFAULT NULL, + `adresse` VARCHAR(255) NOT NULL, + `latitude` VARCHAR(255) NOT NULL, + `longitude` VARCHAR(255) NOT NULL, + `nom` VARCHAR(255) NOT NULL, + `prix` INT NULL DEFAULT NULL, + `sur_place` BOOLEAN NULL DEFAULT NULL, + `telephone` VARCHAR(255) NULL DEFAULT NULL, + `website` VARCHAR(255) NULL DEFAULT NULL, + PRIMARY KEY (`id_restau`) +); + +CREATE TABLE IF NOT EXISTS `simpleat`.`preference` ( + `favori` BOOLEAN NULL DEFAULT NULL, + `note` INT NULL DEFAULT NULL, + `restau_id_restau` INT NOT NULL, + `personne_id_personne` INT NOT NULL, + PRIMARY KEY (`personne_id_personne`, `restau_id_restau`), + INDEX (`restau_id_restau`), + INDEX (`personne_id_personne`), + FOREIGN KEY (`restau_id_restau`) + REFERENCES `simpleat`.`restaurant` (`id_restau`), + FOREIGN KEY (`personne_id_personne`) + REFERENCES `simpleat`.`personne` (`id_personne`) +); + +CREATE TABLE IF NOT EXISTS `simpleat`.`reservation` ( + `date_resa` DATETIME NOT NULL, + `nb_personne` INT NOT NULL, + `id_restau` INT NOT NULL, + `id_personne` INT NOT NULL, + PRIMARY KEY (`date_resa`, `id_personne`, `id_restau`), + INDEX (`id_restau`), + INDEX (`id_personne`), + FOREIGN KEY (`id_restau`) + REFERENCES `simpleat`.`restaurant` (`id_restau`), + FOREIGN KEY (`id_personne`) + REFERENCES `simpleat`.`personne` (`id_personne`) +); + +CREATE TABLE IF NOT EXISTS `simpleat`.`type` ( + `id_type` INT NOT NULL AUTO_INCREMENT, + `libelle` VARCHAR(255) NOT NULL, + PRIMARY KEY (`id_type`) +); + +CREATE TABLE IF NOT EXISTS `simpleat`.`type_restau` ( + `id_restau` INT NOT NULL, + `id_type` INT NOT NULL, + INDEX (`id_type`) , + INDEX (`id_restau` ) , + FOREIGN KEY (`id_type`) + REFERENCES `simpleat`.`type` (`id_type`), + FOREIGN KEY (`id_restau`) + REFERENCES `simpleat`.`restaurant` (`id_restau`) +); + +insert into personne (nom, prenom, email, password) values ('Cardon', 'Thomas', 'thomas.cardon@gmail.com', '$2a$10$724bLjLyGOEKTBbHy.s3C.ETc.HuBnhEoCOuoO7.Ts7kyPbz6hkme'); +insert into personne (nom, prenom, email, password) values ('Ramiere', 'Vincent', 'vincent.ramiere@gmail.com', '$2a$10$x6.VyO9PCMXSPsi5/m/Hze9xOP.IUdYbaye7cNFc.PfyuRuVLbG7e'); +insert into personne (nom, prenom, email, password) values ('Verger', 'Romain', 'romain.verger@gmail.com', '$2a$10$oe/h0ZDpi6xFmTj8CvDMDe13hoEGv0DhHziY7GUatbb9ETcRw/8RG'); +insert into personne (nom, prenom, email, password) values ('Ribardiere', 'Paul-Emmanuel', 'paul.ribardiere@gmail.com', '$2a$10$ArSe7TSUapTs9oGE8824fOv4PM6NJwu7mzcg72cSmHy0.ds585Oke'); +insert into personne (nom, prenom, email, password) values ('Noris', 'William', 'william.noris@gmail.com', '$2a$10$6UbvPYBR2Ql09M1kgK0.HuoX3X1gxScmaOxI242EB2U7cXiylX3z.'); +insert into personne (nom, prenom, email, password) values ('Harmand', 'Isabelle', 'isabelle.harmand@gmail.com', '$2a$10$at1EZABxNN32M5pCttV36OvzbUWx1myGisa36i3..vveO6j0Lk2Da'); +insert into personne (nom, prenom, email, password) values ('Bajard', 'Blandine', 'blandine.bajard@gmail.com', '$2a$10$koeHn0Wg54MTc7iDb9hbsujy/Opfrhhu0uuhhBNA00rMXLeMpSl.m'); +insert into personne (nom, prenom, email, password) values ('El Hiri', 'Sana', 'sana.el-hiri@gmail.com', '$2a$10$jBBk1RQrl5XOeSQYz3xdJ.Xl8hBIu/x3mqHpYyL10m6KjwfDsWGEW'); +insert into personne (nom, prenom, email, password) values ('Lucas', 'Cecile', 'cecile.lucas@gmail.com', '$2a$10$HAUg8vlmtvS/YphJzWAPfuGJdLd/3SeSZ48JVvybK6Wh/AY3QirGG'); +insert into personne (nom, prenom, email, password) values ('Kerkeb', 'Mohamed', 'mohamed.kerkeb@gmail.com', '$2a$10$BpWZMlDLKXA2qGMo9t6cxeS6G/6mvjdsdN4nIUOAjE2sr/0sJNiCW'); +insert into personne (nom, prenom, email, password) values ('Rinquin', 'Aline', 'aline.rinquin@gmail.com', '$2a$10$FJKDTcipj/8PKos7AcCnZ.HHAmdDh6EjknpUWPLDcVfSXWPcHZI5O'); +insert into personne (nom, prenom, email, password) values ('Keddar', 'Noreddine', 'noredinne.keddar@gmail.com', '$2a$10$5iowOIUv72hFVsT9B8K.nerA3YTPAyyUiqOAwKR55ZZcpiHT96LhG'); +insert into personne (nom, prenom, email, password) values ('Tomczyk', 'Julian', 'julian.tomczyk@gmail.com', '$2a$10$vJ89S5CXjtO01NsYrwfLyudU/p2Cz1QNDm1dGUkfKD60Z23HLZM2.'); +insert into personne (nom, prenom, email, password) values ('Mjid', 'Hedi', 'hedi.mjid@gmail.com', '$10$vJ89S5CXjtO01NsYrwfLyudU/p2Cz1QNDm1dGUkfKD60Z23HLZM2.'); +insert into personne (nom, prenom, email, password) values ('BIDEN', 'Joe', 'joe@biden.fr', '$2a$10$NNfAnATNZf/MzIjrUFi5K.xqWizxv1Hil4/PyRAabKWK5DxsLPE6.'); + +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (1,'ROLE_ADMIN'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (2,'ROLE_ADMIN'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (3,'ROLE_ADMIN'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (4,'ROLE_ADMIN'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (5,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (6,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (7,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (8,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (9,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (10,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (11,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (12,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (13,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (14,'ROLE_READER'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_ADMIN'); +INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_READER'); + + +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,1,'Le Jardin de Montreuil','1 Rue du Sergent Godefroy, 93100 Montreuil','01 41 63 92 66','http://www.lejardindemontreuil.fr/','48.853391599999995','2.4347358'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,0,'La CaVe','45 Rue de Paris, 93100 Montreuil','01 42 87 09 48','http://www.lacaveestrestaurant.com/','48.8576152','2.4342148999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (3,0,1,1,'Villa 9 Trois','71 Rue Hoche, 93100 Montreuil','01 48 58 17 37','http://www.villa9trois.com/','48.8638352','2.4331966'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'L''Amourette','54 Rue Robespierre, 93100 Montreuil','01 48 59 99 94','http://www.lamourette.fr/','48.853121599999994','2.4234494'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'La Maison Montreuil','31 Rue du Capitaine Dreyfus, 93100 Montreuil','09 87 18 18 81','https://www.lamaisonmontreuil.com/','48.859359700000006','2.4399254999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'le poulet en feu','63 Rue Danton, 93100 Montreuil','09 87 51 10 90','https://www.pouletenfeu.fr/','48.8653553','2.4514297'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,1,'Les Tonneaux','62 Rue Robespierre, 93100 Montreuil','01 48 58 95 01',NULL,'48.85205','2.4238472'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Les Pianos','26 Rue Robespierre, 93100 Montreuil','09 63 53 85 17','https://www.facebook.com/lespianosmontreuilofficiel/','48.854841799999996','2.4230319'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,1,'M I M','113 Rue Marceau, 93100 Montreuil','01 43 63 31 13',NULL,'48.849849999999996','2.4265312999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'Le Gévaudan','1 Bd Rouget de Lisle, 93100 Montreuil','01 42 87 42 83',NULL,'48.8617445','2.4412374'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Restaurant Filippo','6 Bd Chanzy, 93100 Montreuil','01 48 18 08 16',NULL,'48.8583964','2.4349743'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,0,1,1,'Le Mange Disc','50 Rue de Romainville, 93100 Montreuil','09 83 54 60 27','https://m.facebook.com/Le-Mange-Disc-102557926519195/?locale2=fr_FR','48.8658457','2.4466363'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,NULL,'Restaurant El Kahina','227 Rue de Paris, 93100 Montreuil','01 48 70 95 46',NULL,'48.8550124','2.4195686'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (NULL,1,1,1,'La Baraka','262 Rue de Paris, 93100 Montreuil','01 42 87 19 27','http://www.labarakamontreuil.fr/?lang=fr','48.8549268','2.4177603999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'La Bottega Della Pizza','34 Bd Rouget de Lisle, 93100 Montreuil','01 43 63 04 35','http://www.labottegadellapizza.fr/','48.860204200000005','2.4387626'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,NULL,'Restaurant de la Paix','11 Rue Armand Carrel, 93100 Montreuil','01 73 55 21 72',NULL,'48.853764','2.4177003999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'La Fontaine Bar Restaurant','47 Rue Armand Carrel, 93100 Montreuil','01 48 70 08 84','https://www.facebook.com/pages/la-fontaine-de-montreuil-Restaurant/213852528659590?fref=ts','48.8512132','2.4183881'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (3,1,1,NULL,'La Cantine Arkose Montreuil','33 Rue du Progrès, 93100 Montreuil','01 49 88 45 07','https://lacantine.arkose.com/montreuil/','48.8516335','2.419278'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (3,1,1,NULL,'Kashmir Café.','14 Rue du Capitaine Dreyfus, 93100 Montreuil','01 43 63 33 86','http://www.kashmircafe.fr/','48.8582843','2.4378471999999998'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'W Lounge','37 Rue de Valmy, 93100 Montreuil','01 48 37 61 17','http://wlounge-montreuil.com/?utm_source=gmb&utm_medium=referral','48.8507208','2.4187186'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'L''Oasis','171 Rue de Paris, 93100 Montreuil','01 48 70 70 52','https://loasis-montreuil.fr/fr','48.855555599999995','2.4230556'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Obrigado','8 Av. de la Prte de Montreuil, 75020 Paris','09 84 58 24 21','http://obrigado.paris/','48.8534995','2.4118692'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Le Xanthos','30 Rue du Capitaine Dreyfus, 93100 Montreuil','01 55 86 26 77',NULL,'48.858785','2.4388468999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Thé Vert','43 Rue du Capitaine Dreyfus, 93100 Montreuil','01 42 87 79 57','http://www.thevertenligne.fr/','48.8596741','2.4405049'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Gramophone','1 Rue Pépin, 93100 Montreuil','01 49 88 74 56','http://www.restaurantlegramophone.com/','48.8641275','2.4449753'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,0,1,NULL,'La Grosse Mignonne','56 Rue Carnot, 93100 Montreuil','01 42 87 54 51','https://www.facebook.com/LaGrosseMignonne','48.855322','2.4413144'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,NULL,'La Galetiere','126 Rue de Paris, 93100 Montreuil','01 42 87 47 32','http://lagaletiere.eatbu.com/','48.8563999','2.4263293'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (3,1,1,1,'Le Mamaju','36 Rue de Lagny, 93100 Montreuil','01 83 74 02 26','https://mamaju-restaurant-montreuil.eatbu.com/','48.8490247','2.4265491'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'Le Pizzo','15 Rue du Capitaine Dreyfus, 93100 Montreuil','09 88 46 71 29',NULL,'48.8588721','2.4385882999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'L''Olivier','211 Rue de Paris, 93100 Montreuil','06 47 82 43 41',NULL,'48.855081','2.4203481'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Louise','27 Rue du Capitaine Dreyfus, 93100 Montreuil','06 75 32 56 81','https://instagram.com/cafelouisemontreuil?utm_medium=copy_link','48.859237','2.4394462'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'Ô Bar Lié','16 Rue de la République, 93100 Montreuil','01 48 58 71 95','http://www.obarlie.com/','48.8531155','2.4209562'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,NULL,'Gabycook','27 Rue du Progrès, 93100 Montreuil',NULL,NULL,'48.851772999999994','2.4202114'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'L''ALEMBERT','268 Rue de Paris, 93100 Montreuil','01 42 87 29 61','http://www.lalembert.fr/','48.8549126','2.4174881999999998'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'Gujarat','35 Bd Paul Vaillant Couturier, 93100 Montreuil','01 48 58 77 16','http://restaurantgujarat.fr/','48.865111','2.443053'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'L''effiloché Montreuil','5 Rue du Centenaire, 93100 Montreuil',NULL,NULL,'48.8579636','2.4270348'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'Famille-CMC','6 Av. Pasteur, 93100 Montreuil',NULL,NULL,'48.862999300000006','2.441328'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,NULL,'O''Villagio','28 Rue du Capitaine Dreyfus, 93100 Montreuil','01 57 42 63 82','https://ovillaggio93.wixsite.com/o-villaggio','48.858722','2.4386695'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'La Brasserie des Laitières','38 Rue de Lagny, 93100 Montreuil','01 48 51 50 70','https://le-bl.metro.biz/','48.8490399','2.4262376999999997'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (1,1,1,1,'LE HAVANE','248 Rue de Paris, 93100 Montreuil','01 48 57 17 23',NULL,'48.855091599999994','2.4187965'); +INSERT INTO restaurant(prix,a_emporter,sur_place,accespmr,nom,adresse,telephone,website,latitude,longitude) VALUES (2,1,1,1,'Chez Carla','6 Rue Claude Bernard, 93100 Montreuil','01 48 18 00 53','http://www.chezcarla.fr/','48.8699343','2.4507599'); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'2 Bd Chanzy, 93100 Montreuil','48.85847716355682','2.4358987134859515','Le Sultan',1,1,'0148180475',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'19 Av. de la Résistance, 93100 Montreuil','48.85945630168561','2.436446504305728','Monoprix',1,0,'0141720580','monoprix.fr'); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,' 20, Avenue De La Resistance','48.859572881535506','2.43723868323233','Fournil du Perche',1,0,'',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'Place Jacques Duclot','48.85763987017326','2.4357752878301313','Street Wok',1,0,'',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,'18 Bd Rouget de Lisle, 93100 Montreuil','48.86127664908431','2.440266447738863','La Casa',2,1,'0187004594','www.lacasa-pizza.fr/'); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'31 Rue Franklin, 93100 Montreuil','48.86373425237411','2.444081609130601','New Kyoto',2,1,'0142877365','https://newkyoto93.fr/'); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'86 Bd Henri Barbusse, 93100 Montreuil','48.868535950518506','2.4415787173758625','Cosa C E Da Mangiare',2,1,'0148510777',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,1,'8 Av. Walwein, 93100 Montreuil','48.86227215595597','2.443526611143298','Bamboo & Sum',2,1,'0987366393',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,'78 Av. de la Résistance, 93100 Montreuil','48.86260826926845','2.4370469579964404','O Bon Coin',1,1,'0953523586',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,'14 Rue du Capitaine Dreyfus, 93100 Montreuil','48.85828992238344','2.437848545198565','Kashmir Café',2,1,'0143633386','http://www.kashmircafe.fr/'); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,'45 Bd Paul Vaillant Couturier, 93100 Montreuil','48.86615467929139','2.4442899980905284','Le Marrakech',3,1,'0148589402',''); +INSERT INTO restaurant (`a_emporter`,`accespmr`,`adresse`,`latitude`,`longitude`,`nom`,`prix`,`sur_place`,`telephone`,`website`) VALUES (1,NULL,'7 Bd Rouget de Lisle, 93100 Montreuil','48.86133951184523','2.4407883330629856','BOLKIRI Montreuil Street Food Viêt',2,1,'0184671708','http://bolkiri.fr/'); + + + +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 9, 1, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (3, 1, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 9, 3, true); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (4, 6, 2, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (5, 5, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 10, 1, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (5, 3, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 7, 1, true); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (4, 2, 1, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 3, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (3, 10, 4, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (3, 3, 4, true); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 3, 3, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 8, 3, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (5, 15, 3, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (8, 15, 3, false); + +insert into type (id_type, libelle) values (1, 'Kebab'); +insert into type (id_type, libelle) values (2, 'Supermarché'); +insert into type (id_type, libelle) values (3, 'Boulangerie'); +insert into type (id_type, libelle) values (4, 'Thaï'); +insert into type (id_type, libelle) values (5, 'Français'); +insert into type (id_type, libelle) values (6, 'Pizza'); +insert into type (id_type, libelle) values (7, 'Brasserie'); +insert into type (id_type, libelle) values (8, 'Americain'); +insert into type (id_type, libelle) values (9, 'Japonais'); +insert into type (id_type, libelle) values (11, 'Italien'); +insert into type (id_type, libelle) values (13, 'Chinois'); +insert into type (id_type, libelle) values (15, 'Hamburger'); +insert into type (id_type, libelle) values (16, 'Indien'); +insert into type (id_type, libelle) values (17, 'Marocain'); +insert into type (id_type, libelle) values (20, 'Vietnamien'); +insert into type (id_type, libelle) values (21, 'Bistrot'); +insert into type (id_type, libelle) values (22, 'Poulet'); + +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (1,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (2,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (3,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (4,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (5,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (6,8); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (6,22); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (7,7); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (8,5); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (9,21); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (10,7); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (42,1); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (43,2); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (44,3); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (45,4); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (46,6); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (47,9); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (48,11); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (49,13); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (50,15); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (51,16); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (52,17); +INSERT INTO type_restau (`id_restau`,`id_type`) VALUES (53,20);