From 2a201d416e869f08db89c4f68d5c2b7d75222ace Mon Sep 17 00:00:00 2001 From: Rhys Nute <nuterd@cardiff.ac.uk> Date: Tue, 12 Dec 2023 17:29:15 +0000 Subject: [PATCH] PP with RE to fix bug issue --- .../Organisation/organisationControllers.java | 13 +++++++++---- .../SmartTowns/localauthority/localAuthority.java | 2 ++ .../{static => templates}/local-auth-data.html | 4 ++-- src/main/resources/templates/local-authorities.html | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) rename src/main/resources/{static => templates}/local-auth-data.html (91%) diff --git a/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java b/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java index 014a86a1..05cfe0ba 100644 --- a/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java +++ b/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java @@ -21,15 +21,20 @@ public class organisationControllers { public ModelAndView getLocalAuthoritiesPage(){ ModelAndView mav = new ModelAndView("local-authorities"); List<localAuthority> localAuthority = localAuthorityRepository.getAllLocalAuthority(); - mav.addObject("localAuthority", localAuthority); return mav; } + @GetMapping("/localForm") + public ModelAndView getLocalAuthForm(){ + ModelAndView modelAndView = new ModelAndView("local-auth-data.html"); + modelAndView.addObject("localAuthority",new localAuthority()); + return modelAndView; + } @Autowired private localAuthorityRepository localAuthorityRepository; - @GetMapping("/local-auth-data") + @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", model.asMap()); + 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 @@ -40,7 +45,7 @@ public class organisationControllers { return modelAndView; } } - @PostMapping + @GetMapping("/businesses") public ModelAndView getBusinessesPage(){ ModelAndView mav1 = new ModelAndView("Businesses"); diff --git a/src/main/java/Team5/SmartTowns/localauthority/localAuthority.java b/src/main/java/Team5/SmartTowns/localauthority/localAuthority.java index 0915dcdd..3a07cde4 100644 --- a/src/main/java/Team5/SmartTowns/localauthority/localAuthority.java +++ b/src/main/java/Team5/SmartTowns/localauthority/localAuthority.java @@ -2,10 +2,12 @@ package Team5.SmartTowns.localauthority; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import java.net.URL; @AllArgsConstructor +@NoArgsConstructor @Data public class localAuthority { private String localAuthorityName; diff --git a/src/main/resources/static/local-auth-data.html b/src/main/resources/templates/local-auth-data.html similarity index 91% rename from src/main/resources/static/local-auth-data.html rename to src/main/resources/templates/local-auth-data.html index abacfb46..3bfcf75d 100644 --- a/src/main/resources/static/local-auth-data.html +++ b/src/main/resources/templates/local-auth-data.html @@ -5,13 +5,13 @@ <title>Local Authority</title> <link rel="stylesheet" th:href="@{css/localAuthortyPageStyle.css}"> - <link rel="stylesheet" th:href="@{css/templatingstyle.css}"> + <link rel="stylesheet" th:href="@{../static/css/templatingstyle.css}"> </head> <header th:insert="~{/towns/Templating.html::header}"></header> <body> <div id="container1"> <h2>Enter your Local authority</h2> - <form action="/local-auth-data" method="post" id="data" object="local-auth-data"> + <form action="/local-auth-data1" method="post" id="data"> <p> <label for="localAuthorityName">Enter your local authority</label> <input type="text" name="authority_name" id="localAuthorityName"> diff --git a/src/main/resources/templates/local-authorities.html b/src/main/resources/templates/local-authorities.html index 43d7e07f..577f8fdc 100644 --- a/src/main/resources/templates/local-authorities.html +++ b/src/main/resources/templates/local-authorities.html @@ -14,7 +14,7 @@ <li th:text="${localauthorities}"></li> </ul> </div> -<button><a href="../static/local-auth-data.html" id="authority">Local Authorities please enter here</a></button> +<button><a href="local-auth-data.html" id="authority">Local Authorities please enter here</a></button> <footer th:insert=/towns/Templating.html::footer></footer> </body> </html> \ No newline at end of file -- GitLab