first commit

This commit is contained in:
Thomas Cardon 2022-01-19 15:16:16 +01:00
commit ec0dc019d8
29 changed files with 1458 additions and 0 deletions

View file

@ -0,0 +1,13 @@
package fr.cardon.simpleat;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SimpleatApplication {
public static void main(String[] args) {
SpringApplication.run(SimpleatApplication.class, args);
}
}

View file

@ -0,0 +1,106 @@
package fr.cardon.simpleat.controller;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import fr.cardon.simpleat.model.Personne;
import fr.cardon.simpleat.model.Role;
import fr.cardon.simpleat.repository.PersonneRepository;
import fr.cardon.simpleat.repository.RoleRepository;
@RestController
@CrossOrigin("*")
public class PersonneController {
@Autowired
private PersonneRepository personneRepository;
@Autowired
private RoleRepository roleRepository;
@GetMapping("/")
@ResponseBody
public String home(){
Personne p1 = new Personne();
p1.setNom("Coco");
p1.setPrenom("pouet");
p1.setEmail("pouetcoco@gmail.com");
p1.setPassword("hjfdzov");
p1.setRoles(findRoleById(2));
//ajoutPersonne(p1);
// Personne p2 = new Personne("coco","pouet","cocopouet@gmail.com","motdepasse");
StringBuilder sb = new StringBuilder();
sb.append("<h1>Personne Enregistrée</h1>");
sb.append("<a href='http://localhost:8080/users'>Voir la liste des personnes enregistrées</a>");
return sb.toString();
}
@GetMapping("/users")
public Collection<Personne> findAll(){
return personneRepository.findAll();
}
@GetMapping("/user/{id}")
public Personne findPersonneById(@PathVariable int id){
return personneRepository.findById(id);
}
@PostMapping("/add-user")
public ResponseEntity<?> ajoutPersonne(@RequestBody Personne personne){
return ResponseEntity.status(HttpStatus.OK).body(personneRepository.save(personne));
}
@PutMapping(value = "/update-user/{id}")
public ResponseEntity<?> modifPerso(@PathVariable int id, @RequestBody Personne personne){
// Personne persoAModif= null;
// persoAModif = findById(id);
// persoAModif.setNom(personne.getNom());
// persoAModif.setPrenom(personne.getPrenom());
// persoAModif.setEmail(personne.getEmail());
// persoAModif.setPassword(personne.getPassword());
return ResponseEntity.status(HttpStatus.OK).body(personneRepository.save(personne));
}
@DeleteMapping(value = "/delete-user/{id}")
public void suppressionPerso(@PathVariable int id){
// Personne persoASuppr= new Personne();
// persoASuppr = findById(id);
personneRepository.deleteById(id);
}
public Collection<Role> findRoleById(int idRole){
return roleRepository.findCollectionById(idRole);
}
// public Personne findById(int id) {
// return personneRepository.getById(id);
// }
}

View file

@ -0,0 +1,71 @@
package fr.cardon.simpleat.controller;
import java.util.Collection;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
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.Preference;
import fr.cardon.simpleat.model.PreferencePK;
import fr.cardon.simpleat.repository.PersonneRepository;
import fr.cardon.simpleat.repository.PreferenceRepository;
import fr.cardon.simpleat.repository.RestaurantRepository;
@RestController
@CrossOrigin("*")
public class PreferenceController {
@Autowired
private PreferenceRepository preferenceRepository;
@Autowired
private PersonneRepository personneRepository;
@Autowired
private RestaurantRepository restaurantRepository;
@GetMapping("/preferences")
public Collection<Preference> findAll(){
return preferenceRepository.findAll();
}
@GetMapping("/preference/{iduser}/{idrestau}")
public Optional<Preference> findPreferenceById(@PathVariable int iduser, @PathVariable int idrestau ){
PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau));
System.out.println(iduser);
return preferenceRepository.findById(id);
}
@PostMapping("/add-preference")
public ResponseEntity<?> ajoutPreference(@RequestBody Preference preference){
return ResponseEntity.status(HttpStatus.OK).body(preferenceRepository.save(preference));
}
// @PutMapping(value = "/update-restaurant/{id}")
// public ResponseEntity<?> modifPerso(@PathVariable int id, @RequestBody Restaurant personne){
// return ResponseEntity.status(HttpStatus.OK).body(preferenceRepository.save(personne));
// }
//
// @DeleteMapping(value = "/delete-restaurant/{id}")
// public void suppressionPerso(@PathVariable int id){
//
// preferenceRepository.deleteById(id);
// }
}

