feat: add order service
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
package com.demo.order;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public class OrderService {
|
||||||
|
|
||||||
|
private final OrderRepository repository;
|
||||||
|
|
||||||
|
public OrderService(OrderRepository repository) {
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal total(Order order) {
|
||||||
|
BigDecimal sum = BigDecimal.ZERO;
|
||||||
|
for (OrderLine line : order.getLines()) {
|
||||||
|
sum = sum.add(line.getPrice().multiply(BigDecimal.valueOf(line.getQuantity())));
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void submit(Order order) {
|
||||||
|
repository.save(order);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user