From 7f70c104a4bf59eb4f1de31de6a6a9cdcdf203f3 Mon Sep 17 00:00:00 2001 From: leenawat papahom Date: Sun, 24 Mar 2024 13:22:09 +0700 Subject: [PATCH] add feature toggle --- .../kampus/kbazaar/cart/CartController.java | 24 ++++++++++++++----- .../com/kampus/kbazaar/cart/CartResponse.java | 1 + .../src/main/resources/application.properties | 1 + 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java index 6cf568b..161ee73 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java @@ -1,6 +1,8 @@ package com.kampus.kbazaar.cart; +import java.math.BigDecimal; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -11,6 +13,9 @@ public class CartController { private final CartService cartService; + @Value("${enabled.shipping.fee:true}") + private boolean enableShippingFee; + @GetMapping("/carts") public ResponseEntity getCart() { // NOSONAR return ResponseEntity.ok().build(); @@ -21,11 +26,18 @@ public CartResponse addProduct( @PathVariable("username") String username, @RequestBody AddProductRequest addProductRequest) { - return cartService - .addProductByUsernameAndProductSku( - username, - addProductRequest.getProductSku(), - addProductRequest.getQuantity()) - .toCartResponse(); + CartResponse cartResponse = + cartService + .addProductByUsernameAndProductSku( + username, + addProductRequest.getProductSku(), + addProductRequest.getQuantity()) + .toCartResponse(); + + if (enableShippingFee) { + cartResponse.setShippingFee(new BigDecimal(25)); + } + + return cartResponse; } } 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 919c86f..7706dad 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartResponse.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartResponse.java @@ -19,6 +19,7 @@ public class CartResponse { private List promotionCodes; private BigDecimal totalCost; private BigDecimal entireCartPromotionDiscount; + private BigDecimal shippingFee; private BigDecimal finalTotalCost; public static CartResponse fromCart(Cart cart) { diff --git a/kbazaar/src/main/resources/application.properties b/kbazaar/src/main/resources/application.properties index 9e9dd39..7b67184 100644 --- a/kbazaar/src/main/resources/application.properties +++ b/kbazaar/src/main/resources/application.properties @@ -24,3 +24,4 @@ springdoc.swagger-ui.enabled=true # Featuer Toggle enabled.feature.promotion.list.api=true +enabled.shipping.fee=true