コード例 #1
0
 @RequestMapping(method = POST, value = "/{name}/deposit")
 public ModelAndView depositAmount(@PathVariable String name, @RequestParam String amount) {
   accountService.depositAmount(name, Long.parseLong(amount));
   long balance = accountService.getBalance(name);
   return new ModelAndView(
       "redirect:/accounts/" + name, "account", new AccountView(name, balance, ""));
 }
コード例 #2
0
 @RequestMapping(method = POST, value = "/{name}/withdraw")
 public ModelAndView withdrawAmount(@PathVariable String name, @RequestParam String amount)
     throws AmountExceedsAccountBalanceException {
   AccountView accountView;
   try {
     accountService.withdrawAmount(name, Long.parseLong(amount));
     accountView = new AccountView(name, accountService.getBalance(name));
   } catch (AmountExceedsAccountBalanceException exception) {
     LOGGER.error(exception.getMessage(), exception);
     accountView = new AccountView(name, accountService.getBalance(name), exception.getMessage());
   }
   return new ModelAndView("accounts/show", "account", accountView);
 }
コード例 #3
0
 @RequestMapping(method = GET, value = "")
 public ModelAndView listAllAccounts() {
   List<Account> accounts = accountService.getAllAccounts();
   List<AccountView> accountViews = new ArrayList<>();
   for (Account account : accounts) {
     accountViews.add(new AccountView(account.getName(), account.getBalance(), ""));
   }
   return new ModelAndView("accounts/index", "accounts", accountViews);
 }
コード例 #4
0
 @RequestMapping(method = GET, value = "/{name}")
 public ModelAndView showAccount(@PathVariable String name) {
   long balance = accountService.getBalance(name);
   return new ModelAndView("accounts/show", "account", new AccountView(name, balance, ""));
 }
コード例 #5
0
 @RequestMapping(method = POST)
 public String createAccount(@RequestParam String name) {
   accountService.createAccount(name);
   return "redirect:/accounts/" + name;
 }