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