forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Order.java
47 lines (37 loc) · 1.02 KB
/
Order.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
package onlineshopping;
import java.util.List;
public class Order {
private final String id;
private final User user;
private final List<OrderItem> items;
private final double totalAmount;
private OrderStatus status;
public Order(String id, User user, List<OrderItem> items) {
this.id = id;
this.user = user;
this.items = items;
this.totalAmount = calculateTotalAmount();
this.status = OrderStatus.PENDING;
}
private double calculateTotalAmount() {
return items.stream().mapToDouble(item -> item.getProduct().getPrice() * item.getQuantity()).sum();
}
public void setStatus(OrderStatus status) {
this.status = status;
}
public String getId() {
return id;
}
public User getUser() {
return user;
}
public List<OrderItem> getItems() {
return items;
}
public double getTotalAmount() {
return totalAmount;
}
public OrderStatus getStatus() {
return status;
}
}