From b9ad367ed358364dca2129140bf7aea63f9bf30f Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 9 Mar 2022 14:03:46 +0100 Subject: [PATCH] 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; }