-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct.java
More file actions
123 lines (96 loc) · 2.8 KB
/
Copy pathproduct.java
File metadata and controls
123 lines (96 loc) · 2.8 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
package com.example.store;
public class Product {
private String name;
private double price;
private String category;
private String size;
public Product(String name, double price, String category, String size) {
this.name = name;
this.price = price;
this.category = category;
this.size = size;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public String getCategory() {
return category;
}
package com.example.store;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@Controller
public class ProductController {
private List<Product> products = new ArrayList<>();
@GetMapping("/")
public String index(Model model) {
model.addAttribute("products", products);
return "index";
}
@GetMapping("/add")
public String addForm() {
return "add";
}
}
public String getSize() {
return size;
}
}
package com.example.store;
import jakarta.persistence.*;
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
private String manufacturer;
private double price;
private String category;
private String size;
private String imageUrl;
private String description;
public Product() {}
public Product(String title, String manufacturer, double price,
String category, String size, String imageUrl, String description) {
this.title = title;
this.manufacturer = manufacturer;
this.price = price;
this.category = category;
this.size = size;
this.imageUrl = imageUrl;
this.description = description;
}
public String getTitle() { return title; }
public String getManufacturer() { return manufacturer; }
public double getPrice() { return price; }
public String getCategory() { return category; }
public String getSize() { return size; }
public String getImageUrl() { return imageUrl; }
public String getDescription() { return description; }
}
private int rating;
private String review;
@GetMapping("/checkout")
public String checkout() {
for (Product p : cart) {
if (p.getStock() > 0) {
p.setStock(p.getStock() - 1);
productRepository.save(p);
}
}
cart.clear();
return "redirect:/";
}
private int rating;
private String review;
public int getRating() { return rating; }
public String getReview() { return review; }
public void setRating(int rating) { this.rating = rating; }
public void setReview(String review) { this.review = review; }