Skip to content
Snippets Groups Projects

Draft: Towns

Files

package Team5.SmartTowns.Organisation;
import Team5.SmartTowns.Data.Location;
import Team5.SmartTowns.Data.addAddTownsRepository;
import Team5.SmartTowns.Landmarks.Landmarks;
import Team5.SmartTowns.Towns.Towns;
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.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.Controller;
@Controller
public class organisationControllers {
@GetMapping("/localauthorities")
public ModelAndView getLocalAuthoritiesPage(){
ModelAndView modelAndView = new ModelAndView("WorkWith/local-authorities.html");
return modelAndView;
}
@GetMapping("/businesses")
public ModelAndView getBusinessPage(){
ModelAndView modelAndView = new ModelAndView("WorkWith/business.html");
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;
}
@Autowired
private addAddTownsRepository addAddTownsRepository;
@PostMapping("/townssub")
public ModelAndView townsSent(@Valid @ModelAttribute("towns-data")Towns towns, BindingResult bindingResult, Model model ) {
if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("towns-data", model.asMap());
return modelAndView;
} else {// converts user input using the organisation constructor into a submittable format to the sql table
Towns tow= new Towns(towns.getTownName(), towns.getAddress1(), towns.getAddress2(), towns.getCity(), towns.getCounty(), towns.getPostcode());
System.out.println(bus);
addAddTownsRepository.addAddTown(tow); //add new towns to Add Towns table
ModelAndView modelAndView = new ModelAndView("redirect:/businesses");
return modelAndView;
}
}
Loading