Skip to content

Commit

Permalink
add logic to get interest rate dynamically (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Abhishek Agarwal <abhihsekag03@gmail.com>
  • Loading branch information
abhishekag03 and Abhishek Agarwal committed Nov 21, 2023
1 parent f0515e1 commit 08c4180
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class FlagsmithSpringBootBankingAppApplication {
@Autowired
private FlagsmithClient flagsmithClient;

double defaultInterestRate = 3.5;

public static void main(String[] args) {
SpringApplication.run(FlagsmithSpringBootBankingAppApplication.class, args);
Expand Down Expand Up @@ -74,8 +75,15 @@ public double checkBalance(@RequestParam(value = "accountId") String accountId)

// endpoint to get the current interest rate
@GetMapping("/interest-rate")
public ResponseEntity<Object> getInterestRate() {
return ResponseEntity.ok(3.5);
public ResponseEntity<Object> getInterestRate() throws FlagsmithClientError {
Flags flags = flagsmithClient.getEnvironmentFlags();
String featureName = "interest_rate";
Object intRate = flags.getFeatureValue(featureName);
if (intRate != "") {
return ResponseEntity.ok(intRate);
}
return ResponseEntity.ok(defaultInterestRate);

}
}

0 comments on commit 08c4180

Please sign in to comment.