diff --git a/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java b/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java index cf2a3ce..4aa388e 100644 --- a/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java +++ b/src/main/java/fr/cardon/simpleat/controller/TypeRestauController.java @@ -2,6 +2,7 @@ package fr.cardon.simpleat.controller; import java.util.Collection; +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import fr.cardon.simpleat.model.Restaurant; import fr.cardon.simpleat.model.TypeRestau; import fr.cardon.simpleat.repository.TypeRestauRepository; @@ -36,6 +38,11 @@ public class TypeRestauController { return typeRestauRepository.findById(id); } + @GetMapping("/restaurantbytype/{id}") + public List findRestauByType(@PathVariable int id){ + return findTypetById(id).getRestaurants(); + } + @PostMapping("/add-type") public ResponseEntity ajoutType(@RequestBody TypeRestau type){ return ResponseEntity.status(HttpStatus.OK).body(typeRestauRepository.save(type)); diff --git a/src/main/java/fr/cardon/simpleat/model/Restaurant.java b/src/main/java/fr/cardon/simpleat/model/Restaurant.java index 54a6066..9035bd2 100644 --- a/src/main/java/fr/cardon/simpleat/model/Restaurant.java +++ b/src/main/java/fr/cardon/simpleat/model/Restaurant.java @@ -3,7 +3,6 @@ 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; @@ -13,6 +12,8 @@ import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -25,7 +26,7 @@ public class Restaurant { private String telephone; private boolean aEmporter; private boolean surPlace; - private double prix; + private int prix; private boolean accesPMR; private String latitude; private String longitude; @@ -39,7 +40,7 @@ public class Restaurant { // TODO Auto-generated constructor stub } - public Restaurant(String nom, String adresse, String telephone, boolean aEmporter, boolean surPlace, double prix, + public Restaurant(String nom, String adresse, String telephone, boolean aEmporter, boolean surPlace, int prix, boolean accesPMR, String latitude, String longitude, String website, Collection typerestaus) { super(); this.nom = nom; @@ -102,11 +103,11 @@ public class Restaurant { this.surPlace = surPlace; } @Column(nullable = true) - public double getPrix() { + public int getPrix() { return prix; } - public void setPrix(double prixMin) { - this.prix = prixMin; + public void setPrix(int prix) { + this.prix = prix; } @Column(nullable = true) public boolean isAccesPMR() { @@ -141,7 +142,7 @@ public class Restaurant { @JoinTable(name="type_restau", joinColumns = @JoinColumn(name = "id_restau"/*classe en cours*/,referencedColumnName = "id_restau" /*classe reliée*/) , inverseJoinColumns = @JoinColumn(name = "id_type",referencedColumnName = "id_type")) - @JsonIgnoreProperties("typerestaus") + @JsonBackReference("typerestaus") public Collection getTyperestaus() { return typerestaus; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 180efdc..875e116 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,10 +13,11 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # JPA / HIBERNATE # =============================== spring.jpa.show-sql=true -spring.jpa.hibernate.ddl-auto=update -##spring.jpa.hibernate.ddl-auto=create-drop +##spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect # =============================== # Permet d'exécuter le data.sql # =============================== -##spring.sql.init.mode=always +spring.sql.init.mode=always +spring.jpa.defer-datasource-initialization=true \ No newline at end of file diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index b075246..8dd4536 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -13,11 +13,11 @@ insert into personne (nom, prenom, email, password) values ('Crick', 'Andris', ' insert into role (id_role, intitule) values (1, 'Admin'); insert into role (id_role, intitule) values (2, 'User'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix_min, prix_max, accespmr, latitude, longitude) values ('L Perrigo Company', '301 Thierer Trail', '3092096786', false, true, 10, 16, false, '2.1961772', '22.4708685'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix_min, prix_max, accespmr, latitude, longitude) values ('Sanofi Pasteur Inc.', '9 Barnett Terrace', '6809964349', false, true, 1, 17, false, '31.45571', '34.43719'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix_min, prix_max, accespmr, latitude, longitude) values ('REMEDYREPACK INC.', '3 West Park', '4565542193', true, false, 2, 20, true, '49.817777', '19.785536'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix_min, prix_max, accespmr, latitude, longitude) values ('Physicians Total Care, Inc.', '462 Mosinee Lane', '8521719889', false, false, 1, 22, true, '-13.5', '48.86667'); -insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix_min, prix_max, accespmr, latitude, longitude) values ('Triweld Industries, Inc.', '2482 Corscot Way', '7513208452', false, true, 5, 13, true, '34.326903', '108.117456'); +insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('L Perrigo Company', '301 Thierer Trail', '3092096786', false, true, 1, false, '2.1961772', '22.4708685'); +insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('Sanofi Pasteur Inc.', '9 Barnett Terrace', '6809964349', false, true, 2, false, '31.45571', '34.43719'); +insert into restaurant (nom, adresse, telephone, a_emporter, sur_place, prix, accespmr, latitude, longitude) values ('REMEDYREPACK INC.', '3 West Park', '4565542193', true, false, 3, true, '49.817777', '19.785536'); +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);