modif preferencePK + preferenceController

This commit is contained in:
Thomas Cardon 2022-03-09 14:03:46 +01:00
parent ced6a29d82
commit b9ad367ed3
6 changed files with 24 additions and 7 deletions

View File

@ -1 +1 @@
rootProject.name = 'simpleat-back' rootProject.name = 'simpleat'

View File

@ -125,7 +125,7 @@ public class PersonneController {
} }
} }
@PostMapping("/sign-up") @PostMapping("/signup")
public ResponseEntity<JsonWebToken> signUp(@RequestBody Personne personne) { public ResponseEntity<JsonWebToken> signUp(@RequestBody Personne personne) {
try { try {
return ResponseEntity.ok(new JsonWebToken(personneService.signup(personne))); return ResponseEntity.ok(new JsonWebToken(personneService.signup(personne)));

View File

@ -49,8 +49,17 @@ public class PreferenceController {
} }
@PostMapping("/add-preference") // @PostMapping("/add-preference")
public ResponseEntity<?> ajoutPreference(@RequestBody Preference 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)); 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)); // 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 ){ public void deletePreferenceById(@PathVariable int iduser, @PathVariable int idrestau ){
PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau)); PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau));
preferenceRepository.deleteById(id); preferenceRepository.deleteById(id);

View File

@ -45,7 +45,7 @@ public class RestaurantController {
@PutMapping(value = "/update-restaurant/{id}") @PutMapping(value = "/update-restaurant/{id}")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<?> modifRestaurant(@PathVariable int id, @RequestBody Restaurant personne){ public ResponseEntity<?> modifRestaurant(@PathVariable int id, @RequestBody Restaurant personne){
return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne)); return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne));
} }

View File

@ -19,6 +19,13 @@ public class Preference {
} }
public Preference(PreferencePK preferencePK) {
super();
this.preferencePK = preferencePK;
}
public Preference(PreferencePK preferencePK, int note, boolean favoris) { public Preference(PreferencePK preferencePK, int note, boolean favoris) {
super(); super();
this.preferencePK = preferencePK; this.preferencePK = preferencePK;

View File

@ -10,6 +10,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.PrimaryKeyJoinColumn;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@ -40,7 +41,7 @@ public class PreferencePK implements Serializable {
@ManyToOne @ManyToOne
@PrimaryKeyJoinColumn(name="id_personne", referencedColumnName ="id_personne" ) @PrimaryKeyJoinColumn(name="id_personne", referencedColumnName ="id_personne" )
@JsonIgnore @JsonBackReference("personne")
public Personne getPersonne() { public Personne getPersonne() {
return personne; return personne;
} }