From bf8d24cb876b057a627b338bb9cbd29c7437afea Mon Sep 17 00:00:00 2001 From: Rhys Nute <nuterd@cardiff.ac.uk> Date: Wed, 13 Dec 2023 11:29:05 +0000 Subject: [PATCH] updated --- .../SmartTowns/Landmarks/LandmarksController.java | 15 +++++++++++++++ .../Organisation/organisationControllers.java | 4 ++-- src/main/resources/templates/towns.html | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java index a94feef8..59170c2e 100644 --- a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java +++ b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java @@ -55,3 +55,18 @@ public class LandmarksController { } + @Autowired + private localAuthorityRepository localAuthorityRepository; + @PostMapping("/local-auth-data1") + public ModelAndView localAuthSent(@Valid @ModelAttribute("localAuthority")localAuthority localAuthority, BindingResult bindingResult, Model model ) { + if (bindingResult.hasErrors()){ + ModelAndView modelAndView = new ModelAndView("local-auth-data.html", model.asMap()); + return modelAndView; + }else{// converts user input using the organisation constructor into a submittable format to the sql table + + localAuthority loc = new localAuthority(localAuthority.getLocalAuthorityName(), localAuthority.getAddress1(), localAuthority.getAddress2(), localAuthority.getCity(), localAuthority.getCounty(), localAuthority.getPostcode(), localAuthority.getWebsite()); + System.out.println(loc); + localAuthorityRepository.addLocalAuthority(loc); //add local authority to local authority table + ModelAndView modelAndView = new ModelAndView("redirect:/local-authorities"); + return modelAndView; + } diff --git a/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java b/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java index 14bd8685..67c3e981 100644 --- a/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java +++ b/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java @@ -58,14 +58,14 @@ public class organisationControllers { List<addAddTowns> addtowns = addAddTownsRepository.getAllAddTowns(); if (bindingResult.hasErrors()) { - ModelAndView modelAndView = new ModelAndView("towns-data", model.asMap()); + ModelAndView modelAndView = new ModelAndView("towns-data.html", model.asMap()); return modelAndView; } else {// converts user input using the organisation constructor into a submittable format to the sql table addAddTowns tow = new addAddTowns(towns.getTownName(), towns.getAddress1(), towns.getAddress2(), towns.getCity(), towns.getCounty(), towns.getPostcode()); System.out.println(tow); addAddTownsRepository.addTown(tow); //add new towns to Add Towns table - ModelAndView modelAndView = new ModelAndView("redirect:/businesses"); + ModelAndView modelAndView = new ModelAndView("redirect:/towns"); return modelAndView; } } diff --git a/src/main/resources/templates/towns.html b/src/main/resources/templates/towns.html index ac04f7e3..42fe1144 100644 --- a/src/main/resources/templates/towns.html +++ b/src/main/resources/templates/towns.html @@ -3,7 +3,7 @@ <head> <meta charset="UTF-8"> <title>Towns</title> - <link rel="stylesheet" th:href="@{css/addTownsPageStyle.css}"> + <link rel="stylesheet" th:href="@{css/landmarkFormStyle.css}"> <link rel="stylesheet" th:href="@{css/templatingstyle.css}"> </head> <header th:insert="~{/towns/Templating.html::header}"></header> @@ -16,7 +16,7 @@ <li th:text="${towns}"></li> </ul> </div> -<a href="/townForm"><button id="submit">Towns log in here</button></a> +<a href="/townsForm"><button id="submit">Towns log in here</button></a> </body> <footer th:insert="~{/towns/Templating.html::footer}"></footer> </html> \ No newline at end of file -- GitLab