Commit f88fdfe4 authored by Ashok Kumar K's avatar Ashok Kumar K

changed OrderLineDto model and updated OrderServiceImpl

parent 4a112bbf
...@@ -4,7 +4,6 @@ import lombok.Data; ...@@ -4,7 +4,6 @@ import lombok.Data;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Data @Data
public class OrderLineDto { public class OrderLineDto {
...@@ -13,8 +12,4 @@ public class OrderLineDto { ...@@ -13,8 +12,4 @@ public class OrderLineDto {
private String productId; private String productId;
@Min(value = 1, message = "quantity must be at least one") @Min(value = 1, message = "quantity must be at least one")
private int quantity; private int quantity;
private String productName;
@NotNull(message = "price can't be null")
@Min(value = 1, message = "price can't be negative")
private Double price;
} }
...@@ -47,6 +47,8 @@ public class OrderServiceImpl implements OrderService { ...@@ -47,6 +47,8 @@ public class OrderServiceImpl implements OrderService {
String productId = orderLine.getProductId(); String productId = orderLine.getProductId();
Product product = productClient.getProductById(productId); Product product = productClient.getProductById(productId);
if (product.getId() == null) throw new NotFoundException("product not found with ID: " + productId); if (product.getId() == null) throw new NotFoundException("product not found with ID: " + productId);
orderLine.setProductName(product.getName());
orderLine.setPrice(product.getPrice());
orderLine.setSubTotal(product.getPrice() * orderLine.getQuantity()); orderLine.setSubTotal(product.getPrice() * orderLine.getQuantity());
}); });
order.setOrderTotal(order.getLineItems().stream().mapToDouble(OrderLine::getSubTotal).sum()); order.setOrderTotal(order.getLineItems().stream().mapToDouble(OrderLine::getSubTotal).sum());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment