all models are done

This commit is contained in:
VictoriaPresnyakova 2023-03-27 23:20:07 +04:00
parent 771a6bcafc
commit 6d3128d1d1
7 changed files with 304 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
@ -17,9 +18,9 @@ public class Component {
@Column(name = "amount")
private Integer amount;
// @OneToMany(mappedBy = "component", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
// @JsonIgnore
//private List<FavorComponents> favor;
@OneToMany(mappedBy = "component", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JsonIgnore
private List<FavorComponents> favors;
public Component() {
}
@ -50,7 +51,7 @@ public class Component {
}
public List<FavorComponents> getFavors() {
return Favors;
return favors;
}
public void setFavors(List<FavorComponents> favors) {

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
@ -63,7 +64,7 @@ public class Favor {
}
public void update(Favor favor){
this.favorName = favor.productName;
this.favorName = favor.favorName;
this.price = favor.price;
this.components = favor.getComponents();
}
@ -84,7 +85,7 @@ public class Favor {
return orders;
}
public void setOrders(List<Orderfavors> orders) {
public void setOrders(List<OrderFavors> orders) {
this.orders = orders;
}
public void addOrder(OrderFavors orderFavors){

View File

@ -0,0 +1,68 @@
package ru.ulstu.is.sbapp.repair.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
@Entity
@Table(name = "favor_component")
public class FavorComponents {
@EmbeddedId
private FavorComponentsKey id;
@ManyToOne
@MapsId("componentId")
@JoinColumn(name = "component_id")
private Component component;
@ManyToOne
@MapsId("favorId")
@JoinColumn(name = "favor_id")
@JsonIgnore
private Favor favor;
@Column(name = "count")
private Integer count;
public FavorComponents() {
}
public FavorComponents(Component component, Favor favor, Integer count) {
this.component = component;
this.id = new FavorComponentsKey(favor.getId(), component.getId());
this.id.setComponentId(component.getId());
this.id.setFavorId(favor.getId());
this.favor = favor;
this.count = count;
}
public FavorComponentsKey getId() {
return id;
}
public void setId(FavorComponentsKey id) {
this.id = id;
}
public Component getComponent() {
return component;
}
public void setComponent(Component component) {
this.component = component;
}
public Favor getFavor() {
return favor;
}
public void setFavor(Favor favor) {
this.favor = favor;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}

View File

@ -0,0 +1,47 @@
package ru.ulstu.is.sbapp.repair.model;
import javax.persistence.Embeddable;
import java.io.Serializable;
import java.util.Objects;
@Embeddable
public class FavorComponentsKey implements Serializable {
private Long favorId;
private Long componentId;
public FavorComponentsKey() {
}
public FavorComponentsKey(Long favorId, Long componentId) {
this.favorId = favorId;
this.componentId = componentId;
}
public Long getFavorId() {
return favorId;
}
public void setFavorId(Long favorId) {
this.favorId = favorId;
}
public Long getComponentId() {
return componentId;
}
public void setComponentId(Long componentId) {
this.componentId = componentId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof FavorComponentsKey that)) return false;
return Objects.equals(getFavorId(), that.getFavorId()) && Objects.equals(getComponentId(), that.getComponentId());
}
@Override
public int hashCode() {
return Objects.hash(getFavorId(), getComponentId());
}
}

View File

@ -0,0 +1,77 @@
package ru.ulstu.is.sbapp.repair.model;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "orders")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "date")
private Date date;
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<OrderFavors> favors;
public Order(){
}
public Order(Date date) {
this.date = date;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public List<OrderFavors> getFavors() {
return favors;
}
public void setFavors(List<OrderFavors> favors) {
this.favors = favors;
}
public void addFavor(OrderFavors orderFavors){
if (favors == null){
this.favors = new ArrayList<>();
}
if (!favors.contains(orderFavors))
this.favors.add(orderFavors);
}
public void removeFavors(OrderFavors orderFavors){
if (favors.contains(orderFavors))
this.favors.remove(orderFavors);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Order order)) return false;
return Objects.equals(getId(), order.getId()) && Objects.equals(getDate(), order.getDate());
}
@Override
public int hashCode() {
return Objects.hash(getId(), getDate());
}
}

View File

@ -0,0 +1,57 @@
package ru.ulstu.is.sbapp.repair.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
@Entity
@Table(name = "order_favor")
public class OrderFavors {
@EmbeddedId
private OrderFavorsKey id;
@ManyToOne
@MapsId("favorId")
@JoinColumn(name = "favor_id")
private Favor favor;
@ManyToOne
@MapsId("orderId")
@JoinColumn(name = "order_id")
@JsonIgnore
private Order order;
public OrderFavors() {
}
public OrderFavors(Order order, Favor favor) {
this.order = order;
this.id = new OrderFavorsKey(favor.getId(), order.getId());
this.id.setOrderId(order.getId());
this.id.setFavorId(favor.getId());
this.favor = favor;
}
public OrderFavorsKey getId() {
return id;
}
public void setId(OrderFavorsKey id) {
this.id = id;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public Favor getFavor() {
return favor;
}
public void setFavor(Favor favor) {
this.favor = favor;
}
}

View File

@ -0,0 +1,47 @@
package ru.ulstu.is.sbapp.repair.model;
import javax.persistence.Embeddable;
import java.io.Serializable;
import java.util.Objects;
@Embeddable
public class OrderFavorsKey implements Serializable {
private Long favorId;
private Long orderId;
public OrderFavorsKey() {
}
public OrderFavorsKey(Long favorId, Long orderId) {
this.favorId = favorId;
this.orderId = orderId;
}
public Long getFavorId() {
return favorId;
}
public void setFavorId(Long favorId) {
this.favorId = favorId;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof OrderFavorsKey that)) return false;
return Objects.equals(getFavorId(), that.getFavorId()) && Objects.equals(getOrderId(), that.getOrderId());
}
@Override
public int hashCode() {
return Objects.hash(getFavorId(), getOrderId());
}
}