Newer
Older
//Implements the locations repository using JDBC
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
public class LocationRepositoryJDBC implements LocationRepository {
Rhys Evans
committed
private RowMapper<Location> locationMapper;
Rhys Evans
committed
// public LocationRepositoryJDBC() {
// JdbcTemplate ajdbc = new JdbcTemplate();
// this.jdbc =ajdbc;
// setlocationMapper();
//
// }
Rhys Evans
committed
locationMapper = (rs, i) -> new Location(
rs.getString("locationName"),
rs.getString("locationEmail"),
rs.getString("locationDescription"),
rs.getString("locationPlace"),
rs.getString("locationTrailID"),
rs.getBoolean("locationApproved")
Rhys Evans
committed
public List<Location> getAllLocation(){
String sql= "SELECT * FROM locations";
Rhys Evans
committed
// public LocationRepositoryJDBC() {
// JdbcTemplate ajdbc = new JdbcTemplate();
// this.jdbc =ajdbc;
// setlocationMapper();
//
// }
// public LocationRepositoryJDBC(JdbcTemplate jdbc, RowMapper<Location> locationMapper) {
// this.jdbc = jdbc;
// this.locationMapper = locationMapper;
// }
public List<Location> getAllApprovedLocation(){
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;
}
public List<Location> getAllUnapprovedLocation(){
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;
}
Rhys Evans
committed
@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(), false);
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;
Rhys Evans
committed
//
// @Override
// public List<Location> getApprovedLocations2(List<Location> list){
//
// List<Location> locationApprovalList= new ArrayList<Location>();
// for (Location loc :list){
// if (loc.isLocationApproved()) {
// locationApprovalList.add(loc);
// }
// } return locationApprovalList;
// }
//
@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() {
// return jdbc;
// }