diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartResponse.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartResponse.java index a02bc0b..0a4fafd 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartResponse.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartResponse.java @@ -5,11 +5,25 @@ public class CartResponse { private String username; private List items; - private Integer totalPrice; - private Integer totalDiscount; + private Double totalPrice; + private Double totalDiscount; + private Double fee; public CartResponse( - String username, List items, Integer totalPrice, Integer totalDiscount) { + String username, + List items, + Double totalPrice, + Double totalDiscount, + Double fee) { + this.username = username; + this.items = items; + this.totalPrice = totalPrice; + this.totalDiscount = totalDiscount; + this.fee = fee; + } + + public CartResponse( + String username, List items, Double totalPrice, Double totalDiscount) { this.username = username; this.items = items; this.totalPrice = totalPrice; @@ -32,19 +46,27 @@ public void setItems(List items) { this.items = items; } - public Integer getTotalPrice() { + public Double getTotalPrice() { return totalPrice; } - public void setTotalPrice(Integer totalPrice) { + public void setTotalPrice(Double totalPrice) { this.totalPrice = totalPrice; } - public Integer getTotalDiscount() { + public Double getTotalDiscount() { return totalDiscount; } - public void setTotalDiscount(Integer totalDiscount) { + public void setTotalDiscount(Double totalDiscount) { this.totalDiscount = totalDiscount; } + + public Double getFee() { + return fee; + } + + public void setFee(Double fee) { + this.fee = fee; + } } diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java index 484ff2d..f70b361 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartService.java @@ -7,6 +7,7 @@ import java.math.BigDecimal; import java.util.List; import java.util.Optional; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service @@ -17,6 +18,9 @@ public class CartService { private final ProductRepository productRepository; private final CartRepository cartRepository; + @Value("${enabled.feature.shipping-fee.api}") + private boolean enableToggleShippingFee; + public CartService( PromotionRepository promotionRepository, PromotionService promotionService, @@ -30,28 +34,50 @@ public CartService( this.cartRepository = cartRepository; } - // Story 4 : Add specific product to my cart public CartResponse addItemToCart(String productSku, int quantity, String username) { - // Optional product = productRepository.findBySku(productSku); + Double fee = 0.0; - // if (product.isEmpty()) { - // throw new NotFoundException("Product not found"); - // } + if (enableToggleShippingFee) { + fee = 25.0; + } - // Find the cart by username Optional cart = cartRepository.findByUsername(username); - // Product mockProduct = productRepository.findBySku(productSku); - Item mockItem = - new Item( - "MOBILE-APPLE-IPHONE-12-PRO", - "IPHONE12", - 1, - new BigDecimal("10000.00"), - new BigDecimal("10.00"), - new BigDecimal("10.00")); - - return new CartResponse(username, List.of(mockItem), 0, 0); + + List mockItem = + List.of( + new Item( + "MOBILE-APPLE-IPHONE-12-PRO", + "IPHONE12", + 1, + new BigDecimal("10000.00"), + new BigDecimal("10.00"), + new BigDecimal("9990.00")), + new Item( + "MOBILE-APPLE-IPHONE-12-PRO", + "IPHONE12", + 1, + new BigDecimal("5000.00"), + new BigDecimal("10.00"), + new BigDecimal("4990.00"))); + + Double totalPrice = 0.0; + Double totalDiscount = 0.0; + Double totalFinalPrice = 0.0; + + for (Item item : mockItem) { + totalPrice += item.getPrice().doubleValue(); + totalDiscount += item.getDiscount().doubleValue(); + + totalFinalPrice += item.getFinalPrice().doubleValue(); + + System.out.println(totalFinalPrice); + } + + System.out.println(totalPrice); + System.out.println(totalDiscount); + + return new CartResponse(username, mockItem, totalPrice, totalDiscount, fee); } // if (cart.isEmpty()) { diff --git a/kbazaar/src/main/resources/application.properties b/kbazaar/src/main/resources/application.properties index 49f848e..8af1451 100644 --- a/kbazaar/src/main/resources/application.properties +++ b/kbazaar/src/main/resources/application.properties @@ -25,3 +25,4 @@ springdoc.swagger-ui.enabled=true # Feature Toggle enabled.feature.promotion.list.api=true +enabled.feature.shipping-fee.api=true