Commit a5671314 authored by Christopher Cottier's avatar Christopher Cottier

promotions applied to items upon ordering

parent 3a54dfd3
...@@ -51,27 +51,28 @@ public class OrderService { ...@@ -51,27 +51,28 @@ public class OrderService {
orderItem.setItemQuantity(quantity); orderItem.setItemQuantity(quantity);
//set promotion if applicable return orderItem;
}).flatMap(orderItem -> {
Flux<Promotion> promotionFlux = productService Flux<Promotion> promotionFlux = productService
.getPromotionBySkus(Arrays.asList(orderItem.getItemSku())); .getPromotionBySkus(Arrays.asList(orderItem.getItemSku()));
promotionFlux Mono<OrderItem> orderItemMono = promotionFlux
.collectList() .collectList()
.map(promotionList -> { .map(promotionList -> {
System.out.println("Give me promo list"); System.out.println("Give me promo list");
if (promotionList.size() == 0 ) {return promotionList;} if (promotionList.size() > 0) {
Promotion promotion = promotionList.get(0); Promotion promotion = promotionList.get(0);
if (orderItem.getItemQuantity().intValue() >= promotion.getMinimumQuantity().intValue()) { if (orderItem.getItemQuantity().intValue() >= promotion.getMinimumQuantity().intValue()) {
Float originalPrice = orderItem.getItemPrice(); Float originalPrice = orderItem.getItemPrice();
Float newPrice = originalPrice * (promotion.getDiscountPercentage() / 100); Float newPrice = originalPrice * ((100 - promotion.getDiscountPercentage()) / 100);
orderItem.setItemPrice(newPrice); orderItem.setItemPrice(newPrice);
}
} }
return promotion; return orderItem;
}).subscribe(); });
return orderItemMono;
return orderItem;
}); });
// //falttens the things
Mono<Mono<Order>> map = orderItems.collectList().map(itemList -> { Mono<Mono<Order>> map = orderItems.collectList().map(itemList -> {
OrderSubmission orderSubmission = new OrderSubmission(); OrderSubmission orderSubmission = new OrderSubmission();
......
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