diff --git a/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java b/src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java similarity index 55% rename from src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java rename to src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java index e08931aefed9bbbec3fb30919b1a4d2fda46e735..29e164a001e8017049e7de49396b1981ff4ed579 100644 --- a/src/main/java/Team5/SmartTowns/Organisation/organisationControllers.java +++ b/src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java @@ -1,7 +1,9 @@ package Team5.SmartTowns.Organisation; -import Team5.SmartTowns.business.business; -import Team5.SmartTowns.business.businessRepository; +import Team5.SmartTowns.business.Business; +import Team5.SmartTowns.business.BusinessRepository; +import Team5.SmartTowns.localauthority.LocalAuthority; +import Team5.SmartTowns.localauthority.LocalAuthorityRepository; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.Model; @@ -16,66 +18,86 @@ import org.springframework.stereotype.Controller; import java.util.List; @Controller -public class organisationControllers { - @GetMapping("/localauthorities") +public class OrganisationControllers { + @Autowired + private LocalAuthorityRepository localAuthorityRepository; + + @Autowired + private BusinessRepository businessRepository; + + @GetMapping("/local-authorities") public ModelAndView getLocalAuthoritiesPage(){ - ModelAndView modelAndView = new ModelAndView("local-authorities"); + ModelAndView mav = new ModelAndView("local-authorities"); + List<LocalAuthority> localAuthority = localAuthorityRepository.getAllLocalAuthority(); + mav.addObject("localAuth", localAuthority); + return mav; + } + @GetMapping("/localForm") + public ModelAndView getLocalAuthForm(){ + ModelAndView modelAndView = new ModelAndView("local-auth-data"); + modelAndView.addObject("localAuthority",new LocalAuthority()); return modelAndView; } + + @GetMapping("/businesses") - public ModelAndView getBusinessPage(){ + public ModelAndView getBusinessPage() { ModelAndView modelAndView = new ModelAndView("businesses"); - List<business> business = businessRepository.getAllBusinesses(); + List<Business> business = businessRepository.getAllBusinesses(); modelAndView.addObject("busiSub", business); return modelAndView; } + @GetMapping("/businessSub") - public ModelAndView getBusinessSubPage(){ + public ModelAndView getBusinessSubPage() { ModelAndView modelAndView = new ModelAndView("business-data"); - modelAndView.addObject("business", new business()); + modelAndView.addObject("business", new Business()); return modelAndView; } - @Autowired - private localAuthorityRepository localAuthorityRepository; + @PostMapping("/local-authorities") - public ModelAndView localAuthoritySent(@Valid @ModelAttribute("local-auth-data")localAuthority localAuthority, BindingResult bindingResult, Model model ) { + public ModelAndView localAuthoritySent(@Valid @ModelAttribute("local-auth-data") LocalAuthority localAuthority, BindingResult bindingResult, Model model) { + ModelAndView modelAndView = new ModelAndView("local-authorities"); if (bindingResult.hasErrors()) { - localAuthority loc = new localAuthority(localAuthority.getLocalAuthorityName(), localAuthority.getAddress1(), localAuthority.getAddress2(), localAuthority.getCity(), localAuthority.getCounty(), localAuthority.getPostcode(), localAuthority.getWebsite()); + 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("local-authorities"); - List<localAuthority> localAuthorities = localAuthorityRepository.getAllLocalAuthority(); + List<LocalAuthority> localAuthorities = localAuthorityRepository.getAllLocalAuthority(); modelAndView.addObject("localAuth", localAuthorities); - private businessRepository businessRepository; - @PostMapping("/business-data") - public ModelAndView businessSent(@Valid @ModelAttribute("business-data")business business, BindingResult bindingResult, Model model ) { - if (bindingResult.hasErrors()) { - ModelAndView modelAndView = new ModelAndView("business-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()); + + } else { + 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("local-authorities"); - List<localAuthority> localAuthorities = localAuthorityRepository.getAllLocalAuthority(); + List<LocalAuthority> localAuthorities = localAuthorityRepository.getAllLocalAuthority(); modelAndView.addObject("localAuth", localAuthorities); - } else {// converts user input using the organisation constructor into a submittable format to the sql table + } + return modelAndView; + } + + @PostMapping("/businesses") + public ModelAndView businessSent (@Valid @ModelAttribute("local-auth-data") Business business, BindingResult bindingResult, Model model ){ - business bus = new business(business.getBusinessName(), business.getAddress1(), business.getAddress2(), business.getCity(), business.getCounty(), business.getPostcode(), business.getWebsite()); - System.out.println(bus); + if (bindingResult.hasErrors()) { + ModelAndView modelAndView = new ModelAndView("businesses", model.asMap()); + return modelAndView; + } else { // converts user input using the organisation constructor into a submittable format to the sql table + Business bus = new Business(business.getBusinessName(), business.getAddress1(), business.getAddress2(), business.getCity(), business.getCounty(), business.getPostcode(), business.getWebsite()); businessRepository.addBusiness(bus); //add local authority to local authority table - ModelAndView modelAndView = new ModelAndView("redirect:/businesses"); + ModelAndView modelAndView = new ModelAndView("businesses"); + List<Business> localBusiness = businessRepository.getAllBusinesses(); + modelAndView.addObject("busiSub", localBusiness); return modelAndView; } } - @GetMapping("/consumers") - public ModelAndView getConsumersPage(){ + @GetMapping("/consumers") + public ModelAndView getConsumersPage () { ModelAndView modelAndView = new ModelAndView("WorkWith/consumers.html"); return modelAndView; } @GetMapping("/towns") - public ModelAndView getTownsPage(){ + public ModelAndView getTownsPage () { ModelAndView modelAndView = new ModelAndView("WorkWith/towns.html"); return modelAndView; } diff --git a/src/main/java/Team5/SmartTowns/business/business.java b/src/main/java/Team5/SmartTowns/business/Business.java similarity index 98% rename from src/main/java/Team5/SmartTowns/business/business.java rename to src/main/java/Team5/SmartTowns/business/Business.java index ccb7db134b882e0d0c8c34de836daac2f9932589..b4146e11bf94461089e2f76d5cb77a810ec3774b 100644 --- a/src/main/java/Team5/SmartTowns/business/business.java +++ b/src/main/java/Team5/SmartTowns/business/Business.java @@ -7,7 +7,7 @@ import lombok.NoArgsConstructor; @AllArgsConstructor @NoArgsConstructor @Data -public class business { +public class Business { private String businessName; private String address1; private String address2; diff --git a/src/main/java/Team5/SmartTowns/business/BusinessRepository.java b/src/main/java/Team5/SmartTowns/business/BusinessRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..d98004ccb48ca4b005a5d4c043342a0e1fcca082 --- /dev/null +++ b/src/main/java/Team5/SmartTowns/business/BusinessRepository.java @@ -0,0 +1,8 @@ +package Team5.SmartTowns.business; + +import java.util.List; + +public interface BusinessRepository { + List<Business> getAllBusinesses(); + void addBusiness(Business bus); +} diff --git a/src/main/java/Team5/SmartTowns/business/businessRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/business/BusinessRepositoryJDBC.java similarity index 78% rename from src/main/java/Team5/SmartTowns/business/businessRepositoryJDBC.java rename to src/main/java/Team5/SmartTowns/business/BusinessRepositoryJDBC.java index 0e3073504dc2f58248f44fb501d794e7febb9b62..3752c8bf9f0c24f230a3b1183674554ec758e1e3 100644 --- a/src/main/java/Team5/SmartTowns/business/businessRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/business/BusinessRepositoryJDBC.java @@ -5,18 +5,18 @@ import org.springframework.stereotype.Repository; import java.util.List; @Repository -public class businessRepositoryJDBC implements businessRepository{ +public class BusinessRepositoryJDBC implements BusinessRepository { private JdbcTemplate jdbc; - private RowMapper<business> businessMapper; + private RowMapper<Business> businessMapper; - public businessRepositoryJDBC(JdbcTemplate ajdbc){ + public BusinessRepositoryJDBC(JdbcTemplate ajdbc){ this.jdbc = ajdbc; setbusinessMapper(); } private void setbusinessMapper(){ - businessMapper = (rs, i) -> new business( + businessMapper = (rs, i) -> new Business( rs.getString("businessName"), rs.getString("address1"), rs.getString("address2"), @@ -26,13 +26,13 @@ public class businessRepositoryJDBC implements businessRepository{ rs.getString("website") ); } - public List<business> getAllBusinesses(){ + public List<Business> getAllBusinesses(){ String sql = "SELECT * FROM businesses"; return jdbc.query(sql, businessMapper); } @Override - public void addBusiness(business bus) { + public void addBusiness(Business bus) { String sql = "INSERT INTO businesses( businessName, address1, address2, city, county, postcode, website) values (?, ?, ?, ?, ?, ?, ?)"; jdbc.update(sql, bus.getBusinessName(),bus.getAddress1(),bus.getAddress2(),bus.getCity(),bus.getCounty(),bus.getPostcode(),bus.getWebsite()); } diff --git a/src/main/java/Team5/SmartTowns/business/businessRepository.java b/src/main/java/Team5/SmartTowns/business/businessRepository.java deleted file mode 100644 index dc36607c75d01baaf71b574f32d1f6e10259bca7..0000000000000000000000000000000000000000 --- a/src/main/java/Team5/SmartTowns/business/businessRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package Team5.SmartTowns.business; - -import java.util.List; - -public interface businessRepository { - List<business> getAllBusinesses(); - void addBusiness(business bus); -} diff --git a/src/main/java/Team5/SmartTowns/localauthority/localAuthority.java b/src/main/java/Team5/SmartTowns/localauthority/LocalAuthority.java similarity index 95% rename from src/main/java/Team5/SmartTowns/localauthority/localAuthority.java rename to src/main/java/Team5/SmartTowns/localauthority/LocalAuthority.java index decaa05fc7131343c584bbec024ba2000c236ffd..be01b2c16e4fe13ad1ea444c68143afe547742a5 100644 --- a/src/main/java/Team5/SmartTowns/localauthority/localAuthority.java +++ b/src/main/java/Team5/SmartTowns/localauthority/LocalAuthority.java @@ -4,12 +4,10 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import java.net.URL; - @AllArgsConstructor @NoArgsConstructor @Data -public class localAuthority { +public class LocalAuthority { private String localAuthorityName; private String address1; private String address2; diff --git a/src/main/java/Team5/SmartTowns/localauthority/LocalAuthorityRepository.java b/src/main/java/Team5/SmartTowns/localauthority/LocalAuthorityRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..e2d732d104adff3cef3e738a223f1a921be5b7e9 --- /dev/null +++ b/src/main/java/Team5/SmartTowns/localauthority/LocalAuthorityRepository.java @@ -0,0 +1,9 @@ +package Team5.SmartTowns.localauthority; + +import java.util.List; + +public interface LocalAuthorityRepository { + List<LocalAuthority> getAllLocalAuthority(); + + void addLocalAuthority(LocalAuthority loc); +} diff --git a/src/main/java/Team5/SmartTowns/localauthority/localAuthorityRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/localauthority/LocalAuthorityRepositoryJDBC.java similarity index 76% rename from src/main/java/Team5/SmartTowns/localauthority/localAuthorityRepositoryJDBC.java rename to src/main/java/Team5/SmartTowns/localauthority/LocalAuthorityRepositoryJDBC.java index bdaa4fec44b1936ee45bd464f656e0c4c0a8393e..56aad615c93659cd288b776215571d5cbde36655 100644 --- a/src/main/java/Team5/SmartTowns/localauthority/localAuthorityRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/localauthority/LocalAuthorityRepositoryJDBC.java @@ -7,17 +7,17 @@ import org.springframework.stereotype.Repository; import java.util.List; @Repository -public class localAuthorityRepositoryJDBC implements localAuthorityRepository { +public class LocalAuthorityRepositoryJDBC implements LocalAuthorityRepository { private JdbcTemplate jdbc; - private RowMapper<localAuthority> localAuthorityMapper; + private RowMapper<LocalAuthority> localAuthorityMapper; - public localAuthorityRepositoryJDBC(JdbcTemplate ajdbc){ + public LocalAuthorityRepositoryJDBC(JdbcTemplate ajdbc){ this.jdbc = ajdbc; setlocalauthorityMapper(); } private void setlocalauthorityMapper(){ - localAuthorityMapper = (rs, i) -> new localAuthority( + localAuthorityMapper = (rs, i) -> new LocalAuthority( rs.getString("localAuthorityName"), rs.getString("address1"), rs.getString("address2"), @@ -27,12 +27,12 @@ public class localAuthorityRepositoryJDBC implements localAuthorityRepository { rs.getString("website") ); } - public List<localAuthority> getAllLocalAuthority(){ + public List<LocalAuthority> getAllLocalAuthority(){ String sql = "SELECT * FROM localAuthority"; return jdbc.query(sql, localAuthorityMapper); } @Override - public void addLocalAuthority(localAuthority loc){ + 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/localauthority/localAuthorityRepository.java b/src/main/java/Team5/SmartTowns/localauthority/localAuthorityRepository.java deleted file mode 100644 index 622b0972743ba9536742c3170897cb89b6136851..0000000000000000000000000000000000000000 --- a/src/main/java/Team5/SmartTowns/localauthority/localAuthorityRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package Team5.SmartTowns.localauthority; - -import java.util.List; - -public interface localAuthorityRepository { - List<localAuthority> getAllLocalAuthority(); - - void addLocalAuthority(localAuthority loc); -} diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index e184f1c900c2612a6d2c4992e370ea053d357642..2078cbc3e921010294cbf026c57a689b3ce54657 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -130,4 +130,17 @@ create table if not exists localAuthority website varchar(250) ) engine=InnoDB; +drop table if exists businesses; +create table if not exists businesses +( + businessID bigint auto_increment primary key, + businessName varchar(250), + address1 varchar(250), + address2 varchar(250), + city varchar(100), + county varchar(75), + postcode varchar(15), + website varchar(250) +) engine=InnoDB; + diff --git a/src/main/resources/templates/business-data.html b/src/main/resources/templates/business-data.html index 415bff36be384d23fc1a4489f0c5407c8bbd966c..89923b704fd7b7a3faa3ba7a6fca3f351bd10701 100644 --- a/src/main/resources/templates/business-data.html +++ b/src/main/resources/templates/business-data.html @@ -4,13 +4,13 @@ <meta charset="UTF-8"> <title>Businesses</title> <link rel="stylesheet" th:href="@{css/landmarkFormStyle.css}"> - <link rel="stylesheet" th:href="@{css/templatingstyle.css}"> + <link rel="stylesheet" th:href="@{css/mobile-style.css}"> </head> -<header th:insert="fragments/Templating.html :: header"></header> +<header th:insert="fragments/banners :: header"></header> <body> <div id="container1"> <h2>Enter your Business information</h2> - <form action="/business-data" id="data" name="data" method="post" th:object="${business}"> + <form action="/businesses" id="data" name="data" method="post" th:object="${business}"> <br> <label>Enter your business <input type="text" th:field="*{businessName}"> @@ -37,5 +37,5 @@ </form> </div> </body> -<div th:insert="fragments/Templating.html :: footer"></div> +<div th:insert="fragments/banners :: footer"></div> </html> \ No newline at end of file diff --git a/src/main/resources/templates/businesses.html b/src/main/resources/templates/businesses.html index b9818c7d4f27f95718abd5eddbaa8b83286779ec..29dca7248e8ab3259377151b2ed8c71133950d3c 100644 --- a/src/main/resources/templates/businesses.html +++ b/src/main/resources/templates/businesses.html @@ -5,9 +5,9 @@ <meta charset="UTF-8"> <title>Businesses</title> <link rel="stylesheet" th:href="@{css/landmarkFormStyle.css}"> - <link rel="stylesheet" th:href="@{css/templatingstyle.css}"> + <link rel="stylesheet" th:href="@{css/mobile-style.css}"> </head> -<header th:insert="fragments/Templating.html :: header"></header> +<header th:insert="fragments/banners :: header"></header> <body> <p>A business is an organised establishment in a professional manner in order to achieve your particular aim for owning a business.</p> <h3>Future Proof Businesses</h3> @@ -19,5 +19,5 @@ </ul> <button><a href="/businessSub" id="business">Businesses please enter here</a></button> </body> -<div th:insert="fragments/Templating.html :: footer"></div> +<div th:insert="fragments/banners :: footer"></div> </html> \ No newline at end of file