diff --git a/src/main/java/Team5/SmartTowns/Data/DatabaseController.java b/src/main/java/Team5/SmartTowns/Data/DatabaseController.java index 0d38e955dd0a2e38e9585e5560d1cd4b6df83033..c7f3b2618a2164657614cf439d5c3e6c668c2b5c 100644 --- a/src/main/java/Team5/SmartTowns/Data/DatabaseController.java +++ b/src/main/java/Team5/SmartTowns/Data/DatabaseController.java @@ -32,4 +32,17 @@ public class DatabaseController { mav2.addObject("location", Locations); return mav2; } + +// + public List<Location> approvedLocations(){ + List<Location> locations = locationRepository.getAllLocation(); + List<Location> locationApprovalList; +// for (int i=0;i<locations.size();i++){ +// location + for (Location loc :locations){ + if (loc.isLocationApproved()) { + locationApprovalList.add(loc); + } + } return locationApprovalList; + } } diff --git a/src/main/java/Team5/SmartTowns/Data/Location.java b/src/main/java/Team5/SmartTowns/Data/Location.java index 01ba2932c6b7d0a6201aa8128161bf7ad8b27526..8d4a18e2c3867a7bbefa0a6ac521d0caf3f62c65 100644 --- a/src/main/java/Team5/SmartTowns/Data/Location.java +++ b/src/main/java/Team5/SmartTowns/Data/Location.java @@ -13,6 +13,8 @@ public class Location { private String locationPlace; private int locationTrailID; + private boolean locationApproved; + @Override public String toString() { return "Location{" + @@ -21,6 +23,7 @@ public class Location { locationDescription + '\'' + locationPlace + '\'' + locationTrailID + + locationApproved+ '}'; } @@ -44,5 +47,7 @@ public class Location { return locationTrailID; } - + public boolean isLocationApproved() { + return locationApproved; + } } diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepository.java b/src/main/java/Team5/SmartTowns/Data/locationRepository.java index 822a18cb860654694734c7f591cbb5b216eb8a39..35e0ddbd5494b880c8ccd29035b1ecf16218c992 100644 --- a/src/main/java/Team5/SmartTowns/Data/locationRepository.java +++ b/src/main/java/Team5/SmartTowns/Data/locationRepository.java @@ -7,6 +7,6 @@ import java.util.List; public interface locationRepository { List<Location> getAllLocation(); void addLocation(Location loc); - + List<Location> approvedLocations(); } diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java index a5e79d4442d540f5dba67ee7f2b6217984044ebb..6baeca341af375a247826b468100a721807828a3 100644 --- a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java @@ -5,6 +5,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Repository; +import java.util.ArrayList; import java.util.List; @Repository @@ -23,7 +24,8 @@ public class locationRepositoryJDBC implements locationRepository { rs.getString("locationEmail"), rs.getString("locationDescription"), rs.getString("locationPlace"), - rs.getInt("locationTrailID") + rs.getInt("locationTrailID"), + rs.getBoolean("locationApproved") ); } public List<Location> getAllLocation(){ @@ -33,10 +35,23 @@ public class locationRepositoryJDBC implements locationRepository { @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) values (?,?,?,?,?)"; + 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()); } + @Override + public List<Location> approvedLocations(){ + List<Location> locations = getAllLocation(); + List<Location> locationApprovalList= new ArrayList<>(); +// for (int i=0;i<locations.size();i++){ +// location + for (Location loc :locations){ + if (loc.isLocationApproved()) { + locationApprovalList.add(loc); + } + } return locationApprovalList; + } + } diff --git a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java index a94feef88935a8d3ca71f6326bdb8f44cda6dd0e..046a60d26a10759aa533c8a88e72c17af054748e 100644 --- a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java +++ b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java @@ -37,7 +37,7 @@ 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()); + 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"); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index e40208ba343bab8aeb675e792a3566fd0e573028..838a859b2258a7e64deea5a7eb529d12401b1c43 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -7,31 +7,31 @@ insert into trails ( Name) value ( 'Caerphilly Coffee Trail'); insert into trails ( Name) value ( 'Penarth Dragon Trail'); 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); +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 (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value (19, 'The Esplanade','','Location description here','Penarth',0301, true); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value (20, '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'); diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 92b8d4e0377d6ceeb58aef53b35e946670b6bc62..264fc1e2b2b758a15447a6e2366ab00750ead704 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -14,7 +14,8 @@ 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; diff --git a/src/main/resources/templates/towns/MapApiTest.html b/src/main/resources/templates/towns/MapApiTest.html index 447032514e5dfcb0f2f876593e5c995ad4248681..67b5feac1fd015fc0b31b5e35b002d84d70dfa13 100644 --- a/src/main/resources/templates/towns/MapApiTest.html +++ b/src/main/resources/templates/towns/MapApiTest.html @@ -14,9 +14,17 @@ <div class="map"> <!-- test data from hackathon--> + <p> Google maps embedding;</p> <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d9933.490822613407!2d-3.1845439261935375!3d51.506377949006364!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x486e1c8d0919099f%3A0x60bea7f0ae155f28!2sRoath%20Park!5e0!3m2!1sen!2suk!4v1698921027199!5m2!1sen!2suk" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe> </div> + <div class="map2"> + <!-- test data from hackathon--> + <p> Google maps embedding;</p> + + </div> + + </main> <footer th:insert="~{/towns/Templating.html::footer}"></footer> </body> diff --git a/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java b/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java index d9c15a4bf0557ca94619ec9f61d0d83d2180c7c3..cafd1c8680a65e11a16273c4b1f5226c57df24d9 100644 --- a/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java +++ b/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java @@ -1,8 +1,22 @@ package Team5.SmartTowns; +import Team5.SmartTowns.Data.DatabaseController; +import Team5.SmartTowns.Data.Location; +import Team5.SmartTowns.Data.locationRepository; +import Team5.SmartTowns.Landmarks.Landmarks; +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 static org.junit.jupiter.api.Assertions.assertEquals; + +import java.lang.annotation.Inherited; +import java.util.List; + +import static sun.java2d.pipe.PixelToParallelogramConverter.len; + + @SpringBootTest class SmartTownsApplicationTests { @@ -10,4 +24,48 @@ class SmartTownsApplicationTests { void contextLoads() { } -} + private static Landmarks landamrk; + private static Location location; + @Autowired + private locationRepository locationRepository; + + @Test + public void whenAddingLocationsNonApprovedLocationsDontShowInTrails(){ + /// Discover number of approved/unapproved locations before adding tests +// DatabaseController.approvedLocations(); + + int locationFailureNumber= locations.size()-locationApprovalList.size(); // ensure number always positive + + Location loc1= new Location("TestFail", "Test@PleaseFail.test", "Fail Description here", + "Caerphilly", 103, false); + Location loc2= new Location("TestFail", "Test@PleaseFail.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> locationsAfter = locationRepository.getAllLocation(); + List<String> locationApprovalListAfter = null; + List<String> locationFailureListAfter = null; +// for (int i=0;i<locations.size();i++){ +// location + for (Location loc :locationsAfter){ + if (loc.isLocationApproved()) { + locationApprovalListAfter.add(loc.getLocationName()); + } else{ + locationFailureListAfter.add(loc.getLocationName());} + } + int locationFailureNumberAfter= locations.size()-locationApprovalListAfter.size(); // ensure number always positive + assertEquals(2,locationFailureNumber-locationFailureNumberAfter); + } + + + + + +// locationRepository.addLocation(loc); // adds valid landmark to locations table +// ModelAndView modelAndView = new ModelAndView("redirect:/home"); + } + +