Skip to content

Commit

Permalink
feature-toggle - enable by condition
Browse files Browse the repository at this point in the history
  • Loading branch information
chinnawatsut committed Mar 22, 2024
1 parent c76198f commit 6269084
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1")
@ConditionalOnProperty(
value = "feature.toggle.promotion-api",
havingValue = "true",
matchIfMissing = true)
public class PromotionController {
private PromotionService promotionService;

@Value("${feature.toggle.promotion-api:true}")
private boolean promotionApi;

public PromotionController(PromotionService promotionService) {
this.promotionService = promotionService;
}
Expand All @@ -43,8 +43,11 @@ public PromotionController(PromotionService promotionService) {
mediaType = "application/json",
schema = @Schema(implementation = NotFoundException.class)))
@GetMapping("/promotions")
public List<PromotionResponse> getAllPromotions() {
return promotionService.getAll();
public ResponseEntity<List<PromotionResponse>> getAllPromotions() {
if (!promotionApi) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(promotionService.getAll());
}

@ApiResponse(
Expand Down

0 comments on commit 6269084

Please sign in to comment.