// update a paymentCard @RequestMapping(method = RequestMethod.POST) public String update(@Valid PaymentCard paymentCard, BindingResult bindingResult, Model model) { if (bindingResult.hasErrors()) { List<String> types = paymentCardService.getTypes(); model.addAttribute("typeList", types); return "cards/edit"; } paymentCardService.updatePaymentCard(paymentCard); String message = "Succesfully updated Payment Card " + paymentCard.getNumber() + "."; FlashMap.setSuccessMessage(message); return "redirect:/cards/" + paymentCard.getId(); }
// edit a specific PaymentCard - form @RequestMapping(value = "{id}/edit", method = RequestMethod.GET) public String editForm(@PathVariable Long id, Model model) { PaymentCard paymentCard; List<String> types = paymentCardService.getTypes(); model.addAttribute("typeList", types); try { paymentCard = paymentCardService.findPaymentCardById(id); } catch (NoResultException e) { return "cards/invalidPaymentCard"; } model.addAttribute(paymentCard); return "cards/edit"; }
// add a new paymentCard - form @RequestMapping(value = "add", method = RequestMethod.GET) public String addForm(Model model) { List<String> types = paymentCardService.getTypes(); model.addAttribute("typeList", types); model.addAttribute(new PaymentCard()); return "cards/add"; }
// delete a paymentCard @RequestMapping(value = "{id}", method = RequestMethod.DELETE) public String delete(@PathVariable Long id, Model model) { paymentCardService.deletePaymentCardById(id); String message = "Succesfully deleted Payment Card."; FlashMap.setSuccessMessage(message); return "redirect:../cards/"; }
// find specific payment card - via AJAX @RequestMapping( value = "{id}/details.json", method = RequestMethod.GET, headers = "Accept=application/json") public @ResponseBody PaymentCard details(@PathVariable Long id) { PaymentCard card = paymentCardService.findPaymentCardById(id); return card; }
// find a users payment cards - via AJAX @RequestMapping( value = "{username}/view.json", method = RequestMethod.GET, headers = "Accept=application/json") public @ResponseBody List<PaymentCard> view(@PathVariable String username) { List<PaymentCard> cards = paymentCardService.findPaymentCards(username); return cards; }
// list all of the users PaymentCards - form @RequestMapping(method = RequestMethod.GET) public String listForm(Model model, Principal currentUser) { List<PaymentCard> paymentCards = null; if (currentUser != null) { paymentCards = paymentCardService.findPaymentCards(currentUser.getName()); } model.addAttribute("paymentCardList", paymentCards); return "cards/list"; }
// delete a specific PaymentCard - form @RequestMapping(value = "{id}/delete", method = RequestMethod.GET) public String deleteForm(@PathVariable Long id, Model model) { PaymentCard paymentCard; try { paymentCard = paymentCardService.findPaymentCardById(id); } catch (NoResultException e) { return "cards/invalidPaymentCard"; } model.addAttribute(paymentCard); return "cards/delete"; }
// add a paymentCard @RequestMapping(method = RequestMethod.PUT) public String add( @Valid PaymentCard paymentCard, BindingResult bindingResult, Principal currentUser, Model model) { if (bindingResult.hasErrors()) { List<String> types = paymentCardService.getTypes(); model.addAttribute("typeList", types); return "cards/add"; } if (currentUser != null) { paymentCardService.addPaymentCard(paymentCard, currentUser.getName()); String message = "Succesfully added Payment Card " + paymentCard.getNumber() + "."; FlashMap.setSuccessMessage(message); return "redirect:/cards/" + paymentCard.getId(); } else { // TODO: return error return "redirect:/cards/add"; } }