Skip to content
Snippets Groups Projects
Commit bd9eb068 authored by Rhys Evans's avatar Rhys Evans
Browse files

Renamed location.class to Location.class for better disinguishment. Followed...

Renamed location.class to Location.class for better disinguishment. Followed feedback provided by RN and removed unnecessary locationID variable within Location class
parent fc8ff8da
No related branches found
No related tags found
1 merge request!23Resolve "As a developer I want all landmarks to be stored together"
...@@ -33,8 +33,8 @@ public class DatabaseController { ...@@ -33,8 +33,8 @@ public class DatabaseController {
@GetMapping("locationList") @GetMapping("locationList")
public ModelAndView locationList(){ public ModelAndView locationList(){
ModelAndView mav2 = new ModelAndView("towns/locationData"); ModelAndView mav2 = new ModelAndView("towns/locationData");
List<location> locations = locationRepository.getAllLocation(); List<Location> Locations = locationRepository.getAllLocation();
mav2.addObject("location", locations); mav2.addObject("location", Locations);
return mav2; return mav2;
} }
} }
...@@ -3,13 +3,10 @@ package Team5.SmartTowns.Data; ...@@ -3,13 +3,10 @@ package Team5.SmartTowns.Data;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
//insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace,
// locationTrailID
// ) value ('1', 'St Cenydd','','location description here','Caerphilly',0101);
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class location { public class Location {
private int locationID; // private int locationID;
private String locationName; private String locationName;
private String locationEmail; private String locationEmail;
private String locationDescription; private String locationDescription;
...@@ -18,21 +15,15 @@ public class location { ...@@ -18,21 +15,15 @@ public class location {
@Override @Override
public String toString() { public String toString() {
return "location{" + return "Location{" +
"" + locationID + locationName + '\'' +
", '" + locationName + '\'' + locationEmail + '\'' +
", '" + locationEmail + '\'' + locationDescription + '\'' +
", '" + locationDescription + '\'' + locationPlace + '\'' +
", '" + locationPlace + '\'' + locationTrailID +
", " + locationTrailID +
'}'; '}';
} }
public int getLocationID() {
return locationID;
}
public String getLocationName() { public String getLocationName() {
return locationName; return locationName;
} }
......
//Holds locations data repository (landmarks) //Holds locations data repository (landmarks)
package Team5.SmartTowns.Data; package Team5.SmartTowns.Data;
import Team5.SmartTowns.Landmarks.Landmarks;
import java.util.List; import java.util.List;
public interface locationRepository { public interface locationRepository {
List<location> getAllLocation(); List<Location> getAllLocation();
void addLocation(location loc); void addLocation(Location loc);
} }
//Implements the locations repository using JDBC //Implements the locations repository using JDBC
package Team5.SmartTowns.Data; package Team5.SmartTowns.Data;
import Team5.SmartTowns.Landmarks.Landmarks;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.sql.SQLException;
import java.util.List; import java.util.List;
@Repository @Repository
public class locationRepositoryJDBC implements locationRepository { public class locationRepositoryJDBC implements locationRepository {
private JdbcTemplate jdbc; private JdbcTemplate jdbc;
private RowMapper<location> locationMapper; private RowMapper<Location> locationMapper;
public locationRepositoryJDBC(JdbcTemplate aJdbc) { public locationRepositoryJDBC(JdbcTemplate aJdbc) {
this.jdbc = aJdbc; this.jdbc = aJdbc;
setlocationMapper(); setlocationMapper();
} }
private void setlocationMapper(){ private void setlocationMapper(){
locationMapper = (rs, i) -> new location( locationMapper = (rs, i) -> new Location(
rs.getInt("locationID"),
rs.getString("locationName"), rs.getString("locationName"),
rs.getString("locationEmail"), rs.getString("locationEmail"),
rs.getString("locationDescription"), rs.getString("locationDescription"),
...@@ -28,16 +26,16 @@ public class locationRepositoryJDBC implements locationRepository { ...@@ -28,16 +26,16 @@ public class locationRepositoryJDBC implements locationRepository {
rs.getInt("locationTrailID") rs.getInt("locationTrailID")
); );
} }
public List<location> getAllLocation(){ public List<Location> getAllLocation(){
String sql= "SELECT * FROM locations"; String sql= "SELECT * FROM locations";
return jdbc.query(sql, locationMapper); 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. @Override // intended implementation at current: user data from templates/Landmarks/LandmarkFormTh.html is added to the Location table
public void addLocation(location loc) { public void addLocation(Location loc) {
String sql = "insert into locations(locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) values (?,?,?,?,?,?)"; 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());
} }
......
...@@ -15,12 +15,12 @@ import java.util.List; ...@@ -15,12 +15,12 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class Landmarks { public class Landmarks {
// Intialised object to getID from trail. // Initialized object to getID from trail.
//Predefined Landmark for Dragons Tale. //Predefined Landmark for Dragons Tale.
public static List<Landmarks> landmarksDragonstrail = List.of( 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( 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; private Integer trailID;
......
package Team5.SmartTowns.Landmarks; package Team5.SmartTowns.Landmarks;
import Team5.SmartTowns.Data.location; import Team5.SmartTowns.Data.Location;
import Team5.SmartTowns.Data.locationRepository; import Team5.SmartTowns.Data.locationRepository;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -11,10 +11,6 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -11,10 +11,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView; 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; //import jakarta.validation.Valid;
@Controller @Controller
...@@ -40,8 +36,8 @@ public class LandmarksController { ...@@ -40,8 +36,8 @@ public class LandmarksController {
return modelAndView; return modelAndView;
} else{ } else{
// converts valid response using Location constructor into a submittable format to the sql table
location loc= new location(landmarks.getLandmarkID(),landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID()); Location loc= new Location(landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID());
System.out.println(loc); System.out.println(loc);
locationRepository.addLocation(loc); // adds valid landmark to locations table locationRepository.addLocation(loc); // adds valid landmark to locations table
ModelAndView modelAndView = new ModelAndView("redirect:/home"); ModelAndView modelAndView = new ModelAndView("redirect:/home");
......
...@@ -7,21 +7,21 @@ insert into trails (trailID, Name) value ('1', 'Caerphilly Coffee Trail'); ...@@ -7,21 +7,21 @@ insert into trails (trailID, Name) value ('1', 'Caerphilly Coffee Trail');
insert into trails (trailID, Name) value ('2', 'Penarth Dragon Trail'); insert into trails (trailID, Name) value ('2', 'Penarth Dragon Trail');
delete from locations; 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (16, 'Ty Vaughan House','','Location description here','Caerphilly',0103);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment