forked from aye-shadow/street-scout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuItem.java
55 lines (45 loc) · 1.39 KB
/
MenuItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package xyz.streetscout.vendor.entity;
import jakarta.persistence.*;
import lombok.Data;
@Data
@Entity
@Table(name = "menu_items",
uniqueConstraints = {
@UniqueConstraint(
name = "uc_name_vendor_id",
columnNames = {"name", "vendor_id"})})
public class MenuItem {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "name", nullable = false)
private String name;
@Column(name = "description")
private String description;
@Column(name = "price")
private Double price;
@ManyToOne(
fetch = FetchType.EAGER,
cascade = {CascadeType.DETACH, CascadeType.MERGE,
CascadeType.PERSIST, CascadeType.REFRESH})
@JoinColumn(name = "vendor_id")
private Vendor vendor;
public void setPrice(Double price) {
if (price < 0) {
throw new IllegalArgumentException("Price cannot be negative");
}
this.price = price;
}
@Override
public String toString() {
String vendorName = vendor != null ? vendor.getName() : "";
return "MenuItem{" +
"id=" + id +
", name='" + name + '\'' +
", description='" + description + '\'' +
", price=" + price +
", vendor='" + vendorName + '\'' +
'}';
}
}