View file

@ -0,0 +1,57 @@
package fr.cardon.simpleat.controller;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
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.repository.RestaurantRepository;
@RestController
@CrossOrigin("*")
public class RestaurantController {
@Autowired
private RestaurantRepository restaurantRepository;
@GetMapping("/restaurants")
public Collection<Restaurant> findAll(){
return restaurantRepository.findAll();
}
@GetMapping("/restaurant/{id}")
public Restaurant findRestaurantById(@PathVariable int id){
return restaurantRepository.findById(id);
}
@PostMapping("/add-restaurant")
public ResponseEntity<?> ajoutRestaurant(@RequestBody Restaurant personne){
return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne));
}
@PutMapping(value = "/update-restaurant/{id}")
public ResponseEntity<?> modifRestaurant(@PathVariable int id, @RequestBody Restaurant personne){
return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne));
}
@DeleteMapping(value = "/delete-restaurant/{id}")
public void suppressionRestaurant(@PathVariable int id){
restaurantRepository.deleteById(id);
}
}

View file

@ -0,0 +1,56 @@
package fr.cardon.simpleat.controller;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
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.TypeRestau;
import fr.cardon.simpleat.repository.TypeRestauRepository;
@RestController
@CrossOrigin("*")
public class TypeRestauController {
@Autowired
private TypeRestauRepository typeRestauRepository;
@GetMapping("/types")
public Collection<TypeRestau> findAll(){
return typeRestauRepository.findAll();
}
@GetMapping("/type/{id}")
public TypeRestau findTypetById(@PathVariable int id){
return typeRestauRepository.findById(id);
}
@PostMapping("/add-type")
public ResponseEntity<?> ajoutType(@RequestBody TypeRestau type){
return ResponseEntity.status(HttpStatus.OK).body(typeRestauRepository.save(type));
}
@PutMapping(value = "/update-type/{id}")
public ResponseEntity<?> modifType(@PathVariable int id, @RequestBody TypeRestau type){
return ResponseEntity.status(HttpStatus.OK).body(typeRestauRepository.save(type));
}
@DeleteMapping(value = "/delete-type/{id}")
public void suppressionType(@PathVariable int id){
typeRestauRepository.deleteById(id);
}
}

View file

@ -0,0 +1,110 @@
package fr.cardon.simpleat.model;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Entity
public class Personne {
private int id;
private String nom;
private String prenom;
private String email;
private String password;
private Collection<Role> roles = new ArrayList<Role>();
public Personne() {
super();
// TODO Auto-generated constructor stub
}
public Personne(String nom, String prenom, String email, String password) {
super();
this.nom = nom;
this.prenom = prenom;
this.email = email;
this.password = password;
}
public Personne(String nom, String prenom, String email, String password, Collection<Role> roles) {
super();
this.nom = nom;
this.prenom = prenom;
this.email = email;
this.password = password;
this.roles = roles;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_personne")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(nullable = false)
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
@Column(nullable = false)
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
@Column(nullable = false)
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(nullable = false)
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@ManyToMany
@JoinTable(name="role_personne",
joinColumns = @JoinColumn(name = "id_perso"/*nom créé dans table asso*/,referencedColumnName = "id_personne" /*classe en cours*/) )
@JsonIgnoreProperties("roles")
public Collection<Role> getRoles() {
return roles;
}
public void setRoles(Collection<Role> roles) {
this.roles = roles;
}
}

View file

@ -0,0 +1,54 @@
package fr.cardon.simpleat.model;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
@Entity
public class Preference {
private PreferencePK preferencePK;
private int note;
private boolean favoris;
public Preference() {
super();
// TODO Auto-generated constructor stub
}
public Preference(PreferencePK preferencePK, int note, boolean favoris) {
super();
this.preferencePK = preferencePK;
this.note = note;
this.favoris = favoris;
}
@EmbeddedId
public PreferencePK getPreferencePK() {
return preferencePK;
}
public void setPreferencePK(PreferencePK preferencePK) {
this.preferencePK = preferencePK;
}
@Column(nullable = true)
public int getNote() {
return note;
}
public void setNote(int note) {
this.note = note;
}
@Column(nullable = true)
public boolean isFavori() {
return favoris;
}
public void setFavori(boolean favoris) {
this.favoris = favoris;
}
}

View file

@ -0,0 +1,66 @@
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;
import javax.persistence.ManyToOne;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Embeddable
public class PreferencePK implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Personne personne;
private Restaurant restau;
public PreferencePK() {
super();
// TODO Auto-generated constructor stub
}
public PreferencePK(Personne personne, Restaurant restau) {
super();
this.personne = personne;
this.restau = restau;
}
@ManyToOne
@JoinColumn(name="id_personne", referencedColumnName ="id_personne" )
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public Personne getPersonne() {
return personne;
}
public void setPersonne(Personne personne) {
this.personne = personne;
}
@ManyToOne // TODO mappedBy preferences dans restaurant
@JoinColumn(name="id_restau",referencedColumnName ="id_restau" )
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public Restaurant getRestau() {
return restau;
}
public void setRestau(Restaurant restau) {
this.restau = restau;
}
}

View file

@ -0,0 +1,40 @@
package fr.cardon.simpleat.model;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
@Entity
public class Reservation {
private ReservationPK reservationpk;
private int nbPersonne;
public Reservation() {
super();
// TODO Auto-generated constructor stub
}
public Reservation(ReservationPK reservationpk, int nbPersonne) {
super();
this.reservationpk = reservationpk;
this.nbPersonne = nbPersonne;
}
@EmbeddedId
public ReservationPK getReservationpk() {
return reservationpk;
}
public void setReservationpk(ReservationPK reservationpk) {
this.reservationpk = reservationpk;
}
@Column(nullable = false)
public int getNbPersonne() {
return nbPersonne;
}
public void setNbPersonne(int nbPersonne) {
this.nbPersonne = nbPersonne;
}
}

View file

@ -0,0 +1,61 @@
package fr.cardon.simpleat.model;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@Embeddable
public class ReservationPK implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private Personne personne;
private Restaurant restau;
private Date date;
public ReservationPK() {
super();
// TODO Auto-generated constructor stub
}
public ReservationPK(Personne personne, Restaurant restau, Date date) {
super();
this.personne = personne;
this.restau = restau;
this.date = date;
}
@ManyToOne
@JoinColumn(name="id_personne", referencedColumnName ="id_personne" )
public Personne getPersonne() {
return personne;
}
public void setPersonne(Personne personne) {
this.personne = personne;
}
@ManyToOne
@JoinColumn(name="id_restau",referencedColumnName ="id_restau" )
public Restaurant getRestau() {
return restau;
}
public void setRestau(Restaurant restau) {
this.restau = restau;
}
@Column(name="date_resa")
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}

View file

@ -0,0 +1,154 @@
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;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Entity
public class Restaurant {
private int id;
private String nom;
private String adresse;
private String telephone;
private boolean aEmporter;
private boolean surPlace;
private double prix;
private boolean accesPMR;
private String latitude;
private String longitude;
private String website;
private Collection<TypeRestau> typerestaus = new ArrayList<TypeRestau>();
//TODO @OneToMany relier avec une collec de preferences
public Restaurant() {
super();
// TODO Auto-generated constructor stub
}
public Restaurant(String nom, String adresse, String telephone, boolean aEmporter, boolean surPlace, double prix,
boolean accesPMR, String latitude, String longitude, String website, Collection<TypeRestau> typerestaus) {
super();
this.nom = nom;
this.adresse = adresse;
this.telephone = telephone;
this.aEmporter = aEmporter;
this.surPlace = surPlace;
this.prix = prix;
this.accesPMR = accesPMR;
this.latitude = latitude;
this.longitude = longitude;
this.website = website;
this.typerestaus = typerestaus;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_restau")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(nullable = false)
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
@Column(nullable = false)
public String getAdresse() {
return adresse;
}
public void setAdresse(String adresse) {
this.adresse = adresse;
}
@Column(nullable = true)
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
@Column(nullable = true)
public boolean isaEmporter() {
return aEmporter;
}
public void setaEmporter(boolean aEmporter) {
this.aEmporter = aEmporter;
}
@Column(nullable = true)
public boolean isSurPlace() {
return surPlace;
}
public void setSurPlace(boolean surPlace) {
this.surPlace = surPlace;
}
@Column(nullable = true)
public double getPrix() {
return prix;
}
public void setPrix(double prixMin) {
this.prix = prixMin;
}
@Column(nullable = true)
public boolean isAccesPMR() {
return accesPMR;
}
public void setAccesPMR(boolean accesPMR) {
this.accesPMR = accesPMR;
}
@Column(nullable = false)
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
@Column(nullable = false)
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
@Column(nullable = true)
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
@ManyToMany
@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")
public Collection<TypeRestau> getTyperestaus() {
return typerestaus;
}
public void setTyperestaus(Collection<TypeRestau> typerestaus) {
this.typerestaus = typerestaus;
}
}

View file

@ -0,0 +1,41 @@
package fr.cardon.simpleat.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Role {
private int id;
private String intitule;
public Role() {
super();
// TODO Auto-generated constructor stub
}
public Role(int id, String intitule) {
super();
this.id = id;
this.intitule = intitule;
}
@Id
@Column(name = "id_role")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(nullable = false)
public String getIntitule() {
return intitule;
}
public void setIntitule(String intitule) {
this.intitule = intitule;
}
}

View file

@ -0,0 +1,61 @@
package fr.cardon.simpleat.model;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Entity
@Table(name="type")
public class TypeRestau {
private int id;
private String libelle;
private List<Restaurant> restaurants;
public TypeRestau() {
super();
}
public TypeRestau(int id, String libelle) {
super();
this.id = id;
this.libelle = libelle;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_type")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(nullable = false)
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
@ManyToMany(mappedBy="typerestaus")
@JsonIgnoreProperties("typerestaus")
public List<Restaurant> getRestaurants() {
return restaurants;
}
public void setRestaurants(List<Restaurant> restaurants) {
this.restaurants = restaurants;
}
}

View file

@ -0,0 +1,13 @@
package fr.cardon.simpleat.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import fr.cardon.simpleat.model.Personne;
@Repository
public interface PersonneRepository extends JpaRepository<Personne, Integer> {
Personne findById(int id);
}

View file

@ -0,0 +1,13 @@
package fr.cardon.simpleat.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import fr.cardon.simpleat.model.Preference;
import fr.cardon.simpleat.model.PreferencePK;
@Repository
public interface PreferenceRepository extends JpaRepository<Preference, PreferencePK> {
}

View file

@ -0,0 +1,12 @@
package fr.cardon.simpleat.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import fr.cardon.simpleat.model.Reservation;
import fr.cardon.simpleat.model.ReservationPK;
@Repository
public interface ReservationRepository extends JpaRepository<Reservation, ReservationPK> {
}

View file

@ -0,0 +1,12 @@
package fr.cardon.simpleat.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import fr.cardon.simpleat.model.Restaurant;
@Repository
public interface RestaurantRepository extends JpaRepository<Restaurant, Integer> {
Restaurant findById(int id);
}

View file

@ -0,0 +1,16 @@
package fr.cardon.simpleat.repository;
import java.util.Collection;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import fr.cardon.simpleat.model.Role;
@Repository
public interface RoleRepository extends JpaRepository<Role, Integer> {
Collection<Role> findCollectionById(int id);
}

View file

@ -0,0 +1,13 @@
package fr.cardon.simpleat.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import fr.cardon.simpleat.model.TypeRestau;
@Repository
public interface TypeRestauRepository extends JpaRepository<TypeRestau, Integer> {
TypeRestau findById(int id);
}