BAEL-7143: fixed formatting

This commit is contained in:
emanueltrandafir1993 2023-11-30 21:22:36 +01:00
parent 920dc80c41
commit a2ca867a58
2 changed files with 9 additions and 12 deletions

View File

@ -26,7 +26,7 @@ class ProductService {
private void computePriceAndPublishMessage(String productId, String cartId) {
Product product = repository.findById(productId)
.orElseThrow(() -> new IllegalArgumentException("not found!"));
.orElseThrow(() -> new IllegalArgumentException("not found!"));
Price price = computePrice(productId, product);
@ -35,11 +35,9 @@ class ProductService {
}
private Price computePrice(String productId, Product product) {
if (product.category()
.isEligibleForDiscount()) {
if (product.category().isEligibleForDiscount()) {
BigDecimal discount = discountService.discountForProduct(productId);
return product.basePrice()
.applyDiscount(discount);
return product.basePrice().applyDiscount(discount);
}
return product.basePrice();
}

View File

@ -22,17 +22,16 @@ class ProductService {
public void addProductToCart(String productId, String cartId) {
repository.findById(productId)
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException("not found!")))
.flatMap(this::computePrice)
.map(price -> new ProductAddedToCartEvent(productId, price.value(), price.currency(), cartId))
.subscribe(event -> kafkaTemplate.send(PRODUCT_ADDED_TO_CART_TOPIC, cartId, event));
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException("not found!")))
.flatMap(this::computePrice)
.map(price -> new ProductAddedToCartEvent(productId, price.value(), price.currency(), cartId))
.subscribe(event -> kafkaTemplate.send(PRODUCT_ADDED_TO_CART_TOPIC, cartId, event));
}
private Mono<Price> computePrice(Product product) {
if (product.category()
.isEligibleForDiscount()) {
if (product.category().isEligibleForDiscount()) {
return discountService.discountForProduct(product.id())
.map(product.basePrice()::applyDiscount);
.map(product.basePrice()::applyDiscount);
}
return Mono.just(product.basePrice());
}