/* * This method will delete an ToDoList by it's SSN value. */ @RequestMapping( value = {"/toDoList/delete/{id}"}, method = RequestMethod.GET) public String deleteToDoList(@PathVariable int id) { service.deleteToDoListById(id); return "redirect:/toDoLists"; }
/* * This method will list all existing ToDoLists. */ @RequestMapping( value = {"/", "/toDoLists"}, method = RequestMethod.GET) public String listToDoLists(ModelMap model) { List<ToDoList> ToDoLists = service.findAllToDoLists(); model.addAttribute("toDoLists", ToDoLists); return "toDoLists/list"; }
/* * This method will provide the medium to update an existing ToDoList. */ @RequestMapping( value = {"/toDoList/{id}"}, method = RequestMethod.GET) public String editToDoList(@PathVariable int id, ModelMap model) { ToDoList toDoList = service.findById(id); model.addAttribute("toDoList", toDoList); model.addAttribute("edit", true); return "toDoLists/form"; }
/* * This method will be called on form submission, handling POST request for * saving ToDoList in database. It also validates the user input */ @RequestMapping( value = {"/toDoList/new"}, method = RequestMethod.POST) public String saveToDoList(@Valid ToDoList toDoList, BindingResult result, ModelMap model) { if (result.hasErrors()) { return "toDoLists/form"; } service.saveToDoList(toDoList); model.addAttribute("success", "ToDoList " + toDoList.getTitle() + " registered successfully"); return "redirect:/toDoLists"; }
/* * This method will be called on form submission, handling POST request for * updating ToDoList in database. It also validates the user input */ @RequestMapping( value = {"/toDoList/{id}"}, method = RequestMethod.POST) public String updateToDoList( @Valid ToDoList toDoList, BindingResult result, ModelMap model, @PathVariable int id) { if (result.hasErrors()) { return "toDoLists/form"; } service.updateToDoList(toDoList); model.addAttribute("success", "ToDoList " + toDoList.getTitle() + " updated successfully"); return "redirect:/toDoLists"; }