diff --git a/src/main/java/Team5/SmartTowns/Data/DatabaseController.java b/src/main/java/Team5/SmartTowns/Data/DatabaseController.java index b91d7d880368f6cb405e3ed71c38242f612bfae2..0eed9aca6601fa11eab58684cbf54bae225d5a35 100644 --- a/src/main/java/Team5/SmartTowns/Data/DatabaseController.java +++ b/src/main/java/Team5/SmartTowns/Data/DatabaseController.java @@ -33,8 +33,8 @@ public class DatabaseController { @GetMapping("locationList") public ModelAndView locationList(){ ModelAndView mav2 = new ModelAndView("towns/locationData"); - List<location> locations = locationRepository.getAllLocation(); - mav2.addObject("location", locations); + List<Location> Locations = locationRepository.getAllLocation(); + mav2.addObject("location", Locations); return mav2; } } diff --git a/src/main/java/Team5/SmartTowns/Data/location.java b/src/main/java/Team5/SmartTowns/Data/Location.java similarity index 56% rename from src/main/java/Team5/SmartTowns/Data/location.java rename to src/main/java/Team5/SmartTowns/Data/Location.java index 660a7f961cedae5c346b7683a45fb1bd6a8acd7c..01ba2932c6b7d0a6201aa8128161bf7ad8b27526 100644 --- a/src/main/java/Team5/SmartTowns/Data/location.java +++ b/src/main/java/Team5/SmartTowns/Data/Location.java @@ -3,13 +3,10 @@ package Team5.SmartTowns.Data; import lombok.AllArgsConstructor; import lombok.Data; -//insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, -// locationTrailID -// ) value ('1', 'St Cenydd','','location description here','Caerphilly',0101); @Data @AllArgsConstructor -public class location { - private int locationID; +public class Location { +// private int locationID; private String locationName; private String locationEmail; private String locationDescription; @@ -18,21 +15,15 @@ public class location { @Override public String toString() { - return "location{" + - "" + locationID + - ", '" + locationName + '\'' + - ", '" + locationEmail + '\'' + - ", '" + locationDescription + '\'' + - ", '" + locationPlace + '\'' + - ", " + locationTrailID + + return "Location{" + + locationName + '\'' + + locationEmail + '\'' + + locationDescription + '\'' + + locationPlace + '\'' + + locationTrailID + '}'; } - - public int getLocationID() { - return locationID; - } - public String getLocationName() { return locationName; } diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepository.java b/src/main/java/Team5/SmartTowns/Data/locationRepository.java index 47c2f32703580a3197183648f5cfa87fcc1822c7..822a18cb860654694734c7f591cbb5b216eb8a39 100644 --- a/src/main/java/Team5/SmartTowns/Data/locationRepository.java +++ b/src/main/java/Team5/SmartTowns/Data/locationRepository.java @@ -1,14 +1,12 @@ //Holds locations data repository (landmarks) package Team5.SmartTowns.Data; -import Team5.SmartTowns.Landmarks.Landmarks; - import java.util.List; public interface locationRepository { - List<location> getAllLocation(); - void addLocation(location loc); + List<Location> getAllLocation(); + void addLocation(Location loc); } diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java index 3f86131a3b45b78554f6c4a7d7c561d7fcdb9668..a5e79d4442d540f5dba67ee7f2b6217984044ebb 100644 --- a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java @@ -1,26 +1,24 @@ //Implements the locations repository using JDBC package Team5.SmartTowns.Data; -import Team5.SmartTowns.Landmarks.Landmarks; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Repository; -import java.sql.SQLException; import java.util.List; @Repository public class locationRepositoryJDBC implements locationRepository { private JdbcTemplate jdbc; - private RowMapper<location> locationMapper; + private RowMapper<Location> locationMapper; public locationRepositoryJDBC(JdbcTemplate aJdbc) { this.jdbc = aJdbc; setlocationMapper(); } private void setlocationMapper(){ - locationMapper = (rs, i) -> new location( - rs.getInt("locationID"), + locationMapper = (rs, i) -> new Location( + rs.getString("locationName"), rs.getString("locationEmail"), rs.getString("locationDescription"), @@ -28,16 +26,16 @@ public class locationRepositoryJDBC implements locationRepository { rs.getInt("locationTrailID") ); } - public List<location> getAllLocation(){ + public List<Location> getAllLocation(){ String sql= "SELECT * FROM locations"; return jdbc.query(sql, locationMapper); } - @Override // intended implementation at current: user data from templates/Landmarks/LandmarkFormTh.html is added to the location table, todo change location class to Location as its better code grammar and looks funky otherwise. - public void addLocation(location loc) { - String sql = "insert into locations(locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) values (?,?,?,?,?,?)"; + @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 (?,?,?,?,?)"; - jdbc.update(sql, loc.getLocationID(),loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID()); + jdbc.update(sql,loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID()); } diff --git a/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java b/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java index c173fdf2f9b96e8dd543589e0e2babc0d9320e3d..381ccf04293b752f03e2eb743ba820c186b277dd 100644 --- a/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java +++ b/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java @@ -15,12 +15,12 @@ import java.util.List; @NoArgsConstructor public class Landmarks { - // Intialised object to getID from trail. + // Initialized object to getID from trail. //Predefined Landmark for Dragons Tale. public static List<Landmarks> landmarksDragonstrail = List.of( new Landmarks( 1, "A scent of...Dragon", "The Dragon has been spotted near by, find the QR code to continue" , "Start your discovery, at the sweet shop."), - new Landmarks( 2, "They've been found!", "Don't let them escape, find the next QR code to continue!", "location test") + new Landmarks( 2, "They've been found!", "Don't let them escape, find the next QR code to continue!", "Location test") ); private Integer trailID; diff --git a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java index a9f13567ccba98c4ebdf2a6f64d98a47df286c2f..a94feef88935a8d3ca71f6326bdb8f44cda6dd0e 100644 --- a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java +++ b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java @@ -1,6 +1,6 @@ package Team5.SmartTowns.Landmarks; -import Team5.SmartTowns.Data.location; +import Team5.SmartTowns.Data.Location; import Team5.SmartTowns.Data.locationRepository; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; @@ -11,10 +11,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.support.RedirectAttributes; - -import javax.swing.*; -import java.sql.PreparedStatement; //import jakarta.validation.Valid; @Controller @@ -40,8 +36,8 @@ public class LandmarksController { return modelAndView; } else{ - - location loc= new location(landmarks.getLandmarkID(),landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID()); + // 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()); 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 099498b3aaa853df8a979b286e2d5768168fad7a..c095af09bf246c9d2e6cc0b79a2d665e60350be8 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -7,21 +7,21 @@ insert into trails (trailID, Name) value ('1', 'Caerphilly Coffee Trail'); insert into trails (trailID, Name) value ('2', 'Penarth Dragon Trail'); delete from locations; -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (1, 'St Cenydd','','location description here','Caerphilly',0101); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (2, 'The Castle','','location description here','Caerphilly',0101); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (3, 'Medieval Trades','','location description here','Caerphilly',0101); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (4, 'The Queen''s War','','location description here','Caerphilly',0101); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (5, 'The Green Lady','','location description here','Caerphilly',0101); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (6, 'Armoury','','location description here','Caerphilly',0101); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (7, 'Architecture','','location description here','Caerphilly',0101); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (8, '21st Century Landmark','','location description here','Caerphilly',0101); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (1, 'St Cenydd','','Location description here','Caerphilly',0101); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (2, 'The Castle','','Location description here','Caerphilly',0101); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (3, 'Medieval Trades','','Location description here','Caerphilly',0101); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (4, 'The Queen''s War','','Location description here','Caerphilly',0101); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (5, 'The Green Lady','','Location description here','Caerphilly',0101); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (6, 'Armoury','','Location description here','Caerphilly',0101); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (7, 'Architecture','','Location description here','Caerphilly',0101); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (8, '21st Century Landmark','','Location description here','Caerphilly',0101); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (9, 'JD Wetherspoons-Malcolm Uphill','','location description here','Caerphilly',0102); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (10, 'Caerphilly Cwtch','','location description here','Caerphilly',0102); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (11, 'Caerphilly Conservative Club','','location description here','Caerphilly',0102); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (12, 'The King''s Arms','','location description here','Caerphilly',0102); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (9, 'JD Wetherspoons-Malcolm Uphill','','Location description here','Caerphilly',0102); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (10, 'Caerphilly Cwtch','','Location description here','Caerphilly',0102); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (11, 'Caerphilly Conservative Club','','Location description here','Caerphilly',0102); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (12, 'The King''s Arms','','Location description here','Caerphilly',0102); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (13, 'Caerphilly Bus Station','','location description here','Caerphilly',0103); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (14, 'The Medieval Courthouse','','location description here','Caerphilly',0103); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (15 ,'Caerphilly Castle','','location description here','Caerphilly',0103); -insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (16, 'Ty Vaughan House','','location description here','Caerphilly',0103); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (13, 'Caerphilly Bus Station','','Location description here','Caerphilly',0103); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (14, 'The Medieval Courthouse','','Location description here','Caerphilly',0103); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (15 ,'Caerphilly Castle','','Location description here','Caerphilly',0103); +insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (16, 'Ty Vaughan House','','Location description here','Caerphilly',0103);