我在下面提供了一个REST端点,
@PutMapping("/calculateReward")
public ResponseEntity<String> calculateReward(@RequestParam("userId") Long userId) {
Optional<User> optional = userService.findById(userId);
if (!optional.isPresent()) {
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
User user = optional.get();
double reward = user.getCurrentSteps() * Parameters.REWARD_PER_STEPS_EUR;
RewardList list = new RewardList();
list.setUser(user);
list.setReward(reward);
user.setCurrentSteps(0);
user.setRewardLists(list);
userService.save(user);
rewardListService.save(list);
JSONObject json = new JSONObject();
double convertionRateToEuro = currencyMap.get(user.getCurrencyName());
double rewardConverted = reward * convertionRateToEuro;
json.put("name", user.getName());
json.put("currency", user.getCurrencyName());
json.put("reward", rewardConverted);
return ResponseEntity.status(HttpStatus.CREATED).body(json.toString());
}
ATM我工作到另一个终点,我需要从上面提供的终点获得奖励值。
@PostMapping("/paypal/make/payment")
public ResponseEntity<String> paymentUsingPaypal(@RequestParam("userId") Long userId) {
Optional<User> optional = userService.findById(userId);
if (!optional.isPresent()) {
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
User user = optional.get();
// How do I get the "reward" in double here?
}
如何在第二种方法结束时从calculateReward
方法获得双倍的“奖励”?