Skip to content

Commit

Permalink
add feature toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
leenawat committed Mar 24, 2024
1 parent 07c8b7a commit 7f70c10
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
24 changes: 18 additions & 6 deletions kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java
Original file line number Diff line number Diff line change
@@ -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.*;

Expand All @@ -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();
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CartResponse {
private List<String> promotionCodes;
private BigDecimal totalCost;
private BigDecimal entireCartPromotionDiscount;
private BigDecimal shippingFee;
private BigDecimal finalTotalCost;

public static CartResponse fromCart(Cart cart) {
Expand Down
1 change: 1 addition & 0 deletions kbazaar/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ springdoc.swagger-ui.enabled=true

# Featuer Toggle
enabled.feature.promotion.list.api=true
enabled.shipping.fee=true

0 comments on commit 7f70c10

Please sign in to comment.