diff --git a/src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java b/src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java index 29e164a001e8017049e7de49396b1981ff4ed579..fbf282c2a496ec1f58140f131c865f113ff05400 100644 --- a/src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java +++ b/src/main/java/Team5/SmartTowns/Organisation/OrganisationControllers.java @@ -51,7 +51,8 @@ public class OrganisationControllers { @GetMapping("/businessSub") public ModelAndView getBusinessSubPage() { ModelAndView modelAndView = new ModelAndView("business-data"); - modelAndView.addObject("business", new Business()); + Object businesses = null; + modelAndView.addObject("businessName", null); return modelAndView; } @@ -60,14 +61,14 @@ public class OrganisationControllers { 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.getPostcode()); System.out.println(loc); localAuthorityRepository.addLocalAuthority(loc); //add local authority to local authority table List<LocalAuthority> localAuthorities = localAuthorityRepository.getAllLocalAuthority(); modelAndView.addObject("localAuth", localAuthorities); } else { - 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.getPostcode()); System.out.println(loc); localAuthorityRepository.addLocalAuthority(loc); //add local authority to local authority table List<LocalAuthority> localAuthorities = localAuthorityRepository.getAllLocalAuthority(); diff --git a/src/main/java/Team5/SmartTowns/business/Business.java b/src/main/java/Team5/SmartTowns/business/Business.java index b4146e11bf94461089e2f76d5cb77a810ec3774b..b7c11271c8fae559f3a6302ef9a45ad2c3d429f4 100644 --- a/src/main/java/Team5/SmartTowns/business/Business.java +++ b/src/main/java/Team5/SmartTowns/business/Business.java @@ -16,16 +16,14 @@ public class Business { private String postcode; private String website; + public Business(String businessName, String postcode) { + } + @Override public String toString(){ return "Business:" + " " + businessName + '\'' + " " + - address1 + '\'' + " " + - address2 + '\'' + " " + - city + '\'' + " " + - county + '\'' + " " + postcode + '\'' + " " + - website + " "; } diff --git a/src/main/java/Team5/SmartTowns/business/BusinessRepository.java b/src/main/java/Team5/SmartTowns/business/BusinessRepository.java index d98004ccb48ca4b005a5d4c043342a0e1fcca082..996f33dbeedb66c53af853edfcb8fe2890995403 100644 --- a/src/main/java/Team5/SmartTowns/business/BusinessRepository.java +++ b/src/main/java/Team5/SmartTowns/business/BusinessRepository.java @@ -5,4 +5,6 @@ import java.util.List; public interface BusinessRepository { List<Business> getAllBusinesses(); void addBusiness(Business bus); + + void addBusiness(String testBusinessname, String testEmail, String testPostcode); } diff --git a/src/main/java/Team5/SmartTowns/business/BusinessRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/business/BusinessRepositoryJDBC.java index 3752c8bf9f0c24f230a3b1183674554ec758e1e3..a9eba5504759c2e7cf6eabe995f65472ffd6a0b3 100644 --- a/src/main/java/Team5/SmartTowns/business/BusinessRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/business/BusinessRepositoryJDBC.java @@ -12,18 +12,13 @@ public class BusinessRepositoryJDBC implements BusinessRepository { public BusinessRepositoryJDBC(JdbcTemplate ajdbc){ this.jdbc = ajdbc; - setbusinessMapper(); + setBusinessMapper(); } - private void setbusinessMapper(){ + private void setBusinessMapper(){ businessMapper = (rs, i) -> new Business( rs.getString("businessName"), - rs.getString("address1"), - rs.getString("address2"), - rs.getString("city"), - rs.getString("county"), - rs.getString("postcode"), - rs.getString("website") + rs.getString("postcode") ); } public List<Business> getAllBusinesses(){ @@ -36,6 +31,11 @@ public class BusinessRepositoryJDBC implements BusinessRepository { 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()); } + + @Override + public void addBusiness(String testBusinessname, String testEmail, String testPostcode) { + + } } diff --git a/src/main/java/Team5/SmartTowns/data/Location.java b/src/main/java/Team5/SmartTowns/data/Location.java index e013b0f88572eebe5c8d53da4bb4473516322a67..f34741e93bc401d740d5115b5e21d11be1eccdf8 100644 --- a/src/main/java/Team5/SmartTowns/data/Location.java +++ b/src/main/java/Team5/SmartTowns/data/Location.java @@ -8,17 +8,14 @@ import lombok.NoArgsConstructor; @Data @AllArgsConstructor public class Location { - private long locationID; private String locationName; - private String locationEmail; - private String locationDescription; private String locationPlace; - private String locationTrailID; + public Location() { - private boolean locationApproved; + } - public Location() { + public Location(String landmarkName) { } @@ -26,11 +23,7 @@ public class Location { public String toString() { return "Location{" + locationName + '\'' + - locationEmail + '\'' + - locationDescription + '\'' + locationPlace + '\'' + - locationTrailID + - locationApproved+ '}'; } @@ -38,29 +31,29 @@ public class Location { return locationName; } - public String getLocationEmail() { - return locationEmail; - } - - public String getLocationDescription() { - return locationDescription; - } +// public String getLocationEmail() { +// return locationEmail; +// } +// +// public String getLocationDescription() { +// return locationDescription; +// } public String getLocationPlace() { return locationPlace; } - public String getLocationTrailID() { - return locationTrailID; - } - - - - - - public boolean isLocationApproved() { - return locationApproved; - } +// public String getLocationTrailID() { +// return locationTrailID; +// } +// +// +// +// +// +// public boolean isLocationApproved() { +// return locationApproved; +// } @@ -68,23 +61,23 @@ public class Location { this.locationName = locationName; } - public void setLocationEmail(String locationEmail) { - this.locationEmail = locationEmail; - } - - public void setLocationDescription(String locationDescription) { - this.locationDescription = locationDescription; - } +// public void setLocationEmail(String locationEmail) { +// this.locationEmail = locationEmail; +// } +// +// public void setLocationDescription(String locationDescription) { +// this.locationDescription = locationDescription; +// } public void setLocationPlace(String locationPlace) { this.locationPlace = locationPlace; } - public void setLocationTrailID(String locationTrailID) { - this.locationTrailID = locationTrailID; - } - - public void setLocationApproved(boolean locationApproved) { - this.locationApproved = locationApproved; - } +// public void setLocationTrailID(String locationTrailID) { +// this.locationTrailID = locationTrailID; +// } +// +// public void setLocationApproved(boolean locationApproved) { +// this.locationApproved = locationApproved; +// } } diff --git a/src/main/java/Team5/SmartTowns/data/LocationRepository.java b/src/main/java/Team5/SmartTowns/data/LocationRepository.java index da6f1183ea7cd7b472ba69192d57d43c0ec15139..251c0a714528500248f4b973797d13fd05bc8217 100644 --- a/src/main/java/Team5/SmartTowns/data/LocationRepository.java +++ b/src/main/java/Team5/SmartTowns/data/LocationRepository.java @@ -8,15 +8,15 @@ public interface LocationRepository { List<Location> getAllLocation(); void addLocation(Location loc); - void updateApprovalStatus(int locID); - - - List<Location> getAllApprovedLocations(); - int nametoLocationID(String name); +// void updateApprovalStatus(int locID); +// +// +// List<Location> getAllApprovedLocations(); +// int nametoLocationID(String name); // List<Location> getApprovedLocations2(List<Location> list); - List<Location> getAllUnapprovedLocations(); +// List<Location> getAllUnapprovedLocations(); // List<Location> approvedLocations(); diff --git a/src/main/java/Team5/SmartTowns/data/LocationRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/data/LocationRepositoryJDBC.java index 8ab41dc4589a5ee0a49021c105f31ed40d869546..3f7ed02d9cf22bd08b4fa524431af846afd98cf8 100644 --- a/src/main/java/Team5/SmartTowns/data/LocationRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/data/LocationRepositoryJDBC.java @@ -10,7 +10,7 @@ import java.util.List; @Repository public class LocationRepositoryJDBC implements LocationRepository { - private JdbcTemplate jdbc; + private JdbcTemplate jdbc; private RowMapper<Location> locationMapper; public LocationRepositoryJDBC(JdbcTemplate aJdbc) { @@ -26,55 +26,57 @@ public class LocationRepositoryJDBC implements LocationRepository { // } - private void setlocationMapper(){ + private void setlocationMapper() { locationMapper = (rs, i) -> new Location( - rs.getLong("locationID"), rs.getString("locationName"), - rs.getString("locationEmail"), - rs.getString("locationDescription"), - rs.getString("locationPlace"), - rs.getString("locationTrailID"), - rs.getBoolean("locationApproved") + rs.getString("locationPlace") ); } - public List<Location> getAllLocation(){ - String sql= "SELECT * FROM locations"; + + public List<Location> getAllLocation() { + String sql = "SELECT * FROM locations"; return jdbc.query(sql, locationMapper); } - @Override - public List<Location> getAllApprovedLocations(){ - String sql= "SELECT * FROM locations"; - List<Location> lis = jdbc.query(sql, locationMapper); - List<Location> lisFiltered = new ArrayList<>(); - for (Location li : lis){ - if (li.isLocationApproved()){ - lisFiltered.add(li); - } - } - return lisFiltered; - } + public void addLocation(Location loc) { - @Override - public List<Location> getAllUnapprovedLocations(){ - String sql= "SELECT * FROM locations"; - List<Location> lis = jdbc.query(sql, locationMapper); - List<Location> lisFiltered = new ArrayList<>(); - for (Location li : lis){ - if (!li.isLocationApproved()){ - lisFiltered.add(li); - } - } - return lisFiltered; } +} - @Override // intended implementation at current: user data from templates/Landmarks/LandmarkFormTh.html is added to the Location table - public void addLocation(Location loc) { - String sql = "insert into locations( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values (?,?,?,?,?,?)"; - jdbc.update(sql,loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID(), false); - } +// @Override +// public List<Location> getAllApprovedLocations(){ +// String sql= "SELECT * FROM locations"; +// List<Location> lis = jdbc.query(sql, locationMapper); +// List<Location> lisFiltered = new ArrayList<>(); +// for (Location li : lis){ +// if (li.isLocationApproved()){ +// lisFiltered.add(li); +// } +// } +// return lisFiltered; +// } +// +// @Override +// public List<Location> getAllUnapprovedLocations(){ +// String sql= "SELECT * FROM locations"; +// List<Location> lis = jdbc.query(sql, locationMapper); +// List<Location> lisFiltered = new ArrayList<>(); +// for (Location li : lis){ +// if (!li.isLocationApproved()){ +// lisFiltered.add(li); +// } +// } +// return lisFiltered; +// } +// +// @Override // intended implementation at current: user data from templates/Landmarks/LandmarkFormTh.html is added to the Location table +// public void addLocation(Location loc) { +// String sql = "insert into locations( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) values (?,?,?,?,?,?)"; +// +// jdbc.update(sql,loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID(), false); +// } // @Override // public List<Location> getApprovedLocations(){ @@ -112,22 +114,22 @@ public class LocationRepositoryJDBC implements LocationRepository { // } 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() { -// return jdbc; +// @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() { +//// return jdbc; +//// } +// +// +//} diff --git a/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java b/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java index 773fe4e95e0f689bd398736d2f848ae602ed53a3..e19aa0253cc5355c6b8353970e81c48830722ae2 100644 --- a/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java +++ b/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java @@ -42,7 +42,7 @@ public class LandmarksController { } else { // converts valid response using Location constructor into a submittable format to the sql table - Location loc = new Location(landmarks.getLandmarkID(), landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID(), false); + Location loc = new Location(landmarks.getLandmarkName()); locationRepository.addLocation(loc); // adds valid landmark to locations table ModelAndView modelAndView = new ModelAndView("redirect:/home"); return modelAndView; @@ -51,49 +51,49 @@ public class LandmarksController { } - @Autowired - private PlacesCoordinatesRepository placesCoordinatesRepo; +// @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 - System.out.println(locCoord.getLocationCoordsLong()); - 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?error"); - } - 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:/mobile-home"); //redirects back top form in case admin wants to input second location - return modelAndView; - +// @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 +// System.out.println(locCoord.getLocationCoordsLong()); +// 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?error"); +// } +// 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:/mobile-home"); //redirects back top form in case admin wants to input second location +// return modelAndView; +// // } - - } - } +// +// } +// } } diff --git a/src/main/java/Team5/SmartTowns/localauthority/LocalAuthority.java b/src/main/java/Team5/SmartTowns/localauthority/LocalAuthority.java index be01b2c16e4fe13ad1ea444c68143afe547742a5..1e921d2300083e0f8a4a9d5473671dea94d2a777 100644 --- a/src/main/java/Team5/SmartTowns/localauthority/LocalAuthority.java +++ b/src/main/java/Team5/SmartTowns/localauthority/LocalAuthority.java @@ -9,22 +9,12 @@ import lombok.NoArgsConstructor; @Data public class LocalAuthority { private String localAuthorityName; - private String address1; - private String address2; - private String city; - private String county; private String postcode; - private String website; @Override public String toString() { return "Local Authority:" + " " + localAuthorityName + '\'' + " " + - address1 + '\'' + " " + - address2 + '\'' + " " + - city + '\'' + " " + - county + '\'' + " " + postcode + '\'' + " " + - website + " "; } @@ -32,25 +22,25 @@ public class LocalAuthority { return localAuthorityName; } - public String getAddress1() { return address1; } - - public String getAddress2() { - return address2; - } - - public String getCity() { - return city; - } - - public String getCounty() { - return county; - } +// public String getAddress1() { return address1; } +// +// public String getAddress2() { +// return address2; +// } +// +// public String getCity() { +// return city; +// } +// +// public String getCounty() { +// return county; +// } public String getPostcode() { return postcode; } - public String getWebsite() { - return website; - } +// public String getWebsite() { +// return website; +// } } diff --git a/src/main/java/Team5/SmartTowns/localauthority/LocalAuthorityRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/localauthority/LocalAuthorityRepositoryJDBC.java index 56aad615c93659cd288b776215571d5cbde36655..e603841ca67fd754775fbe4e259d7f2f0f698a12 100644 --- a/src/main/java/Team5/SmartTowns/localauthority/LocalAuthorityRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/localauthority/LocalAuthorityRepositoryJDBC.java @@ -19,12 +19,7 @@ public class LocalAuthorityRepositoryJDBC implements LocalAuthorityRepository { private void setlocalauthorityMapper(){ localAuthorityMapper = (rs, i) -> new LocalAuthority( rs.getString("localAuthorityName"), - rs.getString("address1"), - rs.getString("address2"), - rs.getString("city"), - rs.getString("county"), - rs.getString("postcode"), - rs.getString("website") + rs.getString("postcode") ); } public List<LocalAuthority> getAllLocalAuthority(){ @@ -33,8 +28,8 @@ public class LocalAuthorityRepositoryJDBC implements LocalAuthorityRepository { } @Override 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()); + String sql = "INSERT INTO localAuthority( localAuthorityName, postcode) values (?, ?)"; + jdbc.update(sql, loc.getLocalAuthorityName(), loc.getPostcode()); } } diff --git a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java index f70cabeb917ad1d34537f9799d4f87f26aa0bb0e..06ab95796c9c99c3b6c06e69c037667afa483f68 100644 --- a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java +++ b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java @@ -98,102 +98,102 @@ public class PlacesController { - @GetMapping("/checkpoints") - public ModelAndView getLocationPages(){ - ModelAndView modelAndView = new ModelAndView("landmarks/locationPage.html"); - List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); - List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); - - modelAndView.addObject("location", approvedLocations); - modelAndView.addObject("locationCoords", reorderCoordsWRTLocations(locCoords)); - return modelAndView; - } - - @RequestMapping(value="/location", method= RequestMethod.POST) - public String sendHtmlFragmentLocation(Model map) { - map.addAttribute("foo", "bar"); - return "checkpoint/checkpoint"; - } - - - - - @GetMapping("/checkpoints/{location}") - public ModelAndView getResultBySearchKeyLocation(@PathVariable String location) { - List<LocationsCoordinates> locCoords = reorderCoordsWRTLocations(placeRepo.getAllLocationCoords()); - List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); - - int locationID = 999; - for (int i=0;i<approvedLocations.size();i++){ - if ( (approvedLocations.get(i).getLocationName().replace(' ', '-').trim().equals(location)) ){ - locationID= i; - } - } +// @GetMapping("/checkpoints") +// public ModelAndView getLocationPages(){ +// ModelAndView modelAndView = new ModelAndView("landmarks/locationPage.html"); +// List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); +// List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); +// +// modelAndView.addObject("location", approvedLocations); +// modelAndView.addObject("locationCoords", reorderCoordsWRTLocations(locCoords)); +// return modelAndView; +// } - String trailName=trailsRepo.getTrailNameWithID(approvedLocations.get(locationID).getLocationTrailID()).replace(' ', '-').trim(); - ModelAndView modelAndView= new ModelAndView("fragments/locationPageFrags :: locationSection"); - modelAndView.addObject("locCoord", locCoords.get(locationID)); - modelAndView.addObject("trail", trailName); - modelAndView.addObject("location", approvedLocations.get(locationID)); - return modelAndView; - } +// @RequestMapping(value="/location", method= RequestMethod.POST) +// public String sendHtmlFragmentLocation(Model map) { +// map.addAttribute("foo", "bar"); +// return "checkpoint/checkpoint"; +// } +// +// +// +// +// @GetMapping("/checkpoints/{location}") +// public ModelAndView getResultBySearchKeyLocation(@PathVariable String location) { +// List<LocationsCoordinates> locCoords = reorderCoordsWRTLocations(placeRepo.getAllLocationCoords()); +// List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); +// +// int locationID = 999; +// for (int i=0;i<approvedLocations.size();i++){ +// if ( (approvedLocations.get(i).getLocationName().replace(' ', '-').trim().equals(location)) ){ +// locationID= i; +// } +// } +// +// String trailName=trailsRepo.getTrailNameWithID(approvedLocations.get(locationID).getLocationTrailID()).replace(' ', '-').trim(); +// ModelAndView modelAndView= new ModelAndView("fragments/locationPageFrags :: locationSection"); +// modelAndView.addObject("locCoord", locCoords.get(locationID)); +// modelAndView.addObject("trail", trailName); +// modelAndView.addObject("location", approvedLocations.get(locationID)); +// return modelAndView; +// } /// Trail webpage mapping - @GetMapping("/trails") - public ModelAndView getTrailsPage(){ - ModelAndView modelAndView = new ModelAndView("landmarks/trailsPage.html"); - List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); - List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); - List<Trail> trailslocations = trailsRepo.getAllTrails(); - List<Location> locationCoordsWorkaround = new ArrayList<Location>(); - - modelAndView.addObject("trails", trailslocations); - modelAndView.addObject("locations", approvedLocations); - modelAndView.addObject("locationCoords", reorderCoordsWRTLocations(locCoords)); - return modelAndView; - } - - @RequestMapping(value="/trail", method= RequestMethod.POST) - public String sendHtmlFragmentTrail(Model map) { - map.addAttribute("foo", "bar"); - return "trail/trail"; - } - - @GetMapping("/trails/{trail}") - public ModelAndView getResultBySearchKeyTrails(@PathVariable String trail) { - List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); - List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); - List<Trail> trailslocations = trailsRepo.getAllTrails(); - int trailID = 999;// otherwise cases errors e.g. null used. 999 unlikely to be used so safe until then - for (int i=0;i<trailslocations.size();i++){ - - if (trailslocations.get(i).getTrailName().replace(' ', '-').trim().equals(trail)){ - trailID=i; - break;} - } - ModelAndView modelAndView= new ModelAndView("fragments/trailsPageFrags :: trailsSection"); - System.out.println(locCoords.get(0).getLocationID()); - System.out.println(approvedLocations.get(0).getLocationID()); -// locations[indexValue.index].getLocationTrailID()==trail.getTrailsId()} - - - final int trailIDFINAL = trailID; - List<Location> finalLocations = approvedLocations.stream() - .filter(loc -> Long.parseLong(loc.getLocationTrailID()) == trailslocations.get(trailIDFINAL).getTrailsId()) - .toList(); - System.out.println(finalLocations); - - modelAndView.addObject("trail", trailslocations.get(trailID)); - modelAndView.addObject("locCoords", locCoords); - modelAndView.addObject("locations", finalLocations); - - modelAndView.addObject("stickers", rewardsRepository.getAllStickersFromPack(1)); - return modelAndView; - } +// @GetMapping("/trails") +// public ModelAndView getTrailsPage(){ +// ModelAndView modelAndView = new ModelAndView("landmarks/trailsPage.html"); +// List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); +// List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); +// List<Trail> trailslocations = trailsRepo.getAllTrails(); +// List<Location> locationCoordsWorkaround = new ArrayList<Location>(); +// +// modelAndView.addObject("trails", trailslocations); +// modelAndView.addObject("locations", approvedLocations); +// modelAndView.addObject("locationCoords", reorderCoordsWRTLocations(locCoords)); +// return modelAndView; +// } +// +// @RequestMapping(value="/trail", method= RequestMethod.POST) +// public String sendHtmlFragmentTrail(Model map) { +// map.addAttribute("foo", "bar"); +// return "trail/trail"; +// } +// +// @GetMapping("/trails/{trail}") +// public ModelAndView getResultBySearchKeyTrails(@PathVariable String trail) { +// List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); +// List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); +// List<Trail> trailslocations = trailsRepo.getAllTrails(); +// int trailID = 999;// otherwise cases errors e.g. null used. 999 unlikely to be used so safe until then +// for (int i=0;i<trailslocations.size();i++){ +// +// if (trailslocations.get(i).getTrailName().replace(' ', '-').trim().equals(trail)){ +// trailID=i; +// break;} +// } +// ModelAndView modelAndView= new ModelAndView("fragments/trailsPageFrags :: trailsSection"); +// System.out.println(locCoords.get(0).getLocationID()); +// System.out.println(approvedLocations.get(0).getLocationID()); +//// locations[indexValue.index].getLocationTrailID()==trail.getTrailsId()} +// +// +// final int trailIDFINAL = trailID; +// List<Location> finalLocations = approvedLocations.stream() +// .filter(loc -> Long.parseLong(loc.getLocationTrailID()) == trailslocations.get(trailIDFINAL).getTrailsId()) +// .toList(); +// System.out.println(finalLocations); +// +// modelAndView.addObject("trail", trailslocations.get(trailID)); +// modelAndView.addObject("locCoords", locCoords); +// modelAndView.addObject("locations", finalLocations); +// +// modelAndView.addObject("stickers", rewardsRepository.getAllStickersFromPack(1)); +// return modelAndView; +// } // public List<LocationsCoordinates> reorderCoordsWRTLocations(List<LocationsCoordinates> locCoords){ // List<Location> approvedList = locationRepo.getAllLocation(); //// List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); diff --git a/src/test/java/Team5/SmartTowns/users/UserTests.java b/src/test/java/Team5/SmartTowns/users/UserTests.java deleted file mode 100644 index 5abc6d4551fed61a5427a02650cbf56318d1d2f2..0000000000000000000000000000000000000000 --- a/src/test/java/Team5/SmartTowns/users/UserTests.java +++ /dev/null @@ -1,95 +0,0 @@ -package Team5.SmartTowns.users; - -import org.junit.jupiter.api.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.test.context.jdbc.Sql; - -import javax.sql.DataSource; -import java.util.Arrays; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -@DisplayName("User Database Operations") -@SpringBootTest -class UserTests { - - @Autowired - UserRepository userRepository; - - @Autowired - JdbcTemplate jdbcTemplate; - - - @BeforeEach - public void resetUserTable(){ - /*Deletes table as each test creates the table it needs for its own testing*/ - jdbcTemplate.update("DELETE FROM users"); - } - - @Test - @DisplayName("Add User to Database") - void testAddUser() { - String testEmail = "TestEmail"; - String testPassword = "Password"; - String testUsername = "TestUsername"; - - userRepository.addUser(testUsername, testEmail, testPassword); - - String email = jdbcTemplate.queryForObject("SELECT email FROM users WHERE username=?", String.class, testUsername); - String password = jdbcTemplate.queryForObject("SELECT password FROM users WHERE username=?", String.class, testUsername); - - assertEquals(testPassword, password); - assertEquals(testEmail, email); - - } - - @Test - @DisplayName("Get all from Users") - void testGetAllUsers() { - jdbcTemplate.update("INSERT INTO users (username, password) VALUE ('TestUser1', 'admin')"); - jdbcTemplate.update("INSERT INTO users (username, password) VALUE ('TestUser2', 'admin')"); - jdbcTemplate.update("INSERT INTO users (username, password) VALUE ('TestUser3', 'admin')"); - - List<String> queryList = jdbcTemplate.queryForList("SELECT username FROM users", String.class); - List<User> users = userRepository.getAllUsers(); - - assertEquals(queryList.size(), users.size()); - } - - - @Test - @DisplayName("Find if user exists") - void doesUserExist() { - jdbcTemplate.update("INSERT INTO users (username, email, password) VALUE ('UserExists', 'email@test.com', 'test')" ); - assertTrue( userRepository.doesUserExist("email@test.com") ); - assertFalse( userRepository.doesUserExist("user@doesnot.exist")); - } - - @Test - @DisplayName("Find user by email") - void findUserByEmail() { - String email = "email@test.com"; - jdbcTemplate.update("INSERT INTO users (username, email, password) VALUE ('UserExists', ?, 'test')", - email); - User user = userRepository.findUserByEmail(email); - assertEquals(email, user.getEmail()); - } - - @Test - @DisplayName("Find user by name") - void findUserByName() { - String name = "TestUser"; - jdbcTemplate.update("INSERT INTO users (username, password) VALUE (?, 'test')", - name); - User user = userRepository.findUserByName(name); - assertEquals(name, user.getName()); - assertNull(userRepository.findUserByName("Jack")); - } -} \ No newline at end of file diff --git a/src/test/java/Team5/SmartTowns/users/rhysTests.java b/src/test/java/Team5/SmartTowns/users/rhysTests.java new file mode 100644 index 0000000000000000000000000000000000000000..27a9c68b57618483f5be00f8aadb1d1ed51e1836 --- /dev/null +++ b/src/test/java/Team5/SmartTowns/users/rhysTests.java @@ -0,0 +1,70 @@ +package Team5.SmartTowns.users; + +import Team5.SmartTowns.business.Business; +import Team5.SmartTowns.business.BusinessRepository; +import Team5.SmartTowns.data.Location; +import Team5.SmartTowns.data.LocationRepository; +import Team5.SmartTowns.localauthority.LocalAuthority; +import Team5.SmartTowns.localauthority.LocalAuthorityRepository; +import org.junit.jupiter.api.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@DisplayName("User Database Operations") +@SpringBootTest +class rhysTests { + + @Autowired + BusinessRepository businessRepository; + @Autowired + LocalAuthorityRepository localAuthorityRepository; + @Autowired + LocationRepository locationRepository; + @Autowired + JdbcTemplate jdbcTemplate; + + + @Test + @DisplayName("Get all from Businesses") + void testGetAllBusinesses() { + jdbcTemplate.update("INSERT INTO businesses (businessname, postcode) VALUE ('TestBusiness1', 'NP11 6GN')"); + jdbcTemplate.update("INSERT INTO businesses (businessname, postcode) VALUE ('TestBusiness2', 'NP11 6GN')"); + jdbcTemplate.update("INSERT INTO businesses (businessname, postcode) VALUE ('TestBusiness3', 'NP11 6GN')"); + + List<String> queryList = jdbcTemplate.queryForList("SELECT businessname FROM businesses", String.class); + List<Business> businesses = businessRepository.getAllBusinesses(); + + assertEquals(queryList.size(), businesses.size()); + } + + @Test + @DisplayName("Get all from Local Authority") + void testGetAllLocalAuthorities() { + jdbcTemplate.update("INSERT INTO localAuthority (localAuthorityName, postcode) VALUE ('TestLocalAuth1', 'CF82 7PG')"); + jdbcTemplate.update("INSERT INTO localAuthority (localAuthorityName, postcode) VALUE ('TestLocalAuth2', 'CF82 7PG')"); + jdbcTemplate.update("INSERT INTO localAuthority (localAuthorityName, postcode) VALUE ('TestLocalAuth3', 'CF82 7PG')"); + + List<String> queryList = jdbcTemplate.queryForList("SELECT localAuthorityName FROM localAuthority", String.class); + List<LocalAuthority> localAuthorities = localAuthorityRepository.getAllLocalAuthority(); + + assertEquals(queryList.size(), localAuthorities.size()); + } + @Test + @DisplayName("Get all from Locations") + void testGetAllLocations() { + jdbcTemplate.update("INSERT INTO locations (locationName, locationPlace) VALUE ('TestLocation1', 'TestPlace1')"); + jdbcTemplate.update("INSERT INTO locations (locationName, locationPlace) VALUE ('TestLocation2', 'TestPlace2')"); + jdbcTemplate.update("INSERT INTO locations (locationName, locationPlace) VALUE ('TestLocation3', 'TestPlace3')"); + + List<String> queryList = jdbcTemplate.queryForList("SELECT locationName FROM locations", String.class); + List<Location> locations = locationRepository.getAllLocation(); + + assertEquals(queryList.size(), locations.size()); + } +} diff --git a/src/test/resources/schema.sql b/src/test/resources/schema.sql index 556efd547a20624b9b9d02980ea5010d2cc966ac..5e9f049b7d1ceea6fe3a01105525d7c8ffb5657b 100644 --- a/src/test/resources/schema.sql +++ b/src/test/resources/schema.sql @@ -2,16 +2,24 @@ DROP DATABASE IF EXISTS test_towns; CREATE DATABASE IF NOT EXISTS test_towns; USE test_towns; -CREATE TABLE IF NOT EXISTS users ( - username varchar(30) primary key NOT NULL, +CREATE TABLE IF NOT EXISTS businesses ( + businessname varchar(30) primary key NOT NULL, id bigint auto_increment unique, /*DEPRECATED COLUMN, LEFT IN WHILE SOME OTHER FUNCTIONS STILL USE IT*/ email varchar(128), - password varchar(30) NOT NULL, + postcode varchar(30) NOT NULL, enabled boolean default true )engine=InnoDB; -CREATE TABLE IF NOT EXISTS authorities ( - id bigint primary key auto_increment NOT NULL, - username varchar(30) NOT NULL , - authority varchar(45) NOT NULL -)engine=InnoDB; \ No newline at end of file +CREATE TABLE IF NOT EXISTS localAuthority +( + localAuthorityID bigint auto_increment primary key, + localAuthorityName varchar(250), + postcode varchar(15) +) engine=InnoDB; + +CREATE TABLE IF NOT EXISTS locations +( + locationID bigint auto_increment primary key, + locationName varchar(128), + locationPlace varchar(255) +) engine=InnoDB;