From 656899ea4c43f7f0d47686aa8841f5ed9c2a7a4f Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 2 Mar 2022 14:05:02 +0100 Subject: [PATCH] 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é');