fix des class pour eviter la recursivité de certain en json

This commit is contained in:
Hedi 2022-01-30 19:15:01 +01:00
parent c383149822
commit aece88e2a8
6 changed files with 22 additions and 11 deletions

View File

@ -21,7 +21,7 @@ public class ContactController {
private ContactRepository contactRepo; private ContactRepository contactRepo;
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')") //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> findById(@PathVariable int id){ public ResponseEntity<?> findById(@PathVariable int id){
Optional<Contact> contact = null; Optional<Contact> contact = null;
try try
@ -35,7 +35,7 @@ public class ContactController {
} }
@GetMapping(value = "team/{team_id}") @GetMapping(value = "team/{team_id}")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')") //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> findByTeamId(@PathVariable int team_id){ public ResponseEntity<?> findByTeamId(@PathVariable int team_id){
List<Contact> contacts = null; List<Contact> contacts = null;
try try
@ -49,7 +49,7 @@ public class ContactController {
} }
@PostMapping(value="/add") @PostMapping(value="/add")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')") //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> addContact(@RequestBody Contact contact){ public ResponseEntity<?> addContact(@RequestBody Contact contact){
Contact resultContact = null; Contact resultContact = null;
try { try {
@ -62,7 +62,7 @@ public class ContactController {
} }
@PutMapping("/update/{id}") @PutMapping("/update/{id}")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')") //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> updateContact(@RequestBody Contact contact, @PathVariable Integer id) throws Exception { public ResponseEntity<?> updateContact(@RequestBody Contact contact, @PathVariable Integer id) throws Exception {
Contact resultContact = null; Contact resultContact = null;
try { try {
@ -76,7 +76,7 @@ public class ContactController {
} }
@DeleteMapping(value = "/delete/{id}") @DeleteMapping(value = "/delete/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')") //@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> deleteContact(@PathVariable int id){ public ResponseEntity<?> deleteContact(@PathVariable int id){
try { try {
contactRepo.delete(contactRepo.getById(id)); contactRepo.delete(contactRepo.getById(id));

View File

@ -1,5 +1,6 @@
package fr.organizee.model; package fr.organizee.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*; import javax.persistence.*;
@ -18,7 +19,7 @@ public class Contact {
private LocalDate dateNaissance; private LocalDate dateNaissance;
@ManyToOne @ManyToOne
@JoinColumn(name="TEAM_ID") @JoinColumn(name="TEAM_ID")
@JsonIgnoreProperties("contact") @JsonIgnoreProperties({"contact","membre"})
private Team team; private Team team;
public Contact() { public Contact() {

View File

@ -1,5 +1,6 @@
package fr.organizee.model; package fr.organizee.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*; import javax.persistence.*;
@ -14,13 +15,13 @@ public class Evenement {
private LocalDateTime eventFin; private LocalDateTime eventFin;
private int allDay; private int allDay;
private String libelle; private String libelle;
@ManyToOne(cascade = CascadeType.MERGE) @ManyToOne
@JoinColumn(name="MEMBRE_ID") @JoinColumn(name="MEMBRE_ID")
@JsonIgnoreProperties("evenement") @JsonIgnoreProperties("evenement")
private Membre membre; private Membre membre;
@ManyToOne(cascade = CascadeType.MERGE) @ManyToOne
@JoinColumn(name="TEAM_ID") @JoinColumn(name="TEAM_ID")
@JsonIgnoreProperties("evenement") @JsonIgnoreProperties({"evenement", "membre"})
private Team team; private Team team;
public Evenement() { public Evenement() {

View File

@ -15,7 +15,7 @@ public class Menu {
private int validationProposition; private int validationProposition;
@ManyToOne @ManyToOne
@JoinColumn(name="TEAM_ID") @JoinColumn(name="TEAM_ID")
@JsonIgnoreProperties("menu") @JsonIgnoreProperties({"menu","membre"})
private Team team; private Team team;
public Menu() { public Menu() {

View File

@ -1,5 +1,6 @@
package fr.organizee.model; package fr.organizee.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*; import javax.persistence.*;
@ -12,17 +13,24 @@ public class Team {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private int id; private int id;
private String nom; private String nom;
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL) @OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonIgnoreProperties("team") @JsonIgnoreProperties("team")
private List<Membre> membres = new ArrayList<>(); private List<Membre> membres = new ArrayList<>();
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL) @OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonIgnoreProperties("team") @JsonIgnoreProperties("team")
@JsonIgnore
private List<Contact> contacts = new ArrayList<>(); private List<Contact> contacts = new ArrayList<>();
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL) @OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonIgnoreProperties("team") @JsonIgnoreProperties("team")
@JsonIgnore
private List<TodoList> todolists = new ArrayList<>(); private List<TodoList> todolists = new ArrayList<>();
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL) @OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonIgnoreProperties("team") @JsonIgnoreProperties("team")
@JsonIgnore
private List<Menu> menus = new ArrayList<>(); private List<Menu> menus = new ArrayList<>();
public Team() { public Team() {

View File

@ -1,5 +1,6 @@
package fr.organizee.model; package fr.organizee.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*; import javax.persistence.*;
@ -14,7 +15,7 @@ public class TodoList {
private String nom; private String nom;
@ManyToOne @ManyToOne
@JoinColumn(name="TEAM_ID") @JoinColumn(name="TEAM_ID")
@JsonIgnoreProperties("todolist") @JsonIgnoreProperties({"todolist","membre"})
private Team team; private Team team;
@OneToMany(mappedBy = "todolist", fetch=FetchType.LAZY, cascade = CascadeType.ALL) @OneToMany(mappedBy = "todolist", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonIgnoreProperties("todolist") @JsonIgnoreProperties("todolist")