diff --git a/src/main/java/fr/cardon/simpleat/model/Personne.java b/src/main/java/fr/cardon/simpleat/model/Personne.java index 9b9b7bf..68c58a8 100644 --- a/src/main/java/fr/cardon/simpleat/model/Personne.java +++ b/src/main/java/fr/cardon/simpleat/model/Personne.java @@ -4,6 +4,7 @@ package fr.cardon.simpleat.model; import java.util.ArrayList; import java.util.Collection; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -12,7 +13,9 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity @@ -24,6 +27,7 @@ public class Personne { private String email; private String password; private Collection roles = new ArrayList(); + private Collection preference = new ArrayList(); public Personne() { @@ -106,5 +110,17 @@ public class Personne { public void setRoles(Collection roles) { this.roles = roles; } + + + @OneToMany(mappedBy = "preferencePK.personne", cascade = CascadeType.REMOVE) + @JsonIgnore + public Collection getPreference() { + return preference; + } + + + public void setPreference(Collection preference) { + this.preference = preference; + } } diff --git a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java index 8e17df1..ed364ae 100644 --- a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java +++ b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java @@ -8,6 +8,7 @@ import javax.persistence.Embeddable; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.PrimaryKeyJoinColumn; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -37,7 +38,7 @@ public class PreferencePK implements Serializable { @ManyToOne - @JoinColumn(name="id_personne", referencedColumnName ="id_personne" ) + @PrimaryKeyJoinColumn(name="id_personne", referencedColumnName ="id_personne" ) @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public Personne getPersonne() { return personne; @@ -50,7 +51,7 @@ public class PreferencePK implements Serializable { @ManyToOne // TODO mappedBy preferences dans restaurant - @JoinColumn(name="id_restau",referencedColumnName ="id_restau" ) + @PrimaryKeyJoinColumn(name="id_restau",referencedColumnName ="id_restau" ) @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public Restaurant getRestau() { return restau; diff --git a/src/main/java/fr/cardon/simpleat/model/Restaurant.java b/src/main/java/fr/cardon/simpleat/model/Restaurant.java index 9035bd2..a85ca3f 100644 --- a/src/main/java/fr/cardon/simpleat/model/Restaurant.java +++ b/src/main/java/fr/cardon/simpleat/model/Restaurant.java @@ -3,6 +3,7 @@ package fr.cardon.simpleat.model; import java.util.ArrayList; import java.util.Collection; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -11,6 +12,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -32,7 +34,7 @@ public class Restaurant { private String longitude; private String website; private Collection typerestaus = new ArrayList(); - + private Collection preference = new ArrayList(); //TODO @OneToMany relier avec une collec de preferences public Restaurant() { @@ -150,5 +152,17 @@ public class Restaurant { public void setTyperestaus(Collection typerestaus) { this.typerestaus = typerestaus; } + + + @OneToMany(mappedBy = "preferencePK.restau", cascade = CascadeType.REMOVE) + @JsonIgnore + public Collection getPreference() { + return preference; + } + + + public void setPreference(Collection preference) { + this.preference = preference; + } } diff --git a/src/main/resources/Postman b/src/main/resources/Postman index 94de556..a222d5a 100644 --- a/src/main/resources/Postman +++ b/src/main/resources/Postman @@ -169,15 +169,15 @@ } }, "url": { - "raw": "localhost:8080/preference/5/5", + "raw": "localhost:8080/preference/1/3", "host": [ "localhost" ], "port": "8080", "path": [ "preference", - "5", - "5" + "1", + "3" ] } }, @@ -208,7 +208,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"preferencePK\": {\r\n \"personne\": {\r\n \"id\": 10\r\n },\r\n \"restau\": {\r\n \"id\": 2\r\n }\r\n },\r\n \"note\": 5,\r\n \"favori\": true\r\n}", + "raw": "{\r\n \"personne\": {\r\n \"id\": 1\r\n },\r\n \"restau\": {\r\n \"id\": 5\r\n },\r\n \"note\": 5,\r\n \"favoris\": true\r\n}", "options": { "raw": { "language": "json" diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 8dd4536..669d7b9 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -19,20 +19,20 @@ insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, ac insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Physicians Total Care, Inc.', '462 Mosinee Lane', '8521719889', false, false, 4, true, '-13.5', '48.86667'); insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Triweld Industries, Inc.', '2482 Corscot Way', '7513208452', false, true, 2, true, '34.326903', '108.117456'); -insert into preference (id_restau, id_personne, note, favori) values (2, 9, 1, false); -insert into preference (id_restau, id_personne, note, favori) values (3, 1, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 9, 3, true); -insert into preference (id_restau, id_personne, note, favori) values (4, 6, 2, false); -insert into preference (id_restau, id_personne, note, favori) values (5, 5, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 10, 1, false); -insert into preference (id_restau, id_personne, note, favori) values (5, 3, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 7, 1, true); -insert into preference (id_restau, id_personne, note, favori) values (4, 2, 1, false); -insert into preference (id_restau, id_personne, note, favori) values (1, 3, 5, false); -insert into preference (id_restau, id_personne, note, favori) values (3, 10, 4, false); -insert into preference (id_restau, id_personne, note, favori) values (3, 3, 4, true); -insert into preference (id_restau, id_personne, note, favori) values (2, 3, 3, false); -insert into preference (id_restau, id_personne, note, favori) values (2, 8, 3, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (2, 9, 1, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (3, 1, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 9, 3, true); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (4, 6, 2, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (5, 5, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 10, 1, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (5, 3, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 7, 1, true); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (4, 2, 1, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (1, 3, 5, false); +insert into preference (restau_id_restau, personne_id_personne, note, favori) values (3, 10, 4, false); +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 type (id_type, libelle) values (1, 'Kebab'); insert into type (id_type, libelle) values (2, 'Supermarché');