Skip to content
Snippets Groups Projects

Draft: Businesses

Merged Rhys Nute requested to merge businesses into main
Files
18
package Team5.SmartTowns.Organisation;
import Team5.SmartTowns.business.business;
import Team5.SmartTowns.business.businessRepository;
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.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;
}
@GetMapping("/businesses")
public ModelAndView getBusinessPage(){
ModelAndView modelAndView = new ModelAndView("businesses");
List<business> business = businessRepository.getAllBusinesses();
modelAndView.addObject("busiSub", business);
return modelAndView;
}
@GetMapping("/businessSub")
public ModelAndView getBusinessSubPage(){
ModelAndView modelAndView = new ModelAndView("business-data");
modelAndView.addObject("business", new business());
return modelAndView;
}
@Autowired
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
business bus = new business(business.getBusinessName(), business.getAddress1(), business.getAddress2(), business.getCity(), business.getCounty(), business.getPostcode(), business.getWebsite());
System.out.println(bus);
businessRepository.addBusiness(bus); //add local authority to local authority table
ModelAndView modelAndView = new ModelAndView("redirect:/businesses");
return modelAndView;
}
}
@GetMapping("/consumers")
public ModelAndView getConsumersPage(){
ModelAndView modelAndView = new ModelAndView("WorkWith/consumers.html");
return modelAndView;
}
@GetMapping("/towns")
public ModelAndView getTownsPage(){
ModelAndView modelAndView = new ModelAndView("WorkWith/towns.html");
return modelAndView;
}
}
Loading