OrderModel add total

This commit is contained in:
Tim
2025-06-15 20:44:37 +02:00
parent 91eefceacd
commit 4ea84ac0fd
3 changed files with 14 additions and 1 deletions

View File

@@ -29,4 +29,6 @@ public class OrderModel {
@NotNull
private List<OrderItemModel> orderItems;
private Integer total;
}

View File

@@ -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()
);
}
}

View File

@@ -36,4 +36,8 @@ public class OrderItem {
public OrderItemModel toModel() {
return new OrderItemModel(id, amount, article.getUuid());
}
public Integer getPrice() {
return amount * article.getPrice100();
}
}