Skip to content
Snippets Groups Projects
Commit 229eb78d authored by Rhys Nute's avatar Rhys Nute
Browse files

rhys

parent 73ff41f9
No related branches found
No related tags found
No related merge requests found
Showing
with 351 additions and 387 deletions
......@@ -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();
......
......@@ -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 +
" ";
}
......
......@@ -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);
}
......@@ -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) {
}
}
......@@ -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;
// }
}
......@@ -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();
......
......@@ -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;
//// }
//
//
//}
......@@ -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;
//
// }
}
}
//
// }
// }
}
......@@ -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;
// }
}
......@@ -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());
}
}
......@@ -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();
......
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
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());
}
}
......@@ -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;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment