OrderModel add total
This commit is contained in:
@@ -29,4 +29,6 @@ public class OrderModel {
|
||||
|
||||
@NotNull
|
||||
private List<OrderItemModel> orderItems;
|
||||
|
||||
private Integer total;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,13 @@ public class Order {
|
||||
private List<OrderItem> orderItems;
|
||||
|
||||
public OrderModel toModel() {
|
||||
return new OrderModel(id, customer.getId(), time, status, orderItems.stream().map(OrderItem::toModel).toList());
|
||||
return new OrderModel(
|
||||
id,
|
||||
customer.getId(),
|
||||
time,
|
||||
status,
|
||||
orderItems.stream().map(OrderItem::toModel).toList(),
|
||||
orderItems.stream().mapToInt(OrderItem::getPrice).sum()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,8 @@ public class OrderItem {
|
||||
public OrderItemModel toModel() {
|
||||
return new OrderItemModel(id, amount, article.getUuid());
|
||||
}
|
||||
|
||||
public Integer getPrice() {
|
||||
return amount * article.getPrice100();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user