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

Bugfixing w/ Rhys Nute

parents cc2b827d 8104526e
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 361 additions and 50 deletions
...@@ -32,16 +32,24 @@ public class organisationControllers { ...@@ -32,16 +32,24 @@ public class organisationControllers {
} }
@Autowired @Autowired
private localAuthorityRepository localAuthorityRepository; private localAuthorityRepository localAuthorityRepository;
@PostMapping("/localForm")
@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 ) {
if (bindingResult.hasErrors()) { if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("business-data", model.asMap()); 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();
modelAndView.addObject("localAuth", localAuthorities);
return modelAndView; return modelAndView;
}else{// converts user input using the organisation constructor into a submittable format to the sql table }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()); localAuthority loc = new localAuthority(localAuthority.getLocalAuthorityName(), localAuthority.getAddress1(), localAuthority.getAddress2(), localAuthority.getCity(), localAuthority.getCounty(), localAuthority.getPostcode(), localAuthority.getWebsite());
System.out.println(loc); System.out.println(loc);
localAuthorityRepository.addLocalAuthority(loc); //add local authority to local authority table localAuthorityRepository.addLocalAuthority(loc); //add local authority to local authority table
ModelAndView modelAndView = new ModelAndView("redirect:/localauthority"); ModelAndView modelAndView = new ModelAndView("local-authorities");
List<localAuthority> localAuthorities = localAuthorityRepository.getAllLocalAuthority();
modelAndView.addObject("localAuth", localAuthorities);
return modelAndView; return modelAndView;
} }
} }
......
package Team5.SmartTowns;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class SmartTownsController {
@GetMapping("/")
public ModelAndView getHomePage(){
return new ModelAndView("welcome-page");
}
}
//package Team5.SmartTowns.Data;
//
//import Team5.SmartTowns.users.User;
//import Team5.SmartTowns.users.UserRepository;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.servlet.ModelAndView;
//
//import java.util.*;
//@Controller
//public class DatabaseController {
//
//
// @Autowired
// private LocationRepository LocationRepository;
// @Autowired
// private trailsRepository trailsRepository;
//
//
// @GetMapping("/trailList")
// public ModelAndView trailList() {
// ModelAndView mav1 = new ModelAndView("towns/trailsData");
// List<trail> trail = trailsRepository.getAllTrails();
// mav1.addObject("trails", trail);
// return mav1;
// }
// @GetMapping("locationList")
// public ModelAndView locationList(){
// ModelAndView mav2 = new ModelAndView("towns/locationData");
// List<Location> Locations = LocationRepository.getAllLocation();
// mav2.addObject("location", Locations);
// return mav2;
// }
//}
package Team5.SmartTowns.data; package Team5.SmartTowns.data;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
...@@ -3,16 +3,19 @@ package Team5.SmartTowns.data; ...@@ -3,16 +3,19 @@ package Team5.SmartTowns.data;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class Location { public class Location {
// private int locationID; private long locationID;
private String locationName; private String locationName;
private String locationEmail; private String locationEmail;
private String locationDescription; private String locationDescription;
private String locationPlace; private String locationPlace;
private String locationTrailID; private String locationTrailID;
private boolean locationApproved; private boolean locationApproved;
public Location() { public Location() {
...@@ -51,11 +54,17 @@ public class Location { ...@@ -51,11 +54,17 @@ public class Location {
return locationTrailID; return locationTrailID;
} }
public boolean isLocationApproved() { public boolean isLocationApproved() {
return locationApproved; return locationApproved;
} }
public void setLocationName(String locationName) { public void setLocationName(String locationName) {
this.locationName = locationName; this.locationName = locationName;
} }
......
...@@ -8,8 +8,11 @@ public interface LocationRepository { ...@@ -8,8 +8,11 @@ public interface LocationRepository {
List<Location> getAllLocation(); List<Location> getAllLocation();
void addLocation(Location loc); void addLocation(Location loc);
void updateApprovalStatus(int locID);
List<Location> getAllApprovedLocations(); List<Location> getAllApprovedLocations();
int nametoLocationID(String name);
// List<Location> getApprovedLocations2(List<Location> list); // List<Location> getApprovedLocations2(List<Location> list);
......
...@@ -28,7 +28,7 @@ public class LocationRepositoryJDBC implements LocationRepository { ...@@ -28,7 +28,7 @@ public class LocationRepositoryJDBC implements LocationRepository {
private void setlocationMapper(){ private void setlocationMapper(){
locationMapper = (rs, i) -> new Location( locationMapper = (rs, i) -> new Location(
rs.getLong("locationID"),
rs.getString("locationName"), rs.getString("locationName"),
rs.getString("locationEmail"), rs.getString("locationEmail"),
rs.getString("locationDescription"), rs.getString("locationDescription"),
...@@ -121,6 +121,18 @@ public class LocationRepositoryJDBC implements LocationRepository { ...@@ -121,6 +121,18 @@ public class LocationRepositoryJDBC implements LocationRepository {
// } return locationUnapprovedList; // } return locationUnapprovedList;
// } // }
@Override
public int nametoLocationID(String name){
return jdbc.queryForObject("SELECT locationID FROM locations WHERE locationName=?", Integer.class, name);
}
@Override
public void updateApprovalStatus(int locID){
String updateSql = "update locations set locationApproved = true where locationID = ?";
jdbc.update(updateSql, locID);
}
// return jdbc.queryForObject("SELECT locationApproval FROM locations WHERE locationName=?", locationID);
// public JdbcTemplate getJdbc() { // public JdbcTemplate getJdbc() {
// return jdbc; // return jdbc;
......
//package Team5.SmartTowns.Data;
//
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.util.List;
//
//public class Main {
// @Autowired
// private locationRepository locationRepository;
// List<Location> approvedNumber= locationRepository.approvedLocations();
// public static void main(String[] args) {
// for (Location loc: approvedNumber){}
//
//
// }
//}
package Team5.SmartTowns.data;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import java.util.List;
public class MockUser {
private JdbcTemplate jdbc;
private RowMapper<Trail> trailMapper;
public List<Trail> getAllTrails(){
String sql= "SELECT * FROM trails";
return jdbc.query(sql, trailMapper);
}
}
package Team5.SmartTowns.data;
public class QRCodes {
}
package Team5.SmartTowns.data;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class Town {
private String townName;
private Integer townTrailNumber;
public String getTownName() {
return townName;
}
public Integer getTownTrailNumber() {
return townTrailNumber;
}
}
package Team5.SmartTowns.data;
import java.util.List;
public interface TownRepository {
List<Town> getAllTowns();
void addTown(Town town);
}
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 TownRepositoryJDBC implements TownRepository{
private JdbcTemplate jdbc;
private RowMapper<Town> townMapper;
public TownRepositoryJDBC(JdbcTemplate aJdbc) {
this.jdbc = aJdbc;
setTownMapper();
}
private void setTownMapper(){
townMapper = (rs, i) -> new Town(
rs.getString("townName"),
rs.getInt("townTrailNumber")
);
}
public List<Town> getAllTowns(){
String sql= "SELECT * FROM towns";
return jdbc.query(sql, townMapper);
}
@Override // intended implementation at current: user data from templates/Landmarks/LandmarkFormTh.html is added to the Location table
public void addTown(Town town) {
String sql = "insert into towns( townName,townTrailNumber) values (?,?)";
jdbc.update(sql,town.getTownName(),town.getTownTrailNumber());
}
}
//Holds variable data for the trails table //Holds variable data for the trails table
package Team5.SmartTowns.data; package Team5.SmartTowns.data;
import Team5.SmartTowns.placeswithcoordinates.PlacesCoordinatesRepository;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import java.io.File;
import java.util.List;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class Trail { public class Trail {
private String trailsId; private Long trailsId;
private String trailName; private String trailName;
private String trailNumber; private String trailNumber;
private String imgPath;
public Trail(Long trailsId, String trailName, String trailNumber) {
this.trailsId = trailsId;
this.trailName = trailName;
this.trailNumber = trailNumber;
}
public String getTrailsId() { public Long getTrailsId() {
return trailsId; return trailsId;
} }
...@@ -24,5 +37,19 @@ public class Trail { ...@@ -24,5 +37,19 @@ public class Trail {
return trailNumber; return trailNumber;
} }
public String getTrailLink(){
String[] split = trailName.split(" ");
return String.join("-", split);
}
public String getImagePath(){
/* Finds the image in the Path folder, if image is not found assigns default image */
String imgPath = "images/trails/trail" + trailsId + ".jpg";
String notFoundPath = "images/trails/trailNotFound.jpg";
File imgFile = new File("src/main/resources/static/" + imgPath);
return imgFile.exists() ? imgPath : notFoundPath;
}
} }
...@@ -6,4 +6,8 @@ import java.util.List; ...@@ -6,4 +6,8 @@ import java.util.List;
public interface TrailsRepository { public interface TrailsRepository {
List<Trail> getAllTrails(); List<Trail> getAllTrails();
String getTrailNameWithID(String trailsID); String getTrailNameWithID(String trailsID);
List<Trail> getAllTrailsFromCity(String cityName);
int getTrailIDFromTrailName(String trailsName);
} }
...@@ -17,7 +17,7 @@ public class TrailsRepositoryJDBC implements TrailsRepository { ...@@ -17,7 +17,7 @@ public class TrailsRepositoryJDBC implements TrailsRepository {
} }
private void settrailsMapper(){ private void settrailsMapper(){
trailMapper = (rs, i) -> new Trail( trailMapper = (rs, i) -> new Trail(
rs.getString("trailID"), rs.getLong("trailID"),
rs.getString("trailName"), rs.getString("trailName"),
rs.getString("trailNumber") rs.getString("trailNumber")
); );
...@@ -35,5 +35,16 @@ public class TrailsRepositoryJDBC implements TrailsRepository { ...@@ -35,5 +35,16 @@ public class TrailsRepositoryJDBC implements TrailsRepository {
} }
@Override
public List<Trail> getAllTrailsFromCity(String cityName) {
String sql = "SELECT * FROM trails WHERE city = ?";
return jdbc.query(sql, trailMapper, cityName);
}
@Override
public int getTrailIDFromTrailName(String trailsName){
return jdbc.queryForObject("SELECT trailID FROM trails WHERE trailName=?", Integer.class, trailsName);
}
} }
package Team5.SmartTowns.dragonstale;
import Team5.SmartTowns.landmarks.Landmarks;
import java.util.List;
public class DragonsTale {
Landmarks landmarks = new Landmarks();
private int landmarkID = landmarks.getLandmarkID();
private String landmarkName = landmarks.getLandmarkName();
private String landmarkDescription = landmarks.getLandmarkDescription();
public static List<Landmarks> landmarksDragonstrail = List.of(
new Landmarks( 1, "A scent of...Dragon", "The Dragon has been spotted near by, find the QR code to continue" , "Start your discovery, at the sweet shop."),
new Landmarks( 2, "They've been found!", "Don't let them escape, find the next QR code to continue!", "Location test")
);
public static List<Landmarks> getLandmarksDragonstrail() {
return landmarksDragonstrail;
}
}
package Team5.SmartTowns.dragonstale;
import Team5.SmartTowns.landmarks.Landmarks;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
import static Team5.SmartTowns.dragonstale.DragonsTale.landmarksDragonstrail;
@RestController
public class DragonsTaleController {
ModelAndView modelAndView;
@GetMapping("/dragonstale")
public ModelAndView getDragonsTale(){
List<Landmarks> landmarksList = landmarksDragonstrail;
int landmarksListSize = landmarksDragonstrail.size();
modelAndView = new ModelAndView("/dragonstale/index")
.addObject("landmarksList", landmarksList)
.addObject("getListSize", landmarksListSize);
return modelAndView;
}
@GetMapping ("/QRScan") //In here, we could use trailID as a string variable and use it to track what trail the user clicked from.
public ModelAndView getQRScanner(){
modelAndView = new ModelAndView("fragments/qr-scanner");
//Can we extract the pathvariable in a JS function?
return modelAndView;
}
// @GetMapping("/dragonstale/{landmarkID}")
// public Integer getDTLandmarkID(@RequestParam(value="landmarkID") int landmark){
// Integer idCounter = 0;
// modelAndView = new ModelAndView("/dragonstale/{landmarkID}")
// .addObject() //All your doing is retrieving the information from the database giving it to a string variable.
// }
//Create another controller that directs to the given DragonsTale..Trail.. and updates the users account accordingly.
// This code is to be used
// @GetMapping("dragonstale/{qrCode}/{id}")
// public String qrCodeCheck(@PathVariable Optional<String> qrCode, @PathVariable Optional<Integer> id){
// if (qrCode.isPresent()){
//
// //Check if ID is present, if do this, if not dfo that.
//
// }
// }
}
package Team5.SmartTowns.dragonstale;
import Team5.SmartTowns.users.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DragonsTaleJDBC implements DragonsTaleRepository{
private JdbcTemplate jdbc;
private RowMapper<User> userMapper;
// @Override
// public Map<Long, Boolean> getDTCompletion(int landmarkID){
// //Be conscious of sql injections here.
// String sql = "SELECT userid, trailID, completedOrNot FROM dtprogress WHERE landmarkID = ?";
// int dtQuery = jdbc.query(sql, landmarkID);
// //Query it twice to extract the given parameters, then use these parameters in a loop to query the completion.
// List<Map<String, Integer>> query = jdbc.query(sql, id);
//
// Map<Long, Boolean> dtProgress = new HashMap<>();
// for (Map<String, Object> result : dtQuery) {
// dtProgress.put((Long)result.get("stickerID"), (boolean)result.get("hasSticker"));
// }
// return dtProgress;
// }
}
package Team5.SmartTowns.dragonstale;
public interface DragonsTaleRepository {
}
...@@ -2,6 +2,8 @@ package Team5.SmartTowns.landmarks; ...@@ -2,6 +2,8 @@ package Team5.SmartTowns.landmarks;
import Team5.SmartTowns.data.Location; import Team5.SmartTowns.data.Location;
import Team5.SmartTowns.data.LocationRepository; import Team5.SmartTowns.data.LocationRepository;
import Team5.SmartTowns.placeswithcoordinates.LocationsCoordinates;
import Team5.SmartTowns.placeswithcoordinates.PlacesCoordinatesRepository;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
...@@ -11,14 +13,16 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -11,14 +13,16 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.util.List;
//import jakarta.validation.Valid; //import jakarta.validation.Valid;
@Controller @Controller
public class LandmarksController { public class LandmarksController {
// Controllers for LandmarkFormTh.html landmark submission form // Controllers for LandmarkFormTh.html landmark submission form
@GetMapping("/landmarkSubmission") @GetMapping("/landmarkSubmission")
public ModelAndView landmarkSubmission(){ public ModelAndView landmarkSubmission() {
ModelAndView modelAndView1 = new ModelAndView("Landmarks/LandmarkFormTh.html"); ModelAndView modelAndView1 = new ModelAndView("Landmarks/LandmarkFormTh.html");
modelAndView1.addObject("landmarkData", new Landmarks()); modelAndView1.addObject("landmarkData", new Landmarks());
return modelAndView1; return modelAndView1;
...@@ -27,30 +31,68 @@ public class LandmarksController { ...@@ -27,30 +31,68 @@ public class LandmarksController {
@Autowired @Autowired
private LocationRepository locationRepository; private LocationRepository locationRepository;
@PostMapping("/landmarkSub") @PostMapping("/landmarkSub")
public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model ) { public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model) {
if (bindingResult.hasErrors()) { if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("Landmarks/LandmarkFormTh.html", model.asMap()); ModelAndView modelAndView = new ModelAndView("Landmarks/LandmarkFormTh.html", model.asMap());
return modelAndView; return modelAndView;
} else{ } else {
// converts valid response using Location constructor into a submittable format to the sql table // converts valid response using Location constructor into a submittable format to the sql table
Location loc= new Location(landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID(), false); Location loc = new Location(landmarks.getLandmarkID(), landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID(), false);
locationRepository.addLocation(loc); // adds valid landmark to locations table locationRepository.addLocation(loc); // adds valid landmark to locations table
ModelAndView modelAndView = new ModelAndView("redirect:/home"); ModelAndView modelAndView = new ModelAndView("redirect:/home");
return modelAndView; return modelAndView;
} }
}
@Autowired
private PlacesCoordinatesRepository placesCoordinatesRepo;
// For form that allows an administrator to add an unapproved location to a trail
@GetMapping("/checkpointApproval")
public ModelAndView adminCheckpointApproval() {
List<Location> unapprovedLocations = locationRepository.getAllUnapprovedLocations(); //change to unauthorised once merger 68 accepted!! todo
ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html");
modelAndView.addObject("uLocs", unapprovedLocations);
modelAndView.addObject("location", new Location());
modelAndView.addObject("locationCoord", new LocationsCoordinates());
return modelAndView;
} }
@PostMapping("/checkpointSubmitted")
public ModelAndView checkpointSent(@Valid LocationsCoordinates locCoord, Location location, BindingResult bindingResult, Model model) {
if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html", model.asMap());
return modelAndView;
} else {
int locationID = locationRepository.nametoLocationID(location.getLocationName());
// converts valid response using Location constructor into a submittable format to the sql table
LocationsCoordinates ALocCoord = new LocationsCoordinates(locationID, locCoord.getLocationCoordsLat(), locCoord.getLocationCoordsLong());
boolean checkIfCoorsWithinBoundaries = placesCoordinatesRepo.checkIfCoordsAreWithinTownBoundary(ALocCoord);
if (checkIfCoorsWithinBoundaries==false){ // if coords outside associated town, form is returned to original state
return new ModelAndView("redirect:/checkpointApproval");
}
placesCoordinatesRepo.addLocationCoord(ALocCoord); // adds valid landmark to locations table
locationRepository.updateApprovalStatus(locationID); // updates approval status accordingly
System.out.println(placesCoordinatesRepo.getAllLocationCoords());
ModelAndView modelAndView = new ModelAndView("redirect:/home"); //redirects back top form in case admin wants to input second location
return modelAndView;
// }
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment