Lombok et buider sur les derniers models

This commit is contained in:
vincentRamiere 2025-07-09 19:27:35 +02:00
parent 447d2d07a7
commit 2cfd096660
2 changed files with 71 additions and 196 deletions

View file

@ -1,164 +1,69 @@
package fr.vincent.ramiere.mangerautourdesimplonback.models; package fr.vincent.ramiere.mangerautourdesimplonback.models;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToMany;
@Entity @Entity
@Table(name = "restaurant")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Restaurant implements Serializable { public class Restaurant implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int id;
private String nom;
private String adresse;
private String telephone;
private Boolean aEmporter;
private Boolean surPlace;
private Integer prix;
private Boolean accesPMR;
private String latitude;
private String longitude;
private String website;
private Collection<TypeRestau> typerestaus = new ArrayList<>();
private Collection<Preference> preference = new ArrayList<>();
public Restaurant() {
super();
}
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;
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 @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_restau") @Column(name = "id_restau")
public int getId() { private int id;
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(nullable = false) @Column(nullable = false)
public String getNom() { private String nom;
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
@Column(nullable = false) @Column(nullable = false)
public String getAdresse() { private String adresse;
return adresse;
} @Column
public void setAdresse(String adresse) { private String telephone;
this.adresse = adresse;
} @Column(name = "a_emporter")
@Column(nullable = true) private Boolean aEmporter;
public String getTelephone() {
return telephone; @Column(name = "sur_place")
} private Boolean surPlace;
public void setTelephone(String telephone) {
this.telephone = telephone; @Column
} private Integer prix;
@Column(nullable = true)
public Boolean isaEmporter() { @Column(name = "accespmr")
return aEmporter; private Boolean accesPMR;
}
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 Integer getPrix() {
return prix;
}
public void setPrix(Integer prix) {
this.prix = prix;
}
@Column(nullable = true)
public Boolean isAccesPMR() {
return accesPMR;
}
public void setAccesPMR(Boolean accesPMR) {
this.accesPMR = accesPMR;
}
@Column(nullable = false) @Column(nullable = false)
public String getLatitude() { private String latitude;
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
@Column(nullable = false) @Column(nullable = false)
public String getLongitude() { private String longitude;
return longitude;
} @Column
public void setLongitude(String longitude) { private String website;
this.longitude = longitude;
}
@Column(nullable = true)
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
@ManyToMany @ManyToMany
@JoinTable(name="type_restau", @JoinTable(
joinColumns = @JoinColumn(name = "id_restau"/*classe en cours*/,referencedColumnName = "id_restau" /*classe reliée*/) , name = "type_restau",
inverseJoinColumns = @JoinColumn(name = "id_type",referencedColumnName = "id_type")) joinColumns = @JoinColumn(name = "id_restau", referencedColumnName = "id_restau"),
public Collection<TypeRestau> getTyperestaus() { inverseJoinColumns = @JoinColumn(name = "id_type", referencedColumnName = "id_type")
return typerestaus; )
} @Builder.Default
public void setTyperestaus(Collection<TypeRestau> typerestaus) { private Collection<TypeRestau> typerestaus = new ArrayList<>();
this.typerestaus = typerestaus;
}
@OneToMany(mappedBy = "preferencePK.restau", cascade = CascadeType.REMOVE) @OneToMany(mappedBy = "preferencePK.restau", cascade = CascadeType.REMOVE)
@JsonIgnore @JsonIgnore
public Collection<Preference> getPreference() { @Builder.Default
return preference; private Collection<Preference> preference = new ArrayList<>();
}
public void setPreference(Collection<Preference> preference) {
this.preference = preference;
}
} }

View file

@ -1,63 +1,33 @@
package fr.vincent.ramiere.mangerautourdesimplonback.models; package fr.vincent.ramiere.mangerautourdesimplonback.models;
import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.*;
import lombok.*;
import java.util.ArrayList;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
@Entity @Entity
@Table(name="type") @Table(name = "type")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class TypeRestau implements Serializable { public class TypeRestau implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
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 @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_type") @Column(name = "id_type")
public int getId() { private int id;
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(nullable = false) @Column(nullable = false)
public String getLibelle() { private String libelle;
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
@ManyToMany(mappedBy="typerestaus") @ManyToMany(mappedBy = "typerestaus")
@JsonBackReference("restaurants") @JsonBackReference("restaurants")
public List<Restaurant> getRestaurants() { @Builder.Default
return restaurants; private List<Restaurant> restaurants = new ArrayList<>();
}
public void setRestaurants(List<Restaurant> restaurants) {
this.restaurants = restaurants;
}
} }