-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.java
More file actions
152 lines (112 loc) · 5.18 KB
/
Copy pathProduct.java
File metadata and controls
152 lines (112 loc) · 5.18 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.ecommerce.product.entity;
import jakarta.persistence.*;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@Entity
@Table(name = "products")
@Document(indexName = "products")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@org.springframework.data.annotation.Id
private Long id;
@NotBlank(message = "Product name is required")
@Field(type = FieldType.Text, analyzer = "standard")
private String name;
@Column(length = 1000)
@Field(type = FieldType.Text, analyzer = "standard")
private String description;
@NotNull(message = "Price is required")
@DecimalMin(value = "0.0", inclusive = false, message = "Price must be greater than 0")
@Field(type = FieldType.Double)
private BigDecimal price;
@NotNull(message = "Stock quantity is required")
@Field(type = FieldType.Integer)
private Integer stockQuantity;
@NotBlank(message = "Category is required")
@Field(type = FieldType.Keyword)
private String category;
@Field(type = FieldType.Keyword)
private String brand;
@ElementCollection
@Field(type = FieldType.Keyword)
private List<String> tags;
@ElementCollection
private List<String> imageUrls;
@Field(type = FieldType.Double)
private Double weight;
@Field(type = FieldType.Keyword)
private String dimensions;
@Enumerated(EnumType.STRING)
@Field(type = FieldType.Keyword)
private ProductStatus status = ProductStatus.ACTIVE;
@Field(type = FieldType.Boolean)
private Boolean featured = false;
@Field(type = FieldType.Double)
private Double rating = 0.0;
@Field(type = FieldType.Integer)
private Integer reviewCount = 0;
@CreationTimestamp
@Field(type = FieldType.Date)
private LocalDateTime createdAt;
@UpdateTimestamp
@Field(type = FieldType.Date)
private LocalDateTime updatedAt;
// Constructors
public Product() {}
public Product(String name, String description, BigDecimal price, Integer stockQuantity, String category) {
this.name = name;
this.description = description;
this.price = price;
this.stockQuantity = stockQuantity;
this.category = category;
}
// Getters and Setters
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public BigDecimal getPrice() { return price; }
public void setPrice(BigDecimal price) { this.price = price; }
public Integer getStockQuantity() { return stockQuantity; }
public void setStockQuantity(Integer stockQuantity) { this.stockQuantity = stockQuantity; }
public String getCategory() { return category; }
public void setCategory(String category) { this.category = category; }
public String getBrand() { return brand; }
public void setBrand(String brand) { this.brand = brand; }
public List<String> getTags() { return tags; }
public void setTags(List<String> tags) { this.tags = tags; }
public List<String> getImageUrls() { return imageUrls; }
public void setImageUrls(List<String> imageUrls) { this.imageUrls = imageUrls; }
public Double getWeight() { return weight; }
public void setWeight(Double weight) { this.weight = weight; }
public String getDimensions() { return dimensions; }
public void setDimensions(String dimensions) { this.dimensions = dimensions; }
public ProductStatus getStatus() { return status; }
public void setStatus(ProductStatus status) { this.status = status; }
public Boolean getFeatured() { return featured; }
public void setFeatured(Boolean featured) { this.featured = featured; }
public Double getRating() { return rating; }
public void setRating(Double rating) { this.rating = rating; }
public Integer getReviewCount() { return reviewCount; }
public void setReviewCount(Integer reviewCount) { this.reviewCount = reviewCount; }
public LocalDateTime getCreatedAt() { return createdAt; }
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
public LocalDateTime getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
// Enums
public enum ProductStatus {
ACTIVE, INACTIVE, OUT_OF_STOCK, DISCONTINUED
}
}