favor model
This commit is contained in:
parent
230de1ccaf
commit
771a6bcafc
125
src/main/java/ru/ulstu/is/sbapp/repair/model/Favor.java
Normal file
125
src/main/java/ru/ulstu/is/sbapp/repair/model/Favor.java
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
package ru.ulstu.is.sbapp.repair.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "favors")
|
||||||
|
public class Favor {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
@Column(name = "name")
|
||||||
|
private String favorName;
|
||||||
|
@Column(name = "price")
|
||||||
|
private Integer price;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "favor", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
private List<FavorComponents> components;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "favor", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
@JsonIgnore
|
||||||
|
private List<OrderFavors> orders;
|
||||||
|
|
||||||
|
|
||||||
|
public Favor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Favor(String favorName, Integer price) {
|
||||||
|
this.favorName = favorName;
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFavorName() {
|
||||||
|
return favorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFavorName(String favorName) {
|
||||||
|
this.favorName = favorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(Integer price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FavorComponents> getComponents() {
|
||||||
|
return components;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComponents(List<FavorComponents> components) {
|
||||||
|
this.components = components;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Favor favor){
|
||||||
|
this.favorName = favor.productName;
|
||||||
|
this.price = favor.price;
|
||||||
|
this.components = favor.getComponents();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addComponent(FavorComponents favorComponents){
|
||||||
|
if (components == null){
|
||||||
|
this.components = new ArrayList<>();
|
||||||
|
}
|
||||||
|
if (!components.contains(favorComponents))
|
||||||
|
this.components.add(favorComponents);
|
||||||
|
}
|
||||||
|
public void removeComponent(FavorComponents favorComponents){
|
||||||
|
if (components.contains(favorComponents))
|
||||||
|
this.components.remove(favorComponents);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderFavors> getOrders() {
|
||||||
|
return orders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrders(List<Orderfavors> orders) {
|
||||||
|
this.orders = orders;
|
||||||
|
}
|
||||||
|
public void addOrder(OrderFavors orderFavors){
|
||||||
|
if (orders == null){
|
||||||
|
orders = new ArrayList<>();
|
||||||
|
}
|
||||||
|
if (!orders.contains(orderFavors))
|
||||||
|
this.orders.add(orderFavors);
|
||||||
|
}
|
||||||
|
public void removeOrder(OrderFavors orderFavors){
|
||||||
|
if (orders.contains(orderFavors))
|
||||||
|
this.orders.remove(orderFavors);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Favor favor = (Favor) o;
|
||||||
|
return Objects.equals(id, favor.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Product{" +
|
||||||
|
"id=" + id +
|
||||||
|
", productName='" + favorName + '\'' +
|
||||||
|
", price='" + price + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user