controller restauParType

This commit is contained in:
Thomas Cardon 2022-01-20 16:16:16 +01:00
parent ec0dc019d8
commit 228e013a75
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.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<Restaurant> 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));

View File

@ -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;
@ -40,7 +41,7 @@ public class Restaurant {
}
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) {
super();
this.nom = nom;
@ -103,11 +104,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() {
@ -142,7 +143,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<TypeRestau> getTyperestaus() {
return typerestaus;
}

View File

@ -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

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 (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);