Skip to content
Snippets Groups Projects
Commit fe029757 authored by Gabriel Copat's avatar Gabriel Copat
Browse files

Bugfixing w/ Rhys Nute

parent 8e8af969
No related branches found
No related tags found
1 merge request!31Resolve "As a user, I want to see a page of local authorities so that I can easily source contact details for a variety of different local authorities."
Showing with 105 additions and 55 deletions
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;
}
......
......@@ -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;
......
......@@ -2,7 +2,7 @@ package Team5.SmartTowns.business;
import java.util.List;
public interface businessRepository {
List<business> getAllBusinesses();
void addBusiness(business bus);
public interface BusinessRepository {
List<Business> getAllBusinesses();
void addBusiness(Business bus);
}
......@@ -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());
}
......
......@@ -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;
......
......@@ -2,8 +2,8 @@ package Team5.SmartTowns.localauthority;
import java.util.List;
public interface localAuthorityRepository {
List<localAuthority> getAllLocalAuthority();
public interface LocalAuthorityRepository {
List<LocalAuthority> getAllLocalAuthority();
void addLocalAuthority(localAuthority loc);
void addLocalAuthority(LocalAuthority loc);
}
......@@ -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());
}
......
......@@ -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;
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment