Last active
August 6, 2019 13:34
-
-
Save samuelmale/6e30b1f460bec0857f3216e1025f8b25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@PostMapping("safebusiness/addAct/{string}") | |
public String addAct(@Valid Act act, @PathVariable("string") String action, HttpServletRequest httpRequest) { | |
try { | |
// Try parsing id | |
Integer id = Integer.parseInt(action); | |
// If we reach this point, then we must be dealing with an update operation | |
// Pull the existing Act | |
act = actRepo.findById(id); | |
// act.setId(); NOTE : This should not be done while updating | |
Map<String, String[]> formData = httpRequest.getParameterMap(); | |
// Use the formData to get values from form | |
} catch(NumberFormatException ex) { | |
// means we are creating new. | |
} | |
List<Section> sections = APIUtils.parseSectionString(act.getSectionListString(), sectionRepo); | |
for (Section sec : sections) { | |
sec.setAct(act); | |
} | |
// TODO : https://trello.com/c/V3htZorj/16-in-controller-just-append-an-item-to-the-list-instead-of-just-calling-setlistname | |
act.setSections(sections); | |
Act savedAct = actRepo.save(act); | |
if (savedAct != null) { | |
return "redirect:viewAct/" + savedAct.getId(); | |
} | |
return "redirect:safebusiness/index"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment