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

integrated location/landamrk table with landamrk signup form todo:...

integrated location/landamrk table with landamrk signup form todo: lcoationDEescription constricted by varchar(250), find better way to implement large text
parent dbd4a46d
No related branches found
No related tags found
1 merge request!23Resolve "As a developer I want all landmarks to be stored together"
......@@ -11,10 +11,54 @@ import lombok.Data;
public class location {
private int locationID;
private String locationName;
// private String locationEmail;
// private String locationDescription;
// private String locationPlace; //todo revert this
// private int locationTrailID;
private String locationEmail;
private String locationDescription;
private String locationPlace;
private int locationTrailID;
@Override
public String toString() {
return "location{" +
"" + locationID +
", '" + locationName + '\'' +
", '" + locationEmail + '\'' +
", '" + locationDescription + '\'' +
", '" + locationPlace + '\'' +
", " + locationTrailID +
'}';
}
public int getLocationID() {
return locationID;
}
public String getLocationName() {
return locationName;
}
public String getLocationEmail() {
return locationEmail;
}
public String getLocationDescription() {
return locationDescription;
}
public String getLocationPlace() {
return locationPlace;
}
public int getLocationTrailID() {
return locationTrailID;
}
// public location(int locationID, String locationName, String locationEmail, String locationDescription, String locationPlace, int locationTrailID) {
// this.locationID = locationID;
// this.locationName = locationName;
// this.locationEmail = locationEmail;
// this.locationDescription = locationDescription;
// this.locationPlace = locationPlace;
// this.locationTrailID = locationTrailID;
// }
}
//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 llocation);
}
//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
......@@ -19,15 +21,32 @@ public class locationRepositoryJDBC implements locationRepository {
private void setlocationMapper(){
locationMapper = (rs, i) -> new location(
rs.getInt("locationID"),
rs.getString("locationName")
// rs.getString("locationEmail"),
// rs.getString("locationDescription"),
// rs.getString("locationPlace"), //todo revert this
// rs.getInt("locationTrailID")
rs.getString("locationName"),
rs.getString("locationEmail"),
rs.getString("locationDescription"),
rs.getString("locationPlace"),
rs.getInt("locationTrailID")
);
}
public List<location> getAllLocation(){
String sql= "SELECT locationID,locationName FROM locations";
String sql= "SELECT * FROM locations";
return jdbc.query(sql, locationMapper);
}
@Override
public void addLocation(location llocation) {
String sql = "insert into locations(locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) values (?,?,?,?,?,?)";
jdbc.update(sql, llocation.getLocationID(),llocation.getLocationName(),llocation.getLocationEmail(),llocation.getLocationDescription(),llocation.getLocationPlace(),llocation.getLocationTrailID());
}
// public void insertLocation(Landmarks landmark){
// String sql = "INSERT INTO locations(locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID)"+"VALUES("+ landmark.getLandmarkID()+","+","+landmark.getLandmarkName()+","+landmark.getLandmarkEmail()+","+landmark.getLandmarkDescription()+","+landmark.getLandmarkLocation()+","+landmark.getTrailID()+")";
// try{
// executeUpdate(sql);
// }
// catch(SQLException e){
//
// }
// }
}
package Team5.SmartTowns.Landmarks;
import Team5.SmartTowns.Data.location;
import Team5.SmartTowns.Data.locationRepository;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
......@@ -8,6 +11,8 @@ 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 java.sql.PreparedStatement;
//import jakarta.validation.Valid;
@Controller
......@@ -22,7 +27,8 @@ public class LandmarksController {
}
@Autowired
private locationRepository locationRepository;
@PostMapping("/landmarkSub")
public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model ) {
......@@ -33,6 +39,10 @@ public class LandmarksController {
} else{
System.out.println(landmarks);
location loc= new location(landmarks.getLandmarkID(),landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID());
locationRepository.addLocation(loc);
......
......@@ -11,7 +11,7 @@ create table if not exists locations
locationID bigint auto_increment primary key,
locationName varchar(128),
locationEmail varchar(128),
locationDescription varchar(255),
locationDescription varchar(max),
locationPlace varchar(255),
locationTrailID varchar(128)
) engine=InnoDB;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment