diff --git a/src/main/java/Team5/SmartTowns/Data/Location.java b/src/main/java/Team5/SmartTowns/Data/Location.java index 01ba2932c6b7d0a6201aa8128161bf7ad8b27526..1e37686e6e198ddf40bb4ca1977402bf9b259f70 100644 --- a/src/main/java/Team5/SmartTowns/Data/Location.java +++ b/src/main/java/Team5/SmartTowns/Data/Location.java @@ -6,7 +6,7 @@ import lombok.Data; @Data @AllArgsConstructor public class Location { -// private int locationID; + private int locationID; private String locationName; private String locationEmail; private String locationDescription; diff --git a/src/main/java/Team5/SmartTowns/Data/localAuthority.java b/src/main/java/Team5/SmartTowns/Data/localAuthority.java new file mode 100644 index 0000000000000000000000000000000000000000..96464b8d70d38f5d28fec51849b5dcec33a4c14b --- /dev/null +++ b/src/main/java/Team5/SmartTowns/Data/localAuthority.java @@ -0,0 +1,58 @@ +package Team5.SmartTowns.Data; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@AllArgsConstructor +@Data +public class localAuthority { + private String localAuthorityName; + private String address1; + private String address2; + private String city; + private String county; + private String postcode; + + @Override + public String toString() { + return "localAuthority{" + + localAuthorityName + '\'' + + address1 + '\'' + + address2 + '\'' + + city + '\'' + + county + '\'' + + postcode + '\'' + + website + + '}'; + } + + public String getLocalAuthorityName() { + return localAuthorityName; + } + + public String getAddress1() { + return address1; + } + + public String getAddress2() { + return address2; + } + + public String getCity() { + return city; + } + + public String getCounty() { + return county; + } + + public String getPostcode() { + return postcode; + } + + public String getWebsite() { + return website; + } + + private String website; +} diff --git a/src/main/java/Team5/SmartTowns/Data/localAuthorityRepository.java b/src/main/java/Team5/SmartTowns/Data/localAuthorityRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..3681d32e48a7533d07375ce4180f8fb53e140b29 --- /dev/null +++ b/src/main/java/Team5/SmartTowns/Data/localAuthorityRepository.java @@ -0,0 +1,9 @@ +package Team5.SmartTowns.Data; + +import java.util.List; + +public interface localAuthorityRepository { + List<localAuthority> getAllLocalAuthority(); + + void addLocalAuthority(localAuthority loc); +} diff --git a/src/main/java/Team5/SmartTowns/Data/localAuthorityRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/Data/localAuthorityRepositoryJDBC.java new file mode 100644 index 0000000000000000000000000000000000000000..293954708ab2afc3ca255209119d0a82fe367632 --- /dev/null +++ b/src/main/java/Team5/SmartTowns/Data/localAuthorityRepositoryJDBC.java @@ -0,0 +1,40 @@ +package Team5.SmartTowns.Data; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public class localAuthorityRepositoryJDBC implements localAuthorityRepository { + private JdbcTemplate jdbc; + private RowMapper<localAuthority> localAuthorityMapper; + + public localAuthorityRepositoryJDBC(JdbcTemplate ajdbc){ + this.jdbc = ajdbc; + setlocalauthorityMapper(); + } + + private void setlocalauthorityMapper(){ + localAuthorityMapper = (rs, i) -> new localAuthority( + rs.getString("localAuthorityName"), + rs.getString("address1"), + rs.getString("address2"), + rs.getString("city"), + rs.getString("county"), + rs.getString("postcode"), + rs.getString("website") + ); + } + public List<localAuthority> getAllLocalAuthority(){ + String sql = "SELECT * FROM localAuthority"; + return jdbc.query(sql, localAuthorityMapper); + } + @Override + public void addLocalAuthority(localAuthority loc){ + String sql = "INSERT INTO localAuthority( localAuthorityName, address1, address2, city, county, postcode, website) values (?, ?, ?, ?, ?, ?, ?)"; + jdbc.update(sql, loc.getLocalAuthorityName(),loc.getAddress1(),loc.getAddress2(),loc.getCity(),loc.getCounty(),loc.getPostcode(),loc.getWebsite()); + } + +} diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepository.java b/src/main/java/Team5/SmartTowns/Data/locationRepository.java index 822a18cb860654694734c7f591cbb5b216eb8a39..874f7fb007467313a1b4362c4efb8593a4b07b33 100644 --- a/src/main/java/Team5/SmartTowns/Data/locationRepository.java +++ b/src/main/java/Team5/SmartTowns/Data/locationRepository.java @@ -1,12 +1,12 @@ //Holds locations data repository (landmarks) -package Team5.SmartTowns.Data; - -import java.util.List; - - -public interface locationRepository { - List<Location> getAllLocation(); - void addLocation(Location loc); - - -} +//package Team5.SmartTowns.Data; +// +//import java.util.List; +// +// +//public interface locationRepository { +// List<Location> getAllLocation(); +// void addLocation(Location loc); +// +// +//} diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java index a5e79d4442d540f5dba67ee7f2b6217984044ebb..014ce1c654b51e850ced5425060c4f8b094f99a1 100644 --- a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java @@ -1,42 +1,42 @@ //Implements the locations repository using JDBC -package Team5.SmartTowns.Data; - -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public class locationRepositoryJDBC implements locationRepository { - private JdbcTemplate jdbc; - private RowMapper<Location> locationMapper; - - public locationRepositoryJDBC(JdbcTemplate aJdbc) { - this.jdbc = aJdbc; - setlocationMapper(); - } - private void setlocationMapper(){ - locationMapper = (rs, i) -> new Location( - - rs.getString("locationName"), - rs.getString("locationEmail"), - rs.getString("locationDescription"), - rs.getString("locationPlace"), - rs.getInt("locationTrailID") - ); - } - public List<Location> getAllLocation(){ - String sql= "SELECT * FROM locations"; - return jdbc.query(sql, locationMapper); - } - - @Override // intended implementation at current: user data from templates/Landmarks/LandmarkFormTh.html is added to the Location table - public void addLocation(Location loc) { - String sql = "insert into locations( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) values (?,?,?,?,?)"; - - jdbc.update(sql,loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID()); - } - - -} +//package Team5.SmartTowns.Data; +// +//import org.springframework.jdbc.core.JdbcTemplate; +//import org.springframework.jdbc.core.RowMapper; +//import org.springframework.stereotype.Repository; +// +//import java.util.List; +// +//@Repository +//public class locationRepositoryJDBC implements locationRepository { +// private JdbcTemplate jdbc; +// private RowMapper<Location> locationMapper; +// +// public locationRepositoryJDBC(JdbcTemplate aJdbc) { +// this.jdbc = aJdbc; +// setlocationMapper(); +// } +// private void setlocationMapper(){ +// locationMapper = (rs, i) -> new Location( +// +// rs.getString("locationName"), +// rs.getString("locationEmail"), +// rs.getString("locationDescription"), +// rs.getString("locationPlace"), +// rs.getInt("locationTrailID") +// ); +// } +// public List<Location> getAllLocation(){ +// String sql= "SELECT * FROM locations"; +// return jdbc.query(sql, locationMapper); +// } +// +// @Override // intended implementation at current: user data from templates/Landmarks/LandmarkFormTh.html is added to the Location table +// public void addLocation(Location loc) { +// String sql = "insert into locations( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) values (?,?,?,?,?)"; +// +// jdbc.update(sql,loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID()); +// } +// +// +//} diff --git a/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java b/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java index b9b1b8e33b09ae4be4fa64d9247a9caa1b8b2001..4040d68e2f583ed064fa1da1c1f1f03362b04638 100644 --- a/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java +++ b/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java @@ -1,16 +1,63 @@ package Team5.SmartTowns.Organisation; +import Team5.SmartTowns.Data.localAuthority; +import Team5.SmartTowns.Data.localAuthorityRepository; +import jakarta.validation.Valid; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.bind.annotation.PostMapping; + import org.springframework.stereotype.Controller; + +import java.util.List; + @Controller public class organisationControllers { @GetMapping("/localauthorities") public ModelAndView getLocalAuthoritiesPage(){ - ModelAndView modelAndView = new ModelAndView("local-authorities"); - return modelAndView; + ModelAndView mav = new ModelAndView("local-authorities"); + List<localAuthority> localAuthority = localAuthorityRepository.getAllLocalAuthority(); + mav.addObject("localAuthority", localAuthority); + return mav; + } + @Autowired + private localAuthorityRepository localAuthorityRepository; + @PostMapping("/localauthsub") + public ModelAndView localAuthSent(@Valid @ModelAttribute("local-auth-data")localAuthority localAuthority, BindingResult bindingResult, Model model ) { + if (bindingResult.hasErrors()){ + ModelAndView modelAndView = new ModelAndView("local-auth-data", 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; + } + } + @GetMapping("/businesses") + public ModelAndView getBusinessesPage(){ + ModelAndView mav1 = new ModelAndView("Businesses"); + return mav1; } + @GetMapping("/towns") + public ModelAndView getTownsPage(){ + ModelAndView mav2 = new ModelAndView("towns"); + return mav2; + } + @GetMapping("/consumers") + public ModelAndView getConsumersPage(){ + ModelAndView mav3 = new ModelAndView("consumers"); + return mav3; + } + + + } diff --git a/src/main/resources/local-auth-data.html b/src/main/resources/local-auth-data.html index 851b2bf26857c3abfd4700bdfb23d89c02cccf1d..5bcc9883cfd7a548c7c75615579b038439961b12 100644 --- a/src/main/resources/local-auth-data.html +++ b/src/main/resources/local-auth-data.html @@ -3,12 +3,13 @@ <head> <meta charset="UTF-8"> <title>Local Authority</title> - <link rel="stylesheet" href="static/css/templatingstyle.css"> -</head> + <link rel="stylesheet" th:href="@{css/landmarkFormStyle.css}"> + <link rel="stylesheet" th:href="@{css/templatingstyle.css}"> + <script src="scripts/landmarkFormThScript.js"></script></head> <body> <div id="container1"> <h2>Enter your Local authority</h2> - <form action="local-auth-data.php" method="post" id="data"> + <form action="/localauthsub" method="post" id="data"> <p> <label for="localAthorityName">Enter your local authority</label> <input type="text" name="authority_name" id="localAthorityName">