BAEL-7143: fixed formatting
This commit is contained in:
parent
920dc80c41
commit
a2ca867a58
@ -26,7 +26,7 @@ class ProductService {
|
|||||||
|
|
||||||
private void computePriceAndPublishMessage(String productId, String cartId) {
|
private void computePriceAndPublishMessage(String productId, String cartId) {
|
||||||
Product product = repository.findById(productId)
|
Product product = repository.findById(productId)
|
||||||
.orElseThrow(() -> new IllegalArgumentException("not found!"));
|
.orElseThrow(() -> new IllegalArgumentException("not found!"));
|
||||||
|
|
||||||
Price price = computePrice(productId, product);
|
Price price = computePrice(productId, product);
|
||||||
|
|
||||||
@ -35,11 +35,9 @@ class ProductService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Price computePrice(String productId, Product product) {
|
private Price computePrice(String productId, Product product) {
|
||||||
if (product.category()
|
if (product.category().isEligibleForDiscount()) {
|
||||||
.isEligibleForDiscount()) {
|
|
||||||
BigDecimal discount = discountService.discountForProduct(productId);
|
BigDecimal discount = discountService.discountForProduct(productId);
|
||||||
return product.basePrice()
|
return product.basePrice().applyDiscount(discount);
|
||||||
.applyDiscount(discount);
|
|
||||||
}
|
}
|
||||||
return product.basePrice();
|
return product.basePrice();
|
||||||
}
|
}
|
||||||
|
@ -22,17 +22,16 @@ class ProductService {
|
|||||||
|
|
||||||
public void addProductToCart(String productId, String cartId) {
|
public void addProductToCart(String productId, String cartId) {
|
||||||
repository.findById(productId)
|
repository.findById(productId)
|
||||||
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException("not found!")))
|
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException("not found!")))
|
||||||
.flatMap(this::computePrice)
|
.flatMap(this::computePrice)
|
||||||
.map(price -> new ProductAddedToCartEvent(productId, price.value(), price.currency(), cartId))
|
.map(price -> new ProductAddedToCartEvent(productId, price.value(), price.currency(), cartId))
|
||||||
.subscribe(event -> kafkaTemplate.send(PRODUCT_ADDED_TO_CART_TOPIC, cartId, event));
|
.subscribe(event -> kafkaTemplate.send(PRODUCT_ADDED_TO_CART_TOPIC, cartId, event));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<Price> computePrice(Product product) {
|
private Mono<Price> computePrice(Product product) {
|
||||||
if (product.category()
|
if (product.category().isEligibleForDiscount()) {
|
||||||
.isEligibleForDiscount()) {
|
|
||||||
return discountService.discountForProduct(product.id())
|
return discountService.discountForProduct(product.id())
|
||||||
.map(product.basePrice()::applyDiscount);
|
.map(product.basePrice()::applyDiscount);
|
||||||
}
|
}
|
||||||
return Mono.just(product.basePrice());
|
return Mono.just(product.basePrice());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user