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; }