diff --git a/src/main/java/fr/cardon/simpleat/model/Personne.java b/src/main/java/fr/cardon/simpleat/model/Personne.java index 520f149..3950856 100644 --- a/src/main/java/fr/cardon/simpleat/model/Personne.java +++ b/src/main/java/fr/cardon/simpleat/model/Personne.java @@ -36,12 +36,6 @@ public class Personne { } - public Personne(int id) { - super(); - this.id = id; - } - - public Personne(String nom, String prenom, String email, String password) { super(); this.nom = nom; @@ -129,7 +123,4 @@ public class Personne { this.preference = preference; } - - - -} +} \ No newline at end of file diff --git a/src/main/java/fr/cardon/simpleat/model/Preference.java b/src/main/java/fr/cardon/simpleat/model/Preference.java index c3b52e3..efab64c 100644 --- a/src/main/java/fr/cardon/simpleat/model/Preference.java +++ b/src/main/java/fr/cardon/simpleat/model/Preference.java @@ -1,20 +1,13 @@ package fr.cardon.simpleat.model; import javax.persistence.Column; +import javax.persistence.EmbeddedId; import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity -@IdClass(PreferencePK.class) public class Preference { - private Personne personne; - private Restaurant restau; + private PreferencePK preferencePK; private int note; private boolean favoris; @@ -26,79 +19,36 @@ public class Preference { } - - public Preference(Personne personne, Restaurant restau) { + public Preference(PreferencePK preferencePK, int note, boolean favoris) { super(); - this.personne = personne; - this.restau = restau; - } - - - - public Preference(Personne personne, Restaurant restau, int note, boolean favoris) { - super(); - this.personne = personne; - this.restau = restau; + this.preferencePK = preferencePK; this.note = note; this.favoris = favoris; } - - @Id - @ManyToOne - @JoinColumn(name="id_personne" ) - @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) - public Personne getPersonne() { - return personne; + @EmbeddedId + public PreferencePK getPreferencePK() { + return preferencePK; } - - - - public void setPersonne(Personne personne) { - this.personne = personne; + public void setPreferencePK(PreferencePK preferencePK) { + this.preferencePK = preferencePK; } - - @Id - @ManyToOne - @JoinColumn(name="id_restau" ) - @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) - public Restaurant getRestau() { - return restau; - } - - - - public void setRestau(Restaurant restau) { - this.restau = restau; - } - - @Column(nullable = true) public int getNote() { return note; } - - - public void setNote(int note) { this.note = note; } - - @Column(nullable = true) - public boolean isFavoris() { + public boolean isFavori() { return favoris; } - - - - public void setFavoris(boolean favoris) { + public void setFavori(boolean favoris) { this.favoris = favoris; } - - -} +} \ No newline at end of file diff --git a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java index 2cd7550..bbde557 100644 --- a/src/main/java/fr/cardon/simpleat/model/PreferencePK.java +++ b/src/main/java/fr/cardon/simpleat/model/PreferencePK.java @@ -3,6 +3,7 @@ package fr.cardon.simpleat.model; import java.io.Serializable; +import javax.persistence.CascadeType; import javax.persistence.Embeddable; import javax.persistence.FetchType; import javax.persistence.JoinColumn; @@ -12,7 +13,7 @@ import javax.persistence.PrimaryKeyJoinColumn; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - +@Embeddable public class PreferencePK implements Serializable { /** @@ -48,6 +49,7 @@ public class PreferencePK implements Serializable { this.personne = personne; } + @ManyToOne // TODO mappedBy preferences dans restaurant @PrimaryKeyJoinColumn(name="id_restau",referencedColumnName ="id_restau" ) @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) @@ -62,4 +64,4 @@ public class PreferencePK implements Serializable { -} +} \ No newline at end of file diff --git a/src/main/resources/Postman b/src/main/resources/Postman index cbee787..a222d5a 100644 --- a/src/main/resources/Postman +++ b/src/main/resources/Postman @@ -169,19 +169,15 @@ } }, "url": { - "raw": "localhost:8080/preference/1/3", - "host": [ "localhost" ], "port": "8080", "path": [ "preference", - "1", "3" - ] } }, @@ -212,9 +208,7 @@ "header": [], "body": { "mode": "raw", - "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 6615fc2..6c955fa 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -73,7 +73,6 @@ insert into preference (restau_id_restau, personne_id_personne, note, favori) va 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é'); insert into type (id_type, libelle) values (3, 'Boulangerie');