diff --git a/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java b/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java index 804b00c5775b3578cfe5bdfd990f6a638ca1b9cb..76d93d7bca0ad409fc2177b28dd5b8f548983a4a 100644 --- a/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java +++ b/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java @@ -33,4 +33,19 @@ public class organisationControllers { ModelAndView modelAndView = new ModelAndView("WorkWith/towns.html"); return modelAndView; } + @Autowired + private addAddTownsRepository addAddTownsRepository; + @PostMapping("/townssub") + public ModelAndView townsSent(@Valid @ModelAttribute("towns-data")Towns towns, BindingResult bindingResult, Model model ) { + if (bindingResult.hasErrors()) { + ModelAndView modelAndView = new ModelAndView("towns-data", model.asMap()); + return modelAndView; + } else {// converts user input using the organisation constructor into a submittable format to the sql table + + Towns tow= new Towns(towns.getTownName(), towns.getAddress1(), towns.getAddress2(), towns.getCity(), towns.getCounty(), towns.getPostcode()); + System.out.println(bus); + addAddTownsRepository.addAddTown(tow); //add new towns to Add Towns table + ModelAndView modelAndView = new ModelAndView("redirect:/businesses"); + return modelAndView; + } } diff --git a/src/main/resources/WorkWith/towns.html b/src/main/resources/WorkWith/towns.html index 71fd80f69801f818d5c2b7bf7f2f1332f504fc04..4b268bd1c67eaf68bdc24e23b6883bbdb7a95b09 100644 --- a/src/main/resources/WorkWith/towns.html +++ b/src/main/resources/WorkWith/towns.html @@ -11,6 +11,11 @@ <p>Giving local businesses a voice in the community</p> <h1>Empowering Community Spirit</h1> <h1>Creating the towns Identity</h1> +<div> + <ul th:each="addAddTowns:${addTown}"> + <li th:text="${addAddTowns}"></li> + </ul> +</div> <button id="submit">Towns log in here</button><a href="towns-data.html"></a> </body> <footer th:insert="~{/towns/Templating.html::footer}"></footer>