From 36b96e8170cf61d9826c62c479db5e384b2d0633 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 19 Jan 2022 15:49:07 +0100 Subject: [PATCH 1/9] 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 2/9] 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 3/9] 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 4/9] 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 5/9] 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 786d8b23d9a438a8a56a058812df54a55d99a22a Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 21 Jan 2022 20:04:05 +0100 Subject: [PATCH 6/9] 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 39c546794c4b23b017943f973b7a557031a5a711 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Tue, 25 Jan 2022 11:38:20 +0100 Subject: [PATCH 7/9] 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 8/9] 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 9/9] 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