merge->tho restau par type

This commit is contained in:
Thomas Cardon 2022-01-20 16:19:17 +01:00
commit ee20c5f049
4 changed files with 24 additions and 15 deletions

View File

@ -2,6 +2,7 @@ package fr.cardon.simpleat.controller;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; 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.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import fr.cardon.simpleat.model.Restaurant;
import fr.cardon.simpleat.model.TypeRestau; import fr.cardon.simpleat.model.TypeRestau;
import fr.cardon.simpleat.repository.TypeRestauRepository; import fr.cardon.simpleat.repository.TypeRestauRepository;
@ -36,6 +38,11 @@ public class TypeRestauController {
return typeRestauRepository.findById(id); return typeRestauRepository.findById(id);
} }
@GetMapping("/restaurantbytype/{id}")
public List<Restaurant> findRestauByType(@PathVariable int id){
return findTypetById(id).getRestaurants();
}
@PostMapping("/add-type") @PostMapping("/add-type")
public ResponseEntity<?> ajoutType(@RequestBody TypeRestau type){ public ResponseEntity<?> ajoutType(@RequestBody TypeRestau type){
return ResponseEntity.status(HttpStatus.OK).body(typeRestauRepository.save(type)); return ResponseEntity.status(HttpStatus.OK).body(typeRestauRepository.save(type));

View File

@ -3,7 +3,6 @@ package fr.cardon.simpleat.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
@ -13,6 +12,8 @@ import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@ -25,7 +26,7 @@ public class Restaurant {
private String telephone; private String telephone;
private boolean aEmporter; private boolean aEmporter;
private boolean surPlace; private boolean surPlace;
private double prix; private int prix;
private boolean accesPMR; private boolean accesPMR;
private String latitude; private String latitude;
private String longitude; private String longitude;
@ -39,7 +40,7 @@ public class Restaurant {
// TODO Auto-generated constructor stub // 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<TypeRestau> typerestaus) { boolean accesPMR, String latitude, String longitude, String website, Collection<TypeRestau> typerestaus) {
super(); super();
this.nom = nom; this.nom = nom;
@ -102,11 +103,11 @@ public class Restaurant {
this.surPlace = surPlace; this.surPlace = surPlace;
} }
@Column(nullable = true) @Column(nullable = true)
public double getPrix() { public int getPrix() {
return prix; return prix;
} }
public void setPrix(double prixMin) { public void setPrix(int prix) {
this.prix = prixMin; this.prix = prix;
} }
@Column(nullable = true) @Column(nullable = true)
public boolean isAccesPMR() { public boolean isAccesPMR() {
@ -141,7 +142,7 @@ public class Restaurant {
@JoinTable(name="type_restau", @JoinTable(name="type_restau",
joinColumns = @JoinColumn(name = "id_restau"/*classe en cours*/,referencedColumnName = "id_restau" /*classe reliée*/) , joinColumns = @JoinColumn(name = "id_restau"/*classe en cours*/,referencedColumnName = "id_restau" /*classe reliée*/) ,
inverseJoinColumns = @JoinColumn(name = "id_type",referencedColumnName = "id_type")) inverseJoinColumns = @JoinColumn(name = "id_type",referencedColumnName = "id_type"))
@JsonIgnoreProperties("typerestaus") @JsonBackReference("typerestaus")
public Collection<TypeRestau> getTyperestaus() { public Collection<TypeRestau> getTyperestaus() {
return typerestaus; return typerestaus;
} }

View File

@ -13,10 +13,11 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# JPA / HIBERNATE # JPA / HIBERNATE
# =============================== # ===============================
spring.jpa.show-sql=true spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update ##spring.jpa.hibernate.ddl-auto=update
##spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
# =============================== # ===============================
# Permet d'exécuter le data.sql # Permet d'exécuter le data.sql
# =============================== # ===============================
##spring.sql.init.mode=always spring.sql.init.mode=always
spring.jpa.defer-datasource-initialization=true

View File

@ -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 (1, 'Admin');
insert into role (id_role, intitule) values (2, 'User'); 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, 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_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, 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_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, 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_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, 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_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 ('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 (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 (3, 1, 5, false);