diff --git a/src/main/java/Team5/SmartTowns/data/Location.java b/src/main/java/Team5/SmartTowns/data/Location.java index d833db114ef53492fb99ab9f12b863bcd78177a5..760f37c205f31e28189ded51dfce28f5b451687f 100644 --- a/src/main/java/Team5/SmartTowns/data/Location.java +++ b/src/main/java/Team5/SmartTowns/data/Location.java @@ -11,7 +11,7 @@ public class Location { private String locationEmail; private String locationDescription; private String locationPlace; - private int locationTrailID; + private String locationTrailID; private boolean locationApproved; @@ -47,11 +47,36 @@ public class Location { return locationPlace; } - public int getLocationTrailID() { + public String getLocationTrailID() { return locationTrailID; } public boolean isLocationApproved() { return locationApproved; } + + + public void setLocationName(String locationName) { + this.locationName = locationName; + } + + 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; + } } diff --git a/src/main/java/Team5/SmartTowns/data/LocationRepository.java b/src/main/java/Team5/SmartTowns/data/LocationRepository.java index 1d896aab751dd096ad717fefaa384df7e1ea4fed..cbc980a816f339bae030bd1848d26c34d2376670 100644 --- a/src/main/java/Team5/SmartTowns/data/LocationRepository.java +++ b/src/main/java/Team5/SmartTowns/data/LocationRepository.java @@ -9,11 +9,11 @@ public interface LocationRepository { void addLocation(Location loc); - List<Location> getApprovedLocations(); + List<Location> getAllApprovedLocations(); // List<Location> getApprovedLocations2(List<Location> list); - List<Location> getUnapprovedLocations(); + 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 77efb4d5a772a1f22efe94c6e20eb46586ce111b..457366e8caa54f63f2b18011231a99c600753caa 100644 --- a/src/main/java/Team5/SmartTowns/data/LocationRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/data/LocationRepositoryJDBC.java @@ -33,7 +33,7 @@ public class LocationRepositoryJDBC implements LocationRepository { rs.getString("locationEmail"), rs.getString("locationDescription"), rs.getString("locationPlace"), - rs.getInt("locationTrailID"), + rs.getString("locationTrailID"), rs.getBoolean("locationApproved") ); } @@ -52,24 +52,50 @@ public class LocationRepositoryJDBC implements LocationRepository { // this.locationMapper = 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; + } + + @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()); + jdbc.update(sql,loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID(), false); } - @Override - public List<Location> getApprovedLocations(){ - JdbcTemplate jdbc = new JdbcTemplate(); - List<Location> locations = new LocationRepositoryJDBC(jdbc).getAllLocation(); - List<Location> locationApprovalList= new ArrayList<Location>(); - for (Location loc :locations){ - if (loc.isLocationApproved()) { - locationApprovalList.add(loc); - } - } return locationApprovalList; - } +// @Override +// public List<Location> getApprovedLocations(){ +// JdbcTemplate jdbc = new JdbcTemplate(); +// List<Location> locations = new LocationRepositoryJDBC(jdbc).getAllLocation(); +// List<Location> locationApprovalList= new ArrayList<Location>(); +// for (Location loc :locations){ +// if (loc.isLocationApproved()) { +// locationApprovalList.add(loc); +// } +// } return locationApprovalList; +// } // // @Override // public List<Location> getApprovedLocations2(List<Location> list){ @@ -84,16 +110,16 @@ public class LocationRepositoryJDBC implements LocationRepository { // - @Override - public List<Location> getUnapprovedLocations(){ - List<Location> locations = getAllLocation(); - List<Location> locationUnapprovedList= new ArrayList<Location>(); - for (Location loc :locations){ - if (!loc.isLocationApproved()) { - locationUnapprovedList.add(loc); - } - } return locationUnapprovedList; - } +// @Override +// public List<Location> getUnapprovedLocations(){ +// List<Location> locations = getAllLocation(); +// List<Location> locationUnapprovedList= new ArrayList<Location>(); +// for (Location loc :locations){ +// if (!loc.isLocationApproved()) { +// locationUnapprovedList.add(loc); +// } +// } return locationUnapprovedList; +// } // public JdbcTemplate getJdbc() { diff --git a/src/main/java/Team5/SmartTowns/data/Trail.java b/src/main/java/Team5/SmartTowns/data/Trail.java index 61ab540fce97c94b709c888e3c261db35c318849..f9056d64b47f0f5104216b6eb15f50f9301d843c 100644 --- a/src/main/java/Team5/SmartTowns/data/Trail.java +++ b/src/main/java/Team5/SmartTowns/data/Trail.java @@ -7,7 +7,22 @@ import lombok.Data; @Data @AllArgsConstructor public class Trail { - private int trailsId; - private String name; - private Boolean tru; + private String trailsId; + private String trailName; + private String trailNumber; + + + public String getTrailsId() { + return trailsId; + } + + public String getTrailName() { + return trailName; + } + + public String getTrailNumber() { + return trailNumber; + } + + } diff --git a/src/main/java/Team5/SmartTowns/data/TrailsRepository.java b/src/main/java/Team5/SmartTowns/data/TrailsRepository.java index d25e6fd62efdfdb4d743c829eeab5ddfeb5119d0..7e55ce7d32a732cf645dedabf478d77dbc1b26a9 100644 --- a/src/main/java/Team5/SmartTowns/data/TrailsRepository.java +++ b/src/main/java/Team5/SmartTowns/data/TrailsRepository.java @@ -5,4 +5,5 @@ import java.util.List; public interface TrailsRepository { List<Trail> getAllTrails(); + String getTrailNameWithID(String trailsID); } diff --git a/src/main/java/Team5/SmartTowns/data/TrailsRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/data/TrailsRepositoryJDBC.java index 0bb20867153d77c2fd47f3e031bf63c7c1fdac7e..695ba5b9faff496b3ee941f6cae25b40ab2996ad 100644 --- a/src/main/java/Team5/SmartTowns/data/TrailsRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/data/TrailsRepositoryJDBC.java @@ -17,13 +17,23 @@ public class TrailsRepositoryJDBC implements TrailsRepository { } private void settrailsMapper(){ trailMapper = (rs, i) -> new Trail( - rs.getInt("trailID"), - rs.getString("name"), - rs.getBoolean("tru") + rs.getString("trailID"), + rs.getString("trailName"), + rs.getString("trailNumber") ); } public List<Trail> getAllTrails(){ String sql= "SELECT * FROM trails"; return jdbc.query(sql, trailMapper); } + @Override + public String getTrailNameWithID(String trailsID){ + String resultName = jdbc.queryForObject( + "SELECT trailName FROM trails WHERE trailID=?", String.class, trailsID); + return resultName; + + + } + + } diff --git a/src/main/java/Team5/SmartTowns/landmarks/Landmarks.java b/src/main/java/Team5/SmartTowns/landmarks/Landmarks.java index 6974c1e997c5b2dd6d7396f44ea0cbe4565331c7..8f7471fcc84f95669e9a07aaa3e1f9782dc780d6 100644 --- a/src/main/java/Team5/SmartTowns/landmarks/Landmarks.java +++ b/src/main/java/Team5/SmartTowns/landmarks/Landmarks.java @@ -20,7 +20,7 @@ public class Landmarks { 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") ); - private Integer trailID; + private String trailID; private int landmarkID; @NotEmpty(message = "You must type in a username.") private String landmarkName; diff --git a/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java b/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java index d5d326cdb733339ff3c3ab298090776af9036fc3..a5679aad7406be423fa165f553694ef1d02878a5 100644 --- a/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java +++ b/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java @@ -38,7 +38,6 @@ public class LandmarksController { } else{ // 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); - System.out.println(loc); locationRepository.addLocation(loc); // adds valid landmark to locations table ModelAndView modelAndView = new ModelAndView("redirect:/home"); return modelAndView; diff --git a/src/main/java/Team5/SmartTowns/placeswithcoordinates/LocationsCoordinates.java b/src/main/java/Team5/SmartTowns/placeswithcoordinates/LocationsCoordinates.java index 349adc85e3752bd0f523750e2b5bc8dff25f6e76..a242df3e8b84cee08f3fcdf044e550a49b111343 100644 --- a/src/main/java/Team5/SmartTowns/placeswithcoordinates/LocationsCoordinates.java +++ b/src/main/java/Team5/SmartTowns/placeswithcoordinates/LocationsCoordinates.java @@ -92,16 +92,16 @@ public class LocationsCoordinates { // JdbcTemplate jdbcSuper= new LocationRepositoryJDBC().getJdbc(); // return new LocationRepositoryJDBC(jdbcSuper).getApprovedLocations(); // } - - public List<Location> getFullUnapprovedLocations(JdbcTemplate aJdbc){ -// LocationsCoordinates jdbcSuper= new LocationsCoordinates(aJdbc); - return new LocationRepositoryJDBC(aJdbc).getUnapprovedLocations(); - } +// +// public List<Location> getFullUnapprovedLocations(JdbcTemplate aJdbc){ +//// LocationsCoordinates jdbcSuper= new LocationsCoordinates(aJdbc); +// return new LocationRepositoryJDBC(aJdbc).getUnapprovedLocations(); +// } - /// Need a constructor to create a lcoations list, approved lcoatiosn lsit, unapproved lcoations list. + /// Need a constructor to create a locations list, approved collation list, unapproved locations list. diff --git a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java index 8d142f83569aa8816ea8d9d1b32c6b795ab96c00..6511067e9e636a29d96063357df1e3c7bc4f34e6 100644 --- a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java +++ b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java @@ -2,6 +2,9 @@ package Team5.SmartTowns.placeswithcoordinates; import Team5.SmartTowns.data.Location; import Team5.SmartTowns.data.LocationRepository; +import Team5.SmartTowns.data.Trail; +import Team5.SmartTowns.data.TrailsRepository; +import jakarta.validation.constraints.Max; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -22,55 +25,91 @@ public class PlacesController { @Autowired private LocationRepository locationRepo; - + @Autowired + private TrailsRepository trailsRepo; @GetMapping("/checkpoints") public ModelAndView getLocationPages(){ ModelAndView modelAndView = new ModelAndView("landmarks/locationPage.html"); - List<Location> locations = locationRepo.getAllLocation(); -// List<Location> approvedLocations = locationRepo.getApprovedLocations2(locations); List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); - List<Integer> locationIDIndex = new ArrayList<Integer>(); - List<Location> locationCoordsWorkaround = new ArrayList<Location>(); - for (LocationsCoordinates coord: locCoords){ - locationIDIndex.add(coord.getLocationID()-1); - locationCoordsWorkaround.add(locations.get(coord.getLocationID()-1)); - } - modelAndView.addObject("location", locationCoordsWorkaround); + List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); + + modelAndView.addObject("location", approvedLocations); modelAndView.addObject("locationCoords", locCoords); return modelAndView; } @RequestMapping(value="/location", method= RequestMethod.POST) - public String sendHtmlFragment(Model map) { + public String sendHtmlFragmentLocation(Model map) { map.addAttribute("foo", "bar"); return "checkpoint/checkpoint"; } + + + @GetMapping("/checkpoints/{location}") - public ModelAndView getResultBySearchKey(@PathVariable String location) { - List<Location> locations = locationRepo.getAllLocation(); + public ModelAndView getResultBySearchKeyLocation(@PathVariable String location) { List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); + List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); - List<Integer> locationIDIndex = new ArrayList<Integer>(); - List<Location> locationCoordsWorkaround = new ArrayList<Location>(); int locationID = 999; - int workAroundID=0;// otherwise cases errors e.g. null used. 999 unlikely to be used so safe until then - for (int i=0;i<locCoords.size();i++){ /// for loop iterating over coordinates table need to match coordinate index with lcoation index manually - locationIDIndex.add(locCoords.get(i).getLocationID()-1); // gets location ID and therefore location list index number - locationCoordsWorkaround.add(locations.get(locCoords.get(i).getLocationID()-1)); - if ( (locations.get(locCoords.get(i).getLocationID() - 1).getLocationName().replace(' ', '-').trim().equals(location)) ){ + for (int i=0;i<approvedLocations.size();i++){ + if ( (approvedLocations.get(i).getLocationName().replace(' ', '-').trim().equals(location)) ){ locationID= i; - break; - } workAroundID++; - }System.out.println(locationCoordsWorkaround); - System.out.println("ag"+locationID); + } + } + + String trailName=trailsRepo.getTrailNameWithID(approvedLocations.get(locationID).getLocationTrailID()).replace(' ', '-').trim(); ModelAndView modelAndView= new ModelAndView("fragments/locationPageFrags :: locationSection"); - System.out.println("ag"+locationID); modelAndView.addObject("locCoord", locCoords.get(locationID)); - System.out.println("sd"+workAroundID); - modelAndView.addObject("location", locationCoordsWorkaround.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", 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"); + modelAndView.addObject("trail", trailslocations.get(trailID)); + modelAndView.addObject("locCoords", locCoords); + modelAndView.addObject("locations", approvedLocations); return modelAndView; } diff --git a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepository.java b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepository.java index a5e03d93ab75a20f3c380ca5c1b3d11c6f0b5807..deea368752b4b41bebd49147ce2266e64d942440 100644 --- a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepository.java +++ b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepository.java @@ -13,7 +13,7 @@ public interface PlacesCoordinatesRepository { List<TownWithTrails> getAllTownCoords(); void addTownWithCoords(TownWithTrails town); - List<Location> getFullApprovedLocations(JdbcTemplate aJdbc); +// List<Location> getFullApprovedLocations(JdbcTemplate aJdbc); diff --git a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepositoryJDBC.java index dfca28ecd791d6ec0dc2a3040bc62274c07ff8c3..b90ee0b152d8734e8034e7cc33cd31585ea85fc4 100644 --- a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepositoryJDBC.java @@ -53,6 +53,9 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit String sql= "SELECT * FROM locationCoordinates"; return jdbc.query(sql, locationCoordMapper); } + + + public List<TownWithTrails> getAllTownCoords(){ String sql= "SELECT * FROM townswithtrails"; return jdbc.query(sql, townCoordMapper); @@ -74,10 +77,10 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit } - public List<Location> getFullApprovedLocations(JdbcTemplate aJdbc) { -// LocationsCoordinates jdbcSuper= new LocationsCoordinates(aJdbc); - return new LocationRepositoryJDBC(aJdbc).getApprovedLocations(); - } +// public List<Location> getFullApprovedLocations(JdbcTemplate aJdbc) { +//// LocationsCoordinates jdbcSuper= new LocationsCoordinates(aJdbc); +// return new LocationRepositoryJDBC(aJdbc).getApprovedLocations(); +// } // @Override //TODO CHECK // public List<Location> getFullApprovedLocations(JdbcTemplate aJdbc) { diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index c32f7fec9a996cf9c828449300ea76f36f4813a8..389042e16e7a3acdc3cb53ca62ce1a7438747069 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,62 +1,104 @@ -delete from users; -insert into users (email, name, dragonProgress) value ('hannah@gmail.com', 'Hannah', '90'); -insert into users (userID, email, name, dragonProgress) value ('2', 'nigel@gmail.com', 'Nigel', '40'); +# delete from users; +# insert into users (email, name) value ('hannah@gmail.com', 'Hannah'); +# insert into users (email, name) value ('nigel@gmail.com', 'Nigel'); delete from trails; -insert into trails ( Name) value ( 'Caerphilly Coffee Trail'); -insert into trails ( Name) value ( 'Penarth Dragon Trail'); +insert into trails ( trailID, trailName, trailNumber) value ( 0101,'Caerphilly Castle Trail','0101'); +insert into trails ( trailID, trailName, trailNumber) value ( 0102,'Caerphilly Pub Trail','0102'); +insert into trails ( trailID, trailName, trailNumber) value ( 0103,'Caerphilly Heritage Trail','0103'); +insert into trails ( trailID, trailName, trailNumber) value ( 0201,'Risca Heritage Trail','0201'); +insert into trails ( trailID, trailName, trailNumber) value ( 0301,'Penarth Esplanade Trail','0301'); delete from locations; -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'St Cenydd','','Location description here','Caerphilly',0101); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'The Castle','','Location description here','Caerphilly',0101); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Medieval Trades','','Location description here','Caerphilly',0101); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'The Queen''s War','','Location description here','Caerphilly',0101); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'The Green Lady','','Location description here','Caerphilly',0101); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Armoury','','Location description here','Caerphilly',0101); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Architecture','','Location description here','Caerphilly',0101); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( '21st Century Landmark','','Location description here','Caerphilly',0101); - -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'JD Wetherspoons-Malcolm Uphill','','Location description here','Caerphilly',0102); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Caerphilly Cwtch','','Location description here','Caerphilly',0102); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'The King''s Arms','','Location description here','Caerphilly',0102); - -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Caerphilly Bus Station','','Location description here','Caerphilly',0103); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ('Caerphilly Castle','','Location description here','Caerphilly',0103); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103); - -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Risca Colliery','','Location description here','Risca',0201); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201); - - -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (19, 'The Esplanade','','Location description here','Penarth',0301); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (20, 'The Old Swimming Baths','','Location description here','Penarth',0301); -delete from badges; -insert into badges (name, description, difficulty) value ('TownConnoisseur', 'You know the town very well!', '2'); -insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); -insert into badges (name, description, difficulty) value ('TownMaster', 'You visited the town 7 days in a row!', '1'); -insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); -insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); - -delete from stickers; -insert into stickers (name, description, rarity) value ('TownConnoisseur', 'You know the town very well!', '2'); -insert into stickers (name, description, rarity) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); -insert into stickers (name, description, rarity) value ('TownMaster', 'You visited the town 7 days in a row!', '1'); -insert into stickers (name, description, rarity) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); -insert into stickers (name, description, rarity) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); - -delete from badgeprogress; -insert into badgeprogress (userID, badgeID, progress) value ('1', '1', '40'); -insert into badgeprogress (userID, badgeID, progress) value ('1', '2', '70'); -insert into badgeprogress (userID, badgeID, progress) value ('2', '2', '70'); - -delete from stickerprogress; -insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '1', true); -insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '3', true); -insert into stickerprogress (userID, stickerID, hasSticker) value ('2', '2', true); - -delete from localauthority; -insert into localauthority ( localAuthorityName, address1, address2, city, county, postcode, website) value ( 'Caerphilly County Borough Council', 'Tredomen Park','', 'Ystrad Mynach, Hengoed', '', 'CF82 7PG', 'https://www.caerphilly.gov.uk/main.aspx?lang=en-GB'); -insert into localauthority ( localAuthorityName, address1, address2, city, county, postcode, website) value ( 'Risca Town Council', 'Unit B, 75 Tredegar Street', '', 'Risca', '', 'NP11 6BW', 'https://www.riscatowncouncil.org.uk/'); -insert into localauthority ( localAuthorityName, address1, address2, city, county, postcode, website) value ( 'Penarth Town Council West House', 'Stanwell Road', '', 'Penarth', '', 'CF64 2YG', 'https://www.penarthtowncouncil.gov.uk/your-council/'); \ No newline at end of file +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'St Cenydd','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Castle','','Location description here','Caerphilly',0101, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Medieval Trades','','Location description here','Caerphilly',0101, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Queen''s War','','Location description here','Caerphilly',0101, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Green Lady','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Armoury','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Architecture','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( '21st Century Landmark','','Location description here','Caerphilly',0101, false); + +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'JD Wetherspoons-Malcolm Uphill','','Location description here','Caerphilly',0102, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Cwtch','','Location description here','Caerphilly',0102, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The King''s Arms','','Location description here','Caerphilly',0102, false); + +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Bus Station','','Location description here','Caerphilly',0103, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ('Caerphilly Castle','','Location description here','Caerphilly',0103, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103, false); + +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Risca Colliery','','Location description here','Risca',0201, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201, true); + +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Esplanade','','Location description here','Penarth',0301, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Old Swimming Baths','','Location description here','Penarth',0301, true); + + +# delete from badges; +# insert into badges (name, description, difficulty) value ('TownConnoisseur', 'You know the town very well!', '2'); +# insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); +# insert into badges (name, description, difficulty) value ('TownMaster', 'You visited the town 7 days in a row!', '1'); +# insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); +# insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); + + + +delete from packs; +insert into packs (name, description) value ('Wales Football Team', 'Pack of Welsh Football Players in the National Team'); +insert into packs (name, description) value ('Wales Rugby Team', 'Pack of Welsh Rugby Players in the National Team'); +insert into packs (name, description) value ('Welsh Heritage', 'Pack About Welsh Heritage'); + + +DELETE FROM stickers; +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 1, 'wayne_hennessey', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 2, 'neco_williams', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 3, 'joe_morrell', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 4, 'ethan_ampadu', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 5, 'connor_roberts', 'Wales Football Team Player', '2'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 1, 'Taine_Basham', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 2, 'Adam Beard', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 3, 'Elliot Dee', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 4, 'Corey Domachowski', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (2, 5, 'Ryan Elias', 'Wales Rugby Team Player', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 1, 'Welsh Lady', 'Welsh Heritage', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 2, 'Welsh Outline', 'Welsh Heritage', '1'); +INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 3, 'Welsh Spoon', 'Welsh Heritage', '1'); + +# delete from stickerprogress; +# insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '1', true); +# insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '3', true); +# insert into stickerprogress (userID, stickerID, hasSticker) value ('2', '2', true); + +delete from locationCoordinates; +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (2, 51.57623, -3.21910 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (3, 51.575372, -3.219186); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (4, 51.576363, -3.220712 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (9, 51.57239, -3.21992); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (10, 51.57230, -3.21938 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (13, 51.57168, -3.21861); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (14, 51.57465, -3.22022 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (17, 51.61117, -3.10198 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (18, 51.61655, -3.12371 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (19, 51.43484, -3.16492 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (20, 51.43547, -3.16789 ); + + + + + +# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 1); +# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 2); +# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 3); +# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 5); +# insert into stickerprogress (userID, packID, stickerID) value (1, 2, 1); +# insert into stickerprogress (userID, packID, stickerID) value (1, 2, 3); + + + +# +delete from townsWithTrails; +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Caerphilly', '51.57903','-3.22075 ','51.60418','51.55093','-3.25222','-3.17696'); +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Risca','51.61195','-3.09648','51.63039','51.59175','-3.12129','-3.06438'); +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Penarth','51.43893','-3.17354','51.44878','51.41233','-3.20271','-3.16005'); \ No newline at end of file diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index c1e30317ce0e407e6a13ca7cbfe8d7a6149997a4..b3d550519a311c891985937ed9cd0916542cd5c4 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -1,12 +1,32 @@ + +/* DELETES AND RECREATES DATABASE EVERY TIME THE SYSTEM IS BOOTED*/ +DROP DATABASE IF EXISTS towns; +CREATE DATABASE IF NOT EXISTS towns; +USE towns; +/****************************************************************/ + +/* DROPS ALL TABLES IF THEY EXIST (they wont but just in case) */ + +drop table if exists locationCoordinates; +drop table if exists locations; drop table if exists trails; +DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS stickers; +DROP TABLE IF EXISTS packs; +DROP TABLE IF EXISTS stickerProgress; + +/****************************************************************/ + +/* CREATES ALL TABLES */ create table if not exists trails ( - trailID bigint auto_increment primary key, - name varchar(128) + trailID varchar(128) primary key, + trailName varchar(128), + trailNumber varchar(128) ) engine=InnoDB; +drop table if exists locationCoordinates; drop table if exists locations; - create table if not exists locations ( locationID bigint auto_increment primary key, @@ -14,63 +34,85 @@ create table if not exists locations locationEmail varchar(128), locationDescription longtext, locationPlace varchar(255), - locationTrailID varchar(128) + locationTrailID varchar(128), + locationApproved boolean ) engine=InnoDB; -drop table if exists users; -create table if not exists users -( - userID bigint auto_increment primary key, + +CREATE TABLE IF NOT EXISTS users ( + username 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), - name varchar(128), - dragonProgress int -) engine=InnoDB; + password varchar(30) NOT NULL, + enabled boolean default true +); -drop table if exists badges; -create table if not exists badges -( - badgeID bigint auto_increment primary key, - name varchar(128), - description varchar(128), - difficulty bigint -) engine=InnoDB; - -drop table if exists stickers; -create table if not exists stickers -( - stickerID bigint auto_increment primary key, - name varchar(128), - description varchar(128), - rarity bigint -) engine=InnoDB; - -drop table if exists badgeProgress; -create table if not exists badgeProgress -( - userID bigint, - badgeID bigint, - progress int /*0-100*/ -) 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 +); -create table if not exists stickerProgress +CREATE TABLE IF NOT EXISTS packs ( + id bigint auto_increment primary key, + name varchar(20) NOT NULL, + description text +); + +CREATE TABLE IF NOT EXISTS stickers ( + id bigint auto_increment primary key, + packID bigint NOT NULL, + FOREIGN KEY (packID) REFERENCES packs(id) + ON DELETE CASCADE + ON UPDATE RESTRICT, + stickerID bigint NOT NULL, /*STICKER ID NUMBER WITHIN ITS OWN PACK*/ + name varchar(30) NOT NULL, + description text NOT NULL, + rarity tinyint +); +CREATE TABLE IF NOT EXISTS stickerProgress ( + id bigint auto_increment primary key, + username varchar(30) NOT NULL, + FOREIGN KEY (username) REFERENCES users(username) + ON DELETE CASCADE + ON UPDATE RESTRICT, + packID bigint NOT NULL, + FOREIGN KEY (packID) REFERENCES packs(id) + ON DELETE CASCADE + ON UPDATE RESTRICT, + stickerID bigint NOT NULL, + FOREIGN KEY (stickerID) REFERENCES stickers(id) + ON DELETE CASCADE + ON UPDATE RESTRICT +); + +create table if not exists locationCoordinates ( - userID bigint, - stickerID bigint, - hasSticker boolean /*Has sticker or not*/ -) engine=InnoDB; + locationCoordID bigint auto_increment primary key, + locationID bigint, + Foreign Key (locationID) REFERENCES locations(locationID) + ON DELETE CASCADE + ON UPDATE RESTRICT, + locationCoordsLat DECIMAL(8,6), + locationCoordsLong DECIMAL(8,6) + -drop table if exists localAuthority; -create table if not exists localAuthority +)engine=InnoDB; + + +drop table if exists townsWithTrails; +create table if not exists townsWithTrails ( - localAuthorityID bigint auto_increment primary key, - localAuthorityName varchar(250), - address1 varchar(250), - address2 varchar(250), - city varchar(100), - county varchar(75), - postcode varchar(15), - website varchar(250) -) engine=InnoDB; + townID bigint auto_increment primary key, + townName varchar(128), + townCentreCoordsLat varchar(128), + townCentreCoordsLong varchar(128), + townUppermostCoordsLat varchar(128), + townLowermostCoordsLat varchar(128), + townLeftmostCoordsLong varchar(128), + townRightmostCoordsLong varchar(128) + +)engine=InnoDB; drop table if exists businesses; create table if not exists businesses diff --git a/src/main/resources/static/css/locationPageFragsStyle.css b/src/main/resources/static/css/locationPageFragsStyle.css index 53cf211001f02daf8ff1874a25d6546015115b37..db091e112e77a7abc0c507fc0305e6a2a2244317 100644 --- a/src/main/resources/static/css/locationPageFragsStyle.css +++ b/src/main/resources/static/css/locationPageFragsStyle.css @@ -14,6 +14,9 @@ color: wheat; } +#return{ + padding-bottom: 10px; +} iframe{ margin-top: 20px; margin-bottom: 60px; diff --git a/src/main/resources/static/css/trailsPageFragsStyle.css b/src/main/resources/static/css/trailsPageFragsStyle.css new file mode 100644 index 0000000000000000000000000000000000000000..1e2a067eb8819da6c8d0b69c8486cc5055795023 --- /dev/null +++ b/src/main/resources/static/css/trailsPageFragsStyle.css @@ -0,0 +1,36 @@ +.trailsFragment{ + background-color: rgb(206, 153, 253); + color: black; + border-color: white; + align-content: center; + text-align: center; + border-radius: 25px; + max-width: 800px; + margin: 0 auto; + +} +.trailsPageFrag{ + background: rgb(41, 41, 41); + color: wheat; +} + +iframe{ + margin-top: 20px; + margin-bottom: 20px; + border: white 2px solid; +} +H1{ + padding-top: 15px; + padding-bottom:3px ; + margin-bottom: 0; +} +#trailHeader{ + margin: 0; + padding: 0; + +} + +#checkpointList{ + list-style: none; + padding-bottom: 10px; +} \ No newline at end of file diff --git a/src/main/resources/static/scripts/mapAPI.js b/src/main/resources/static/scripts/mapAPI.js index 6af8c3b085396384779093efaca5f777112a7537..8b81c394af31962757934756bdd48a299881b03f 100644 --- a/src/main/resources/static/scripts/mapAPI.js +++ b/src/main/resources/static/scripts/mapAPI.js @@ -1,153 +1,153 @@ -import GeoJSON from '/nodeMods/node_modules/ol/format/GeoJSON.js'; -import Map from '/nodeMods/node_modules/ol/Map.js'; -import VectorLayer from '/nodeMods/node_modules/ol/source/Vector.js' -import VectorSource from '/nodeMods/node_modules/ol/source/Vector.js'; -import View from '/nodeMods/node_modules/ol/View.js'; -import {DragBox, Select} from '/nodeMods/node_modules/ol/interaction.js'; -import {Fill, Stroke, Style} from '/nodeMods/node_modules/ol/style.js'; -import {getWidth} from '/nodeMods/node_modules/ol/extent.js'; -import {platformModifierKeyOnly} from '/nodeMods/node_modules/ol/events/condition.js'; -// //Invesitgate created directories mnode module mapstest and extent.js -// import GeoJSON from '/node_modules/ol/format/GeoJSON.js'; -// import Map from '/ol/Map.js'; -// import VectorLayer from '/ol/layer/Vector.js'; -// import VectorSource from '/ol/source/Vector.js'; -// import View from '/ol/View.js'; -// import {DragBox, Select} from '/ol/interaction.js'; -// import {Fill, Stroke, Style} from '/ol/style.js'; -// import {getWidth} from '/ol/extent.js'; -// import {platformModifierKeyOnly} from '/ol/events/condition.js'; - - -const vectorSource = new VectorSource({ - url: 'https://openlayers.org/data/vector/ecoregions.json', - format: new GeoJSON(), -}); - -const style = new Style({ - fill: new Fill({ - color: '#eeeeee', - }), -}); - -const map = new Map({ - layers: [ - new VectorLayer({ - source: vectorSource, - background: '#1a2b39', - style: function (feature) { - const color = feature.get('COLOR_BIO') || '#eeeeee'; - style.getFill().setColor(color); - return style; - }, - }), - ], - target: 'map', - view: new View({ - center: [0, 0], - zoom: 2, - constrainRotation: 16, - }), -}); - -const selectedStyle = new Style({ - fill: new Fill({ - color: 'rgba(255, 255, 255, 0.6)', - }), - stroke: new Stroke({ - color: 'rgba(255, 255, 255, 0.7)', - width: 2, - }), -}); - -// a normal select interaction to handle click -const select = new Select({ - style: function (feature) { - const color = feature.get('COLOR_BIO') || '#eeeeee'; - selectedStyle.getFill().setColor(color); - return selectedStyle; - }, -}); -map.addInteraction(select); - -const selectedFeatures = select.getFeatures(); - -// a DragBox interaction used to select features by drawing boxes -const dragBox = new DragBox({ - condition: platformModifierKeyOnly, -}); - -map.addInteraction(dragBox); - -dragBox.on('boxend', function () { - const boxExtent = dragBox.getGeometry().getExtent(); - - // if the extent crosses the antimeridian process each world separately - const worldExtent = map.getView().getProjection().getExtent(); - const worldWidth = getWidth(worldExtent); - const startWorld = Math.floor((boxExtent[0] - worldExtent[0]) / worldWidth); - const endWorld = Math.floor((boxExtent[2] - worldExtent[0]) / worldWidth); - - for (let world = startWorld; world <= endWorld; ++world) { - const left = Math.max(boxExtent[0] - world * worldWidth, worldExtent[0]); - const right = Math.min(boxExtent[2] - world * worldWidth, worldExtent[2]); - const extent = [left, boxExtent[1], right, boxExtent[3]]; - - const boxFeatures = vectorSource - .getFeaturesInExtent(extent) - .filter( - (feature) => - !selectedFeatures.getArray().includes(feature) && - feature.getGeometry().intersectsExtent(extent) - ); - - // features that intersect the box geometry are added to the - // collection of selected features - - // if the view is not obliquely rotated the box geometry and - // its extent are equalivalent so intersecting features can - // be added directly to the collection - const rotation = map.getView().getRotation(); - const oblique = rotation % (Math.PI / 2) !== 0; - - // when the view is obliquely rotated the box extent will - // exceed its geometry so both the box and the candidate - // feature geometries are rotated around a common anchor - // to confirm that, with the box geometry aligned with its - // extent, the geometries intersect - if (oblique) { - const anchor = [0, 0]; - const geometry = dragBox.getGeometry().clone(); - geometry.translate(-world * worldWidth, 0); - geometry.rotate(-rotation, anchor); - const extent = geometry.getExtent(); - boxFeatures.forEach(function (feature) { - const geometry = feature.getGeometry().clone(); - geometry.rotate(-rotation, anchor); - if (geometry.intersectsExtent(extent)) { - selectedFeatures.push(feature); - } - }); - } else { - selectedFeatures.extend(boxFeatures); - } - } -}); - -// clear selection when drawing a new box and when clicking on the map -dragBox.on('boxstart', function () { - selectedFeatures.clear(); -}); - -const infoBox = document.getElementById('info'); - -selectedFeatures.on(['add', 'remove'], function () { - const names = selectedFeatures.getArray().map((feature) => { - return feature.get('ECO_NAME'); - }); - if (names.length > 0) { - infoBox.innerHTML = names.join(', '); - } else { - infoBox.innerHTML = 'None'; - } -}); \ No newline at end of file +// import GeoJSON from '/nodeMods/node_modules/ol/format/GeoJSON.js'; +// import Map from '/nodeMods/node_modules/ol/Map.js'; +// import VectorLayer from '/nodeMods/node_modules/ol/source/Vector.js' +// import VectorSource from '/nodeMods/node_modules/ol/source/Vector.js'; +// import View from '/nodeMods/node_modules/ol/View.js'; +// import {DragBox, Select} from '/nodeMods/node_modules/ol/interaction.js'; +// import {Fill, Stroke, Style} from '/nodeMods/node_modules/ol/style.js'; +// import {getWidth} from '/nodeMods/node_modules/ol/extent.js'; +// import {platformModifierKeyOnly} from '/nodeMods/node_modules/ol/events/condition.js'; +// // //Invesitgate created directories mnode module mapstest and extent.js +// // import GeoJSON from '/node_modules/ol/format/GeoJSON.js'; +// // import Map from '/ol/Map.js'; +// // import VectorLayer from '/ol/layer/Vector.js'; +// // import VectorSource from '/ol/source/Vector.js'; +// // import View from '/ol/View.js'; +// // import {DragBox, Select} from '/ol/interaction.js'; +// // import {Fill, Stroke, Style} from '/ol/style.js'; +// // import {getWidth} from '/ol/extent.js'; +// // import {platformModifierKeyOnly} from '/ol/events/condition.js'; +// // +// +// const vectorSource = new VectorSource({ +// url: 'https://openlayers.org/data/vector/ecoregions.json', +// format: new GeoJSON(), +// }); +// +// const style = new Style({ +// fill: new Fill({ +// color: '#eeeeee', +// }), +// }); +// +// const map = new Map({ +// layers: [ +// new VectorLayer({ +// source: vectorSource, +// background: '#1a2b39', +// style: function (feature) { +// const color = feature.get('COLOR_BIO') || '#eeeeee'; +// style.getFill().setColor(color); +// return style; +// }, +// }), +// ], +// target: 'map', +// view: new View({ +// center: [0, 0], +// zoom: 2, +// constrainRotation: 16, +// }), +// }); +// +// const selectedStyle = new Style({ +// fill: new Fill({ +// color: 'rgba(255, 255, 255, 0.6)', +// }), +// stroke: new Stroke({ +// color: 'rgba(255, 255, 255, 0.7)', +// width: 2, +// }), +// }); +// +// // a normal select interaction to handle click +// const select = new Select({ +// style: function (feature) { +// const color = feature.get('COLOR_BIO') || '#eeeeee'; +// selectedStyle.getFill().setColor(color); +// return selectedStyle; +// }, +// }); +// map.addInteraction(select); +// +// const selectedFeatures = select.getFeatures(); +// +// // a DragBox interaction used to select features by drawing boxes +// const dragBox = new DragBox({ +// condition: platformModifierKeyOnly, +// }); +// +// map.addInteraction(dragBox); +// +// dragBox.on('boxend', function () { +// const boxExtent = dragBox.getGeometry().getExtent(); +// +// // if the extent crosses the antimeridian process each world separately +// const worldExtent = map.getView().getProjection().getExtent(); +// const worldWidth = getWidth(worldExtent); +// const startWorld = Math.floor((boxExtent[0] - worldExtent[0]) / worldWidth); +// const endWorld = Math.floor((boxExtent[2] - worldExtent[0]) / worldWidth); +// +// for (let world = startWorld; world <= endWorld; ++world) { +// const left = Math.max(boxExtent[0] - world * worldWidth, worldExtent[0]); +// const right = Math.min(boxExtent[2] - world * worldWidth, worldExtent[2]); +// const extent = [left, boxExtent[1], right, boxExtent[3]]; +// +// const boxFeatures = vectorSource +// .getFeaturesInExtent(extent) +// .filter( +// (feature) => +// !selectedFeatures.getArray().includes(feature) && +// feature.getGeometry().intersectsExtent(extent) +// ); +// +// // features that intersect the box geometry are added to the +// // collection of selected features +// +// // if the view is not obliquely rotated the box geometry and +// // its extent are equalivalent so intersecting features can +// // be added directly to the collection +// const rotation = map.getView().getRotation(); +// const oblique = rotation % (Math.PI / 2) !== 0; +// +// // when the view is obliquely rotated the box extent will +// // exceed its geometry so both the box and the candidate +// // feature geometries are rotated around a common anchor +// // to confirm that, with the box geometry aligned with its +// // extent, the geometries intersect +// if (oblique) { +// const anchor = [0, 0]; +// const geometry = dragBox.getGeometry().clone(); +// geometry.translate(-world * worldWidth, 0); +// geometry.rotate(-rotation, anchor); +// const extent = geometry.getExtent(); +// boxFeatures.forEach(function (feature) { +// const geometry = feature.getGeometry().clone(); +// geometry.rotate(-rotation, anchor); +// if (geometry.intersectsExtent(extent)) { +// selectedFeatures.push(feature); +// } +// }); +// } else { +// selectedFeatures.extend(boxFeatures); +// } +// } +// }); +// +// // clear selection when drawing a new box and when clicking on the map +// dragBox.on('boxstart', function () { +// selectedFeatures.clear(); +// }); +// +// const infoBox = document.getElementById('info'); +// +// selectedFeatures.on(['add', 'remove'], function () { +// const names = selectedFeatures.getArray().map((feature) => { +// return feature.get('ECO_NAME'); +// }); +// if (names.length > 0) { +// infoBox.innerHTML = names.join(', '); +// } else { +// infoBox.innerHTML = 'None'; +// } +// }); \ No newline at end of file diff --git a/src/main/resources/templates/fragments/locationPageFrags.html b/src/main/resources/templates/fragments/locationPageFrags.html index 9cb90e48b97924a4bc53092a7aa86593d20bbf8a..ba7813ecf7e24927302cd49b1ca1523d959cae17 100644 --- a/src/main/resources/templates/fragments/locationPageFrags.html +++ b/src/main/resources/templates/fragments/locationPageFrags.html @@ -1,6 +1,5 @@ <!DOCTYPE html> <html lang="en" th:fragment="locationSection" class="locationPageFrag"> -<!-- todo check if this is ok here--> <head> <meta charset="UTF-8"> <title th:text="${location.getLocationName()}"></title> @@ -29,6 +28,8 @@ marginwidth="0" th:src="'https://maps.google.com/maps?q='+ ${locCoord.getLocationCoordsLat()} +','+ ${locCoord.getLocationCoordsLong()} +'&hl=en&z=20&output=embed'"> </iframe> + <H2 id="return"> + <a th:href="@{'/trails/'+${trail}}">Return</a></H2> </article> <hr style="height:40px; visibility:hidden;" /> diff --git a/src/main/resources/templates/fragments/trailsPageFrags.html b/src/main/resources/templates/fragments/trailsPageFrags.html new file mode 100644 index 0000000000000000000000000000000000000000..296cd2d153d1671b467a27a78f5a1994bdb77806 --- /dev/null +++ b/src/main/resources/templates/fragments/trailsPageFrags.html @@ -0,0 +1,114 @@ +<!DOCTYPE html> +<html lang="en" th:fragment="trailsSection" class="trailsPageFrag"> +<head> + <meta charset="UTF-8"> + <title th:text="${trail.getTrailName()}"></title> + + <link rel="stylesheet" th:href="@{/css/templatingstyle.css}"> + <link rel="stylesheet" th:href="@{/css/trailsPageFragsStyle.css}"> + + +</head> +<body > +<header th:insert="~{/fragments/Templating.html::header}"></header> +<main> + + <hr style="height:40px; visibility:hidden;" /> + <article class="trailsFragment"> + + <H1 th:text="*{trail.getTrailName()}" id="trailHeader"></H1> + + <div th:if="*{trail.getTrailName()=='Caerphilly Castle Trail'}"> + <iframe + width="600" + height="400" + frameborder="0" + scrolling="yes" + marginheight="0" + marginwidth="0" + src="https://www.google.com/maps/dir/51.57623,-3.21910/51.575372,-3.219186/51.576363,-3.220712//@11z"> + </iframe> + <div><a href="https://www.google.com/maps/dir/51.57623,-3.21910/51.575372,-3.219186/51.576363,-3.220712//@11z">Trail Map</a></div> + + </div> + + <div th:if="*{trail.getTrailName()=='Caerphilly Pub Trail'}"> + <iframe + width="600" + height="400" + frameborder="0" + scrolling="yes" + marginheight="0" + marginwidth="0" + th:src="'https://www.google.com/maps/dir/51.57239,-3.21992/51.57230,-3.21938//@&hl=en&z=20&output=embed'"> + </iframe> + <div><a href="https://www.google.com/maps/dir/51.57239,-3.21992/51.57230,-3.21938//@11z">Trail Map</a></div> + + </div> + <div th:if="*{trail.getTrailName()=='Caerphilly Heritage Trail'}"> + <iframe + width="600" + height="400" + frameborder="0" + scrolling="yes" + marginheight="0" + marginwidth="0" + th:src="'https://www.google.com/maps/dir/51.57168,-3.21861/51.57465,-3.22022//@11z'"> + </iframe> + <div> + <a href="https://www.google.com/maps/dir/51.57168,-3.21861/51.57465,-3.22022//@11z">Trail Map</a></div> + + </div> + <div th:if="*{trail.getTrailName()=='Risca Heritage Trail'}"> + <iframe + width="600" + height="400" + frameborder="0" + scrolling="yes" + marginheight="0" + marginwidth="0" + th:src="'https://www.google.com/maps/dir/51.61117,-3.10198/51.61655,-3.12371 //@11z'"> + </iframe> + <div><a href="https://www.google.com/maps/dir/51.61117,-3.10198/51.61655,-3.12371 //@11z">Trail Map</a></div> + </div> + <div th:if="*{trail.getTrailName()=='Penarth Esplanade Trail'}"> + <iframe + width="600" + height="400" + frameborder="0" + scrolling="yes" + marginheight="0" + marginwidth="0" + th:src="'https://www.google.com/maps/dir/51.43484,-3.16492/51.43547,-3.16789//@11z'"> + </iframe> + <div> + <a href="https://www.google.com/maps/dir/51.43484,-3.16492/51.43547,-3.16789//@11z">Trail Map</a> + </div> + </div> + <H3>Checkpoints:</H3> +<!-- With the trial name, we go through locations list to get --> + <div th:each="locationCoord, indexValue:${locCoords}" > + <div th:if="${locations[indexValue.index].getLocationTrailID()==trail.getTrailsId()}"> + <li id="checkpointList"> + <div><a th:href="'/checkpoints/'+${locations[indexValue.index].getLocationName().replace(' ', '-')}" th:text="${locations[indexValue.index].getLocationName()}"></a></div> + <ul></ul> + </li> + + + + + </div> + + + + + + + </div> + </article> + <hr style="height:40px; visibility:hidden;" /> +</main> + +<footer th:insert="~{/fragments/Templating.html::footer}"></footer> +</body> +</html> diff --git a/src/main/resources/templates/landmarks/LandmarkFormTh.html b/src/main/resources/templates/landmarks/LandmarkFormTh.html index 0f7879d8277ad1012ffefaae75fc49d70b6932ca..646632ce015eb3e16d14e7da06c604cc2ae10c5b 100644 --- a/src/main/resources/templates/landmarks/LandmarkFormTh.html +++ b/src/main/resources/templates/landmarks/LandmarkFormTh.html @@ -42,7 +42,7 @@ <select th:field="*{trailID}"> <option value=0 hidden="true">Select Trail</option> <option value=0 disabled selected>Select Trail</option> - <option value=0101>(Caerphilly) Castle Trail</option> + <option value=101>(Caerphilly) Castle Trail</option> <option value=0102>(Caerphilly) Pub Trail</option> <option value=0103>(Caerphilly) Heritage Trail</option> <option value=0201>(Risca) Heritage and Culture Trail</option> diff --git a/src/main/resources/templates/landmarks/trailsPage.html b/src/main/resources/templates/landmarks/trailsPage.html new file mode 100644 index 0000000000000000000000000000000000000000..4316d94fe409ebeba57db4005b31fbba6178bc70 --- /dev/null +++ b/src/main/resources/templates/landmarks/trailsPage.html @@ -0,0 +1,98 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title>Trails</title> + <link rel="stylesheet" th:href="@{/css/templatingstyle.css}"> +</head> +<body> +<header th:insert="~{/fragments/Templating.html::header}"></header> +<main> + <div th:each="trail, indexValue:${trails}"> + <H1 th:text="*{trail.getTrailName()}"></H1> + + <div th:if="*{trail.getTrailName()=='Caerphilly Castle Trail'}"> + <iframe + width="600" + height="400" + frameborder="0" + scrolling="yes" + marginheight="0" + marginwidth="0" + src="https://www.google.com/maps/dir/51.57623,-3.21910/51.575372,-3.219186/51.576363,-3.220712//@11z"> + </iframe> + + </div> + + <div th:if="*{trail.getTrailName()=='Caerphilly Pub Trail'}"> + <iframe + width="600" + height="400" + frameborder="0" + scrolling="yes" + marginheight="0" + marginwidth="0" + th:src="'https://www.google.com/maps/dir/51.57239,-3.21992/51.57230,-3.21938//@11z'"> + </iframe> + + </div> + <div th:if="*{trail.getTrailName()=='Caerphilly Heritage Trail'}"> + <iframe + width="600" + height="400" + frameborder="0" + scrolling="yes" + marginheight="0" + marginwidth="0" + th:src="'https://www.google.com/maps/dir/51.57168,-3.21861/51.57465,-3.22022//@11z'"> + </iframe> + + </div> + <div th:if="*{trail.getTrailName()=='Risca Heritage Trail'}"> + <iframe + width="600" + height="400" + frameborder="0" + scrolling="yes" + marginheight="0" + marginwidth="0" + th:src="'https://www.google.com/maps/dir/51.61117,-3.10198/51.61655,-3.12371 //@11z'"> + </iframe> + + </div> + <div th:if="*{trail.getTrailName()=='Penarth Esplanade Trail'}"> + <iframe + width="600" + height="400" + frameborder="0" + scrolling="yes" + marginheight="0" + marginwidth="0" + th:src="'https://www.google.com/maps/dir/51.43484,-3.16492/51.43547,-3.16789//@11z'"> + </iframe> + + </div> + <H3>Checkpoints:</H3> + + <div th:each="locationCoord, indexValue2:${locationCoords}" > + <div th:if="${locations[indexValue2.index].getLocationTrailID()==trail.getTrailsId()}"> + <li style="list-style: none"> + <a th:href="'/checkpoints/'+${locations[indexValue2.index].getLocationName().replace(' ', '-')}" th:text="${locations[indexValue2.index].getLocationName()}"></a> + <ul></ul> + </li> + + + + + </div> + + + + + + + </div> +</main> +<footer th:insert="~{/fragments/Templating.html::footer}"></footer> +</body> +</html> \ No newline at end of file diff --git a/src/test/java/Team5/SmartTowns/DataSourceConfig.java b/src/test/java/Team5/SmartTowns/DataSourceConfig.java index eb7623abb1831b13d72138f824b600d6ce361fa7..568065a262e3a45668c889f8a8ddc6c1048bba01 100644 --- a/src/test/java/Team5/SmartTowns/DataSourceConfig.java +++ b/src/test/java/Team5/SmartTowns/DataSourceConfig.java @@ -1,20 +1,19 @@ package Team5.SmartTowns; +import javax.sql.DataSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DriverManagerDataSource; -import javax.sql.DataSource; @Configuration public class DataSourceConfig { @Bean public DataSource dataSource(){ - DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setUrl("jdbc:mariadb://localhost:3306/test_towns"); - dataSource.setUsername("root"); - dataSource.setPassword("comsc"); - return dataSource; + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setUrl("jdbc:mariadb://localhost:3306/test_towns"); + dataSource.setUsername("root"); + dataSource.setPassword("comsc"); + return dataSource; } - -} +} \ No newline at end of file diff --git a/src/test/java/Team5/SmartTowns/LocationRepositoryTest.java b/src/test/java/Team5/SmartTowns/LocationRepositoryTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0c029bd95f7e372481c2a64c0aa2394b8794ff73 --- /dev/null +++ b/src/test/java/Team5/SmartTowns/LocationRepositoryTest.java @@ -0,0 +1,120 @@ +package Team5.SmartTowns; + +import Team5.SmartTowns.data.Location; +import Team5.SmartTowns.data.LocationRepository; + +import Team5.SmartTowns.data.TrailsRepository; +import Team5.SmartTowns.placeswithcoordinates.LocationsCoordinates; +import Team5.SmartTowns.placeswithcoordinates.PlacesCoordinatesRepository; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@SpringBootTest +public class LocationRepositoryTest { + + @Autowired + TrailsRepository trailsRepo; + @Autowired + LocationRepository locationRepository; + + + @Autowired + PlacesCoordinatesRepository placesRepository; + + @Autowired + JdbcTemplate jdbcTemplate; + + + +// @BeforeEach +// public void beforeEachTest(){ +// jdbcTemplate.update("DELETE FROM locations"); +// } + + @Test + public void testGetAllApprovedLocations() { + List<Location> approvedLocations = locationRepository.getAllApprovedLocations(); + List<Location> allLocations = locationRepository.getAllLocation(); + for (int i=0;i<allLocations.size();i++){ // iterate over all location, removing authorised=true + for (Location app : approvedLocations){ + if (Objects.equals(allLocations.get(i).getLocationName(), app.getLocationName())){ + allLocations.remove(allLocations.get(i)); + } + } + } boolean noApporvedLeft=false; + for (Location loc2: allLocations){ + if (loc2.isLocationApproved()){ + noApporvedLeft=false; + break; + } else{ + noApporvedLeft=true; + } + } assertTrue(noApporvedLeft); + } + + + @Test + public void testGetAllUnapprovedLocations() { + List<Location> unapprovedLocations = locationRepository.getAllUnapprovedLocations(); + List<Location> allLocations = locationRepository.getAllLocation(); + for (int i=0;i<allLocations.size();i++){ // iterate over all location, removing authorised=false + for (Location app : unapprovedLocations){ + if (Objects.equals(allLocations.get(i).getLocationName(), app.getLocationName())){ + allLocations.remove(allLocations.get(i)); + } + } + } boolean noUnapporvedLeft=false; + for (Location loc2: allLocations){ + if (!loc2.isLocationApproved()){ + noUnapporvedLeft=false; + break; + } else{ + noUnapporvedLeft=true; + } + } assertTrue(noUnapporvedLeft); + } + @Test + public void ensureApprovedLocationsAndCoordinatessAreTheSameSize(){ + List<Location> approvedLocations = locationRepository.getAllApprovedLocations(); + List<LocationsCoordinates> coordinatesLocations = placesRepository.getAllLocationCoords(); + assertSame(approvedLocations.size(),coordinatesLocations.size() ); + + } + + + @Test + public void ensureApprovedLocationsAndCoordinatessTableLineUpTest(){ + List<Location> approvedLocations = locationRepository.getAllApprovedLocations(); + List<LocationsCoordinates> coordinatesLocations = placesRepository.getAllLocationCoords(); + List<Integer> coordinatesLocationsID = new ArrayList<>(); + boolean doTheyMatch=false; + for (int i=0;i<coordinatesLocations.size();i++){ + int locID=coordinatesLocations.get(i).getLocationID(); + String coordName = jdbcTemplate.queryForObject("SELECT locationName FROM locations WHERE locationID=?", String.class, locID); + + if (Objects.equals(coordName, approvedLocations.get(i).getLocationName())){ + doTheyMatch=true; + } else{ + doTheyMatch=false; + break; + } + // for loop goes through entire list, if there were any discrepancies, the loop would break, resulting in a fail + + + } assertTrue(doTheyMatch); + } +} diff --git a/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java b/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java index 320fa59b1281d8b7a194e69d497022bff55d5571..4b281aab3e06da893c6862fda7dd47b2b3c54e65 100644 --- a/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java +++ b/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java @@ -1,67 +1,92 @@ -package Team5.SmartTowns; - -import Team5.SmartTowns.data.DatabaseController; -import Team5.SmartTowns.data.Location; -import Team5.SmartTowns.data.LocationRepository; -import Team5.SmartTowns.data.LocationRepositoryJDBC; -import Team5.SmartTowns.landmarks.Landmarks; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.jdbc.core.JdbcTemplate; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.lang.annotation.Inherited; -import java.util.List; - - - - -@SpringBootTest -class SmartTownsApplicationTests { - - @Test - void contextLoads() { - } - - - - - -// private static Location location; -// private static locationRepositoryJDBC locationRepo; -// private static JdbcTemplate jdbc; -// @BeforeAll -// public static void before() { -// location = new Location(); -// locationRepo = new locationRepositoryJDBC(jdbc);} -// @BeforeAll -// public static void before2() { -// locationRepo = new locationRepositoryJDBC(jdbc); } +//package Team5.SmartTowns; +// +//import Team5.SmartTowns.data.DatabaseController; +//import Team5.SmartTowns.data.Location; +//import Team5.SmartTowns.data.LocationRepository; +//import Team5.SmartTowns.data.LocationRepositoryJDBC; +//import Team5.SmartTowns.landmarks.Landmarks; +//import org.junit.jupiter.api.BeforeAll; +//import org.junit.jupiter.api.Test; +//import org.mockito.InjectMocks; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +//import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.jdbc.core.JdbcTemplate; +// +//import static org.junit.jupiter.api.Assertions.assertEquals; +// +//import java.lang.annotation.Inherited; +//import java.util.List; +// +// +// +//@DataJpaTest +//@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) +////@SpringBootTest +//class SmartTownsApplicationTests { +// // @Autowired -// private locationRepository locationRepository; - +// private LocationRepository locationRepository; +// +// // @Test -// public void whenAddingLocationsNonApprovedLocationsDontShowInTrails(){ -// /// Discover number of approved/unapproved locations before adding tests -// List<Location> approvedNumber = locationRepo.approvedLocations(); +// void contextLoads() { // } -//// Location loc1= new Location("TestFail", "Test@PleaseFail.test", "Fail Description here", -//// "Caerphilly", 103, false); -//// Location loc2= new Location("TestFail", "Test@PleaseFail2.test", "Fail Description here", -//// "Caerphilly", 103, false); -//// Location loc3= new Location("TestPass", "Test@PleasePass.test", "Pass Description here", -//// "Caerphilly", 103, true); -//// locationRepository.addLocation(loc1); -//// locationRepository.addLocation(loc2); -//// locationRepository.addLocation(loc3); -//// List<Location> ApprovedNumberAfter=locationRepository.approvedLocations(); -//// -//// assertEquals(1,( ApprovedNumber.size()-ApprovedNumberAfter.size())); -// } - } - -// create test where getFullListLocations and getFullApproved/Unapporved lcopations from lcoationcooirds matches locationJDBC +// +// @Test +// void test(){ +// Location location = new Location(); +// location.setLocationName("Test"); +// location.setLocationEmail("test@test"); +// location.setLocationDescription("Description Here"); +// location.setLocationPlace("Caerphilly"); +// location.setLocationTrailID("0103"); +// location.setLocationApproved(false); +// +// int locSize1 = locationRepository.getAllLocation().size(); +// locationRepository.addLocation(location); +// int locSize2 = locationRepository.getAllLocation().size(); +// assertEquals(1, (locSize2-locSize1)); +// +// +// } +// +// +// +// +// +//// private static Location location; +//// private static locationRepositoryJDBC locationRepo; +//// private static JdbcTemplate jdbc; +//// @BeforeAll +//// public static void before() { +//// location = new Location(); +//// locationRepo = new locationRepositoryJDBC(jdbc);} +//// @BeforeAll +//// public static void before2() { +//// locationRepo = new locationRepositoryJDBC(jdbc); } +//// @Autowired +//// private locationRepository locationRepository; +// +//// @Test +//// public void whenAddingLocationsNonApprovedLocationsDontShowInTrails(){ +//// /// Discover number of approved/unapproved locations before adding tests +//// List<Location> approvedNumber = locationRepo.approvedLocations(); +//// } +////// Location loc1= new Location("TestFail", "Test@PleaseFail.test", "Fail Description here", +////// "Caerphilly", 103, false); +////// Location loc2= new Location("TestFail", "Test@PleaseFail2.test", "Fail Description here", +////// "Caerphilly", 103, false); +////// Location loc3= new Location("TestPass", "Test@PleasePass.test", "Pass Description here", +////// "Caerphilly", 103, true); +////// locationRepository.addLocation(loc1); +////// locationRepository.addLocation(loc2); +////// locationRepository.addLocation(loc3); +////// List<Location> ApprovedNumberAfter=locationRepository.approvedLocations(); +////// +////// assertEquals(1,( ApprovedNumber.size()-ApprovedNumberAfter.size())); +//// } +// } +// +//// create test where getFullListLocations and getFullApproved/Unapporved lcopations from lcoationcooirds matches locationJDBC diff --git a/src/test/java/Team5/SmartTowns/TrailsRepositoryTest.java b/src/test/java/Team5/SmartTowns/TrailsRepositoryTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c0d8d91555c8a68955b49b61ba78c2589f7a507e --- /dev/null +++ b/src/test/java/Team5/SmartTowns/TrailsRepositoryTest.java @@ -0,0 +1,44 @@ +package Team5.SmartTowns; + +import Team5.SmartTowns.data.LocationRepository; +import Team5.SmartTowns.data.TrailsRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + +@SpringBootTest +public class TrailsRepositoryTest { + @Autowired + TrailsRepository trailsRepo; + + @Autowired + JdbcTemplate jdbcTemplate; + + @Test + public void getTrailNameWithIDTest(){ + String trailsID="101"; + String trailName= trailsRepo.getTrailNameWithID(trailsID); + assertEquals("Caerphilly Castle Trail",trailName); + trailsID="102"; + trailName= trailsRepo.getTrailNameWithID(trailsID); + assertEquals("Caerphilly Pub Trail",trailName); + trailsID="103"; + trailName= trailsRepo.getTrailNameWithID(trailsID); + assertEquals("Caerphilly Heritage Trail",trailName); + trailsID="201"; + trailName= trailsRepo.getTrailNameWithID(trailsID); + assertEquals("Risca Heritage Trail",trailName); + trailsID="301"; + trailName= trailsRepo.getTrailNameWithID(trailsID); + assertEquals("Penarth Esplanade Trail",trailName); + } // test whether function works correctly for all instances + + + + +} diff --git a/src/test/java/Team5/SmartTowns/data/LocationRepositoryJDBCTest.java b/src/test/java/Team5/SmartTowns/data/LocationRepositoryJDBCTest.java new file mode 100644 index 0000000000000000000000000000000000000000..73792324a036bc848146988f73abe5bbc9a268c2 --- /dev/null +++ b/src/test/java/Team5/SmartTowns/data/LocationRepositoryJDBCTest.java @@ -0,0 +1,44 @@ +//package Team5.SmartTowns.data; +// +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.jdbc.core.JdbcTemplate; +//import org.springframework.jdbc.core.RowMapper; +// +//@SpringBootTest +//class LocationRepositoryJDBCTest { +// private JdbcTemplate jdbcTemplate; +// private LocationRepositoryJDBC locationRepositoryJDBC; +// +// private RowMapper<Location> locationMapper; +// +// +// @Autowired +// public void setlocationMapper(){ +// locationMapper = (rs, i) -> new Location( +// +// rs.getString("locationName"), +// rs.getString("locationEmail"), +// rs.getString("locationDescription"), +// rs.getString("locationPlace"), +// rs.getString("locationTrailID"), +// rs.getBoolean("locationApproved") +// ); +// } +// @Autowired +// public void LocationRepositoryJDBC(JdbcTemplate jdbc){ +// this.jdbcTemplate = jdbc; +// locationRepositoryJDBC = new LocationRepositoryJDBC(jdbc); +// } +// +// +// +// +// @Test +// public void test(){ +// +// } +// +// +//} \ No newline at end of file diff --git a/src/test/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesTest.java b/src/test/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..933541d774f1666db611121fd72377a02c73c78c --- /dev/null +++ b/src/test/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesTest.java @@ -0,0 +1,82 @@ +package Team5.SmartTowns.placeswithcoordinates; + +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) +@SpringBootTest +class PlacesCoordinatesTest { + + @Autowired + PlacesCoordinatesRepository placesCoordinatesRepository; + + @Autowired + JdbcTemplate jdbcTemplate; + + @BeforeEach + void setUp() { + /* Ensures that each test starts with a clean table*/ + jdbcTemplate.update("DELETE FROM locationCoordinates"); + } + + @AfterEach + void tearDown() { + jdbcTemplate.update("DELETE FROM locationCoordinates"); + } + + @Test + void getAllLocationCoords() { + jdbcTemplate.update("insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (2, 51.57623, -3.21910 )"); + jdbcTemplate.update("insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (3, 51.57623, -3.21910 )"); + jdbcTemplate.update("insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (4, 51.57623, -3.21910 )"); + + List<Long> expected = jdbcTemplate.queryForList("SELECT locationID FROM locationcoordinates", Long.class); + List<LocationsCoordinates> allObjects = placesCoordinatesRepository.getAllLocationCoords(); + assertEquals(expected.size(), allObjects.size()); + assertEquals(expected.get(0), allObjects.get(0).getLocationID()); + assertEquals(expected.get(1), allObjects.get(1).getLocationID()); + assertEquals(expected.get(2), allObjects.get(2).getLocationID()); + } + + @Test + void getAllTownCoords() { + } + + @Test + void addLocationCoord() { + int locationID = 1; + double locationCoordsLat = 1.5; + double locationCoordsLong = 1.5; + placesCoordinatesRepository.addLocationCoord( + new LocationsCoordinates(1, locationCoordsLat, locationCoordsLong) + ); + + double resultLat = jdbcTemplate.queryForObject( + "SELECT locationCoordsLat FROM locationcoordinates WHERE locationID=?", + Double.class, locationID); + double resultLong = jdbcTemplate.queryForObject( + "SELECT locationCoordsLat FROM locationcoordinates WHERE locationID=?", + Double.class, locationID); + + + + assertEquals(locationCoordsLat, resultLat); + assertEquals(locationCoordsLong, resultLong); + } + + + @Test + void getFullApprovedLocations() { + + } + + @Test + void getLocationTableIDValue() { + } +} \ No newline at end of file diff --git a/src/test/java/testTwo.java b/src/test/java/testTwo.java new file mode 100644 index 0000000000000000000000000000000000000000..225fb28724e8c0dc26ba5ad295dd166b52498969 --- /dev/null +++ b/src/test/java/testTwo.java @@ -0,0 +1,52 @@ +////package Team5.SmartTowns.data; +// +////import org.junit.platform.commons.util.Preconditions; +//// +//import Team5.SmartTowns.data.Location; +//import Team5.SmartTowns.data.LocationRepository; +//import Team5.SmartTowns.data.LocationRepositoryJDBC; +//import org.junit.jupiter.api.BeforeAll; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.jdbc.core.JdbcTemplate; +//import org.springframework.jdbc.core.RowMapper; +// +//import static org.junit.jupiter.api.Assertions.assertEquals; +// +// +////@SpringBootTest +//public class testTwo { +// +//private JdbcTemplate jdbcTemplate; +//private LocationRepositoryJDBC locationRepositoryJDBC; +// +//private RowMapper<Location> locationMapper; +// +//@Autowired +//private LocationRepository locationRepository; +// +// +//@Autowired +// public void LocationRepositoryJDBC(JdbcTemplate jdbc){ +// this.jdbcTemplate = jdbc; +// locationRepositoryJDBC = new LocationRepositoryJDBC(jdbc); +//} +// +// +//@BeforeAll +//public static void setUp(){ +// locationRepository = new LocationRepositoryJDBC.getAllLocation(); +//// locationRepository = (LocationRepositoryJDBC) locationRepository.getAllLocation(); +//} +// +//@Test +//public void test(){ +// int aa=1; +// assertEquals(1,aa); +// +// } +// +// +// +//} diff --git a/src/test/resources/data.sql b/src/test/resources/data.sql new file mode 100644 index 0000000000000000000000000000000000000000..c2259e46e52a7b84e4dabf968a3c315118ff253a --- /dev/null +++ b/src/test/resources/data.sql @@ -0,0 +1,74 @@ +# delete from users; +# insert into users (email, name) value ('hannah@gmail.com', 'Hannah'); +# insert into users (email, name) value ('nigel@gmail.com', 'Nigel'); +# +# +# insert into trails ( trailID, trailName, trailNumber) value ( 0101,'Caerphilly Castle Trail','0101'); +# insert into trails ( trailID, trailName, trailNumber) value ( 0102,'Caerphilly Pub Trail','0102'); +# insert into trails ( trailID, trailName, trailNumber) value ( 0103,'Caerphilly Heritage Trail','0103'); +# insert into trails ( trailID, trailName, trailNumber) value ( 0201,'Risca Heritage Trail','0201'); +# insert into trails ( trailID, trailName, trailNumber) value ( 0301,'Penarth Esplanade Trail','0301'); +# +# +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'St Cenydd','','Location description here','Caerphilly',0101, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Castle','','Location description here','Caerphilly',0101, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Medieval Trades','','Location description here','Caerphilly',0101, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Queen''s War','','Location description here','Caerphilly',0101, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Green Lady','','Location description here','Caerphilly',0101, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Armoury','','Location description here','Caerphilly',0101, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Architecture','','Location description here','Caerphilly',0101, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( '21st Century Landmark','','Location description here','Caerphilly',0101, true); +# +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'JD Wetherspoons-Malcolm Uphill','','Location description here','Caerphilly',0102, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Cwtch','','Location description here','Caerphilly',0102, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The King''s Arms','','Location description here','Caerphilly',0102, true); +# +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Bus Station','','Location description here','Caerphilly',0103, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ('Caerphilly Castle','','Location description here','Caerphilly',0103, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Risca Colliery','','Location description here','Risca',0201, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Esplanade','','Location description here','Penarth',0301, true); +# insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Old Swimming Baths','','Location description here','Penarth',0301, true); +# +# +# +# insert into packs (name, description) value ('Wales Football Team', 'Pack of Welsh Football Players in the National Team'); +# insert into packs (name, description) value ('Wales Rugby Team', 'Pack of Welsh Rugby Players in the National Team'); +# insert into packs (name, description) value ('Welsh Heritage', 'Pack About Welsh Heritage'); +# +# +# +# insert into stickers (packID, stickerID, name, description, rarity) value (1, 1, 'wayne_hennessey', 'Wales Football Team Player', '2'); +# insert into stickers (packID, stickerID, name, description, rarity) value (1, 2, 'neco_williams', 'Wales Football Team Player', '2'); +# insert into stickers (packID, stickerID, name, description, rarity) value (1, 3, 'joe_morrell', 'Wales Football Team Player', '2'); +# insert into stickers (packID, stickerID, name, description, rarity) value (1, 4, 'ethan_ampadu', 'Wales Football Team Player', '2'); +# insert into stickers (packID, stickerID, name, description, rarity) value (1, 5, 'connor_roberts', 'Wales Football Team Player', '2'); +# insert into stickers (packID, stickerID, name, description, rarity) value (2, 1, 'Taine_Basham', 'Wales Rugby Team Player', '1'); +# insert into stickers (packID, stickerID, name, description, rarity) value (2, 2, 'Adam Beard', 'Wales Rugby Team Player', '1'); +# insert into stickers (packID, stickerID, name, description, rarity) value (2, 3, 'Elliot Dee', 'Wales Rugby Team Player', '1'); +# insert into stickers (packID, stickerID, name, description, rarity) value (2, 4, 'Corey Domachowski', 'Wales Rugby Team Player', '1'); +# insert into stickers (packID, stickerID, name, description, rarity) value (2, 5, 'Ryan Elias', 'Wales Rugby Team Player', '1'); +# insert into stickers (packID, stickerID, name, description, rarity) value (3, 1, 'Welsh Lady', 'Welsh Heritage', '1'); +# insert into stickers (packID, stickerID, name, description, rarity) value (3, 2, 'Welsh Outline', 'Welsh Heritage', '1'); +# insert into stickers (packID, stickerID, name, description, rarity) value (3, 3, 'Welsh Spoon', 'Welsh Heritage', '1'); +# +# +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (2, 51.57623, -3.21910 ); +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (3, 51.575372, -3.219186); +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (4, 51.576363, -3.220712 ); +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (9, 51.57239, -3.21992); +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (10, 51.57230, -3.21938 ); +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (13, 51.57168, -3.21861); +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (14, 51.57465, -3.22022 ); +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (17, 51.61117, -3.10198 ); +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (18, 51.61655, -3.12371 ); +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (19, 51.43484, -3.16492 ); +# insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (20, 51.43547, -3.16789 ); +# +# +# insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Caerphilly', '51.57903','-3.22075 ','51.60418','51.55093','-3.25222','-3.17696'); +# insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Risca','51.61195','-3.09648','51.63039','51.59175','-3.12129','-3.06438'); +# insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Penarth','51.43893','-3.17354','51.44878','51.41233','-3.20271','-3.16005'); \ No newline at end of file diff --git a/src/test/resources/schema-test.sql b/src/test/resources/schema-test.sql index 744c10245fa965d81b641fc0cf3231ea612782a7..60304bee1fb5f57502846d60fea88d90713c1735 100644 --- a/src/test/resources/schema-test.sql +++ b/src/test/resources/schema-test.sql @@ -5,18 +5,29 @@ DROP DATABASE IF EXISTS test_towns; CREATE DATABASE IF NOT EXISTS test_towns; USE test_towns; -DROP TABLE IF EXISTS trails; -DROP TABLE IF EXISTS locations; +/****************************************************************/ + +/* DROPS ALL TABLES IF THEY EXIST (they wont but just in case) */ + +drop table if exists locationCoordinates; +drop table if exists locations; +drop table if exists trails; DROP TABLE IF EXISTS users; DROP TABLE IF EXISTS stickers; DROP TABLE IF EXISTS packs; DROP TABLE IF EXISTS stickerProgress; -CREATE TABLE IF NOT EXISTS trails ( - trailID bigint auto_increment primary key, - name varchar(128), - tru boolean + +/****************************************************************/ + +/* CREATES ALL TABLES */ + +create table if not exists trails +( + trailID varchar(128) primary key, + trailName varchar(128), + trailNumber varchar(128) ) engine=InnoDB; drop table if exists locationCoordinates; @@ -31,6 +42,8 @@ create table if not exists locations locationTrailID varchar(128), locationApproved boolean ) engine=InnoDB; + + CREATE TABLE IF NOT EXISTS users ( username varchar(30) primary key NOT NULL, id bigint auto_increment unique, /*DEPRECATED COLUMN, LEFT IN WHILE SOME OTHER FUNCTIONS STILL USE IT*/ @@ -62,7 +75,6 @@ CREATE TABLE IF NOT EXISTS stickers ( description text NOT NULL, rarity tinyint ); - CREATE TABLE IF NOT EXISTS stickerProgress ( id bigint auto_increment primary key, username varchar(30) NOT NULL, @@ -107,4 +119,3 @@ create table if not exists townsWithTrails )engine=InnoDB; - diff --git a/src/test/resources/schema.sql b/src/test/resources/schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..70cf59c3ea7e21770133191348ff79616c78622a --- /dev/null +++ b/src/test/resources/schema.sql @@ -0,0 +1,108 @@ +# DROP DATABASE test_towns; +# CREATE DATABASE test_towns; +# USE test_towns; +# +# +# drop table if exists locationCoordinates; +# drop table if exists locations; +# drop table if exists trails; +# +# create table if not exists trails +# ( +# trailID varchar(128) primary key, +# trailName varchar(128), +# trailNumber varchar(128) +# ) engine=InnoDB; +# +# +# create table if not exists locations +# ( +# locationID bigint auto_increment primary key, +# locationName varchar(128), +# locationEmail varchar(128), +# locationDescription longtext, +# locationPlace varchar(255), +# locationTrailID varchar(128), +# Foreign Key (locationTrailID) REFERENCES trails(trailID) +# ON DELETE CASCADE +# ON UPDATE RESTRICT, +# locationApproved boolean +# ) engine=InnoDB; +# +# +# drop table if exists users; +# drop table if exists stickers; +# drop table if exists packs; +# drop table if exists stickerProgress; +# +# create table if not exists users +# ( +# id bigint auto_increment primary key, +# email varchar(128), +# name varchar(30), +# dragonProgress int, +# dragonsLandmarkIDs longtext +# ) engine=InnoDB; +# +# +# create table if not exists packs +# ( +# id bigint auto_increment primary key, +# name varchar(20), +# description text +# ) engine=InnoDB; +# +# create table if not exists stickers +# ( +# id bigint auto_increment primary key, +# packID bigint, +# FOREIGN KEY (packID) REFERENCES packs(id) +# ON DELETE CASCADE +# ON UPDATE RESTRICT, +# stickerID bigint, /*STICKER ID NUMBER WITHIN ITS OWN PACK*/ +# name varchar(30), +# description text, +# rarity tinyint +# +# ) engine=InnoDB; +# +# create table if not exists stickerProgress +# ( +# id bigint auto_increment primary key, +# userID bigint, +# stickerID bigint +# ) engine=InnoDB; +# +# +# +# +# +# create table if not exists locationCoordinates +# ( +# locationCoordID bigint auto_increment primary key, +# locationID bigint, +# Foreign Key (locationID) REFERENCES locations(locationID) +# ON DELETE CASCADE +# ON UPDATE RESTRICT, +# locationCoordsLat DECIMAL(8,6), +# locationCoordsLong DECIMAL(8,6) +# +# +# )engine=InnoDB; +# +# +# drop table if exists townsWithTrails; +# create table if not exists townsWithTrails +# ( +# townID bigint auto_increment primary key, +# townName varchar(128), +# townCentreCoordsLat varchar(128), +# townCentreCoordsLong varchar(128), +# townUppermostCoordsLat varchar(128), +# townLowermostCoordsLat varchar(128), +# townLeftmostCoordsLong varchar(128), +# townRightmostCoordsLong varchar(128) +# +# )engine=InnoDB; +# +# diff --git a/src/test/resources/test-data.sql b/src/test/resources/test-data.sql index 05db12e66b276dace05661710dff01ba513875d7..f2e5430167e4ec54f04063fc60dd41c28d216b0a 100644 --- a/src/test/resources/test-data.sql +++ b/src/test/resources/test-data.sql @@ -1,39 +1,67 @@ +# delete from users; +# insert into users (email, name) value ('hannah@gmail.com', 'Hannah'); +# insert into users (email, name) value ('nigel@gmail.com', 'Nigel'); + delete from trails; -insert into trails ( Name,tru) value ( 'Caerphilly Coffee Trail',false); -insert into trails ( Name,tru) value ( 'Penarth Dragon Trail',true); +insert into trails ( trailID, trailName, trailNumber) value ( 0101,'Caerphilly Castle Trail','0101'); +insert into trails ( trailID, trailName, trailNumber) value ( 0102,'Caerphilly Pub Trail','0102'); +insert into trails ( trailID, trailName, trailNumber) value ( 0103,'Caerphilly Heritage Trail','0103'); +insert into trails ( trailID, trailName, trailNumber) value ( 0201,'Risca Heritage Trail','0201'); +insert into trails ( trailID, trailName, trailNumber) value ( 0301,'Penarth Esplanade Trail','0301'); delete from locations; -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'St Cenydd','','Location description here','Caerphilly',0101, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'St Cenydd','','Location description here','Caerphilly',0101, false); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Castle','','Location description here','Caerphilly',0101, true); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Medieval Trades','','Location description here','Caerphilly',0101, true); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Queen''s War','','Location description here','Caerphilly',0101, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Green Lady','','Location description here','Caerphilly',0101, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Armoury','','Location description here','Caerphilly',0101, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Architecture','','Location description here','Caerphilly',0101, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( '21st Century Landmark','','Location description here','Caerphilly',0101, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Green Lady','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Armoury','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Architecture','','Location description here','Caerphilly',0101, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( '21st Century Landmark','','Location description here','Caerphilly',0101, false); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'JD Wetherspoons-Malcolm Uphill','','Location description here','Caerphilly',0102, true); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Cwtch','','Location description here','Caerphilly',0102, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The King''s Arms','','Location description here','Caerphilly',0102, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The King''s Arms','','Location description here','Caerphilly',0102, false); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Caerphilly Bus Station','','Location description here','Caerphilly',0103, true); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ('Caerphilly Castle','','Location description here','Caerphilly',0103, true); -insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103, true); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ('Caerphilly Castle','','Location description here','Caerphilly',0103, false); +insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103, false); + insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Risca Colliery','','Location description here','Risca',0201, true); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201, true); + insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Esplanade','','Location description here','Penarth',0301, true); insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Old Swimming Baths','','Location description here','Penarth',0301, true); +DELETE FROM locationCoordinates; +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (2, 51.57623, -3.21910 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (3, 51.575372, -3.219186); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (4, 51.576363, -3.220712 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (9, 51.57239, -3.21992); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (10, 51.57230, -3.21938 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (13, 51.57168, -3.21861); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (14, 51.57465, -3.22022 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (17, 51.61117, -3.10198 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (18, 51.61655, -3.12371 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (19, 51.43484, -3.16492 ); +insert into locationCoordinates(locationID, locationCoordsLat, locationCoordsLong) value (20, 51.43547, -3.16789 ); + +# delete from badges; +# insert into badges (name, description, difficulty) value ('TownConnoisseur', 'You know the town very well!', '2'); +# insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); +# insert into badges (name, description, difficulty) value ('TownMaster', 'You visited the town 7 days in a row!', '1'); +# insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); +# insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1'); +delete from packs; +insert into packs (name, description) value ('Wales Football Team', 'Pack of Welsh Football Players in the National Team'); +insert into packs (name, description) value ('Wales Rugby Team', 'Pack of Welsh Rugby Players in the National Team'); +insert into packs (name, description) value ('Welsh Heritage', 'Pack About Welsh Heritage'); -DELETE FROM packs; -INSERT INTO packs (name, description) VALUE ('Wales Football Team', 'Pack of Welsh Football Players in the National Team'); -INSERT INTO packs (name, description) VALUE ('Wales Rugby Team', 'Pack of Welsh Rugby Players in the National Team'); -INSERT INTO packs (name, description) VALUE ('Welsh Heritage', 'Pack About Welsh Heritage'); DELETE FROM stickers; INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (1, 1, 'wayne_hennessey', 'Wales Football Team Player', '2'); @@ -50,19 +78,27 @@ INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 1, INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 2, 'Welsh Outline', 'Welsh Heritage', '1'); INSERT INTO stickers (packID, stickerID, name, description, rarity) VALUE (3, 3, 'Welsh Spoon', 'Welsh Heritage', '1'); -INSERT INTO users (username, password) VALUE ('Admin', 'admin'); -INSERT INTO users (username, password) VALUE ('Hannah', 'root'); -INSERT INTO users (username, password) VALUE ('Nigel', 'root'); -INSERT INTO users (username, password) VALUE ('Oscar', 'root'); -INSERT INTO users (username, email, password) VALUE ('kevin','Kevin@Gmail.com' ,'root'); - -INSERT INTO authorities (username, authority) VALUE ('Admin', 'ADMIN'); -INSERT INTO authorities (username, authority) VALUE ('Hannah', 'USER'); - -DELETE FROM stickerprogress; -INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 1, 1); -INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 1, 2); -INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 1, 3); -INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 1, 5); -INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 2, 1); -INSERT INTO stickerprogress (username, packID, stickerID) VALUE ('Admin', 2, 3); +# delete from stickerprogress; +# insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '1', true); +# insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '3', true); +# insert into stickerprogress (userID, stickerID, hasSticker) value ('2', '2', true); + + + + + + +# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 1); +# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 2); +# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 3); +# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 5); +# insert into stickerprogress (userID, packID, stickerID) value (1, 2, 1); +# insert into stickerprogress (userID, packID, stickerID) value (1, 2, 3); + + + +# +delete from townsWithTrails; +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Caerphilly', '51.57903','-3.22075 ','51.60418','51.55093','-3.25222','-3.17696'); +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Risca','51.61195','-3.09648','51.63039','51.59175','-3.12129','-3.06438'); +insert into townsWithTrails (townName, townCentreCoordsLat, townCentreCoordsLong, townUppermostCoordsLat, townLowermostCoordsLat, townLeftmostCoordsLong, townRightmostCoordsLong) value ('Penarth','51.43893','-3.17354','51.44878','51.41233','-3.20271','-3.16005'); \ No newline at end of file