@Test public void add() throws Exception { String type = MessageType.REFERRAL_SHARE.toString(); this.mockMvc.perform(post("/messages/{type}/add", type)) .andExpect(redirectAlert("success", "Message added")) .andExpect(redirectedUrl("/messages/" + type)); }
@PostMapping("/messages/{type}/add") public ModelAndView add(WebRequest request, @PathVariable String type, RedirectAttributes redirectAttributes) { MessageDto messageDto = MessageDto.builder() .name(request.getParameter("name")) .type(MessageType.valueOf(type.toUpperCase())) .title(request.getParameter("title")) .description(request.getParameter("description")) .link(request.getParameter("link")) .build(); messageService.add(messageDto); return redirectView(redirectAttributes) .withSuccessMessage("Message added") .url("/messages/" + type) .build(); }
MessagesController extends AbstractController { @PostMapping("/messages/{type}/add") public ModelAndView add(WebRequest request, @PathVariable String type, RedirectAttributes redirectAttributes) { MessageDto messageDto = MessageDto.builder() .name(request.getParameter("name")) .type(MessageType.valueOf(type.toUpperCase())) .title(request.getParameter("title")) .description(request.getParameter("description")) .link(request.getParameter("link")) .build(); messageService.add(messageDto); return redirectView(redirectAttributes) .withSuccessMessage("Message added") .url("/messages/" + type) .build(); } }
MessagesController extends AbstractController { @PostMapping("/messages/{type}/add") public ModelAndView add(WebRequest request, @PathVariable String type, RedirectAttributes redirectAttributes) { MessageDto messageDto = MessageDto.builder() .name(request.getParameter("name")) .type(MessageType.valueOf(type.toUpperCase())) .title(request.getParameter("title")) .description(request.getParameter("description")) .link(request.getParameter("link")) .build(); messageService.add(messageDto); return redirectView(redirectAttributes) .withSuccessMessage("Message added") .url("/messages/" + type) .build(); } MessagesController(final MessageService messageService); }
MessagesController extends AbstractController { @PostMapping("/messages/{type}/add") public ModelAndView add(WebRequest request, @PathVariable String type, RedirectAttributes redirectAttributes) { MessageDto messageDto = MessageDto.builder() .name(request.getParameter("name")) .type(MessageType.valueOf(type.toUpperCase())) .title(request.getParameter("title")) .description(request.getParameter("description")) .link(request.getParameter("link")) .build(); messageService.add(messageDto); return redirectView(redirectAttributes) .withSuccessMessage("Message added") .url("/messages/" + type) .build(); } MessagesController(final MessageService messageService); @RequestMapping("/messages") ModelAndView showAllMessagesPage(final Model model); @RequestMapping("/messages/{type}") ModelAndView showMessagesOfTypePage(final Model model, @PathVariable String type); @RequestMapping("/messages/{type}/add") ModelAndView showAddMessageToTypePage(final Model model, @PathVariable String type); @RequestMapping("/messages/{type}/{name}/edit") ModelAndView showEditPage(final Model model, @PathVariable String type, @PathVariable String name); @PostMapping("/messages/{type}/add") ModelAndView add(WebRequest request, @PathVariable String type, RedirectAttributes redirectAttributes); @PostMapping("/messages/{type}/{name}/edit") ModelAndView update(WebRequest request, @PathVariable String type, @PathVariable String name, RedirectAttributes redirectAttributes); @PostMapping("/messages/{type}/{name}/delete") ModelAndView delete(final Model model, @PathVariable String type, @PathVariable String name, RedirectAttributes redirectAttributes); }
MessagesController extends AbstractController { @PostMapping("/messages/{type}/add") public ModelAndView add(WebRequest request, @PathVariable String type, RedirectAttributes redirectAttributes) { MessageDto messageDto = MessageDto.builder() .name(request.getParameter("name")) .type(MessageType.valueOf(type.toUpperCase())) .title(request.getParameter("title")) .description(request.getParameter("description")) .link(request.getParameter("link")) .build(); messageService.add(messageDto); return redirectView(redirectAttributes) .withSuccessMessage("Message added") .url("/messages/" + type) .build(); } MessagesController(final MessageService messageService); @RequestMapping("/messages") ModelAndView showAllMessagesPage(final Model model); @RequestMapping("/messages/{type}") ModelAndView showMessagesOfTypePage(final Model model, @PathVariable String type); @RequestMapping("/messages/{type}/add") ModelAndView showAddMessageToTypePage(final Model model, @PathVariable String type); @RequestMapping("/messages/{type}/{name}/edit") ModelAndView showEditPage(final Model model, @PathVariable String type, @PathVariable String name); @PostMapping("/messages/{type}/add") ModelAndView add(WebRequest request, @PathVariable String type, RedirectAttributes redirectAttributes); @PostMapping("/messages/{type}/{name}/edit") ModelAndView update(WebRequest request, @PathVariable String type, @PathVariable String name, RedirectAttributes redirectAttributes); @PostMapping("/messages/{type}/{name}/delete") ModelAndView delete(final Model model, @PathVariable String type, @PathVariable String name, RedirectAttributes redirectAttributes);  }