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

Fixed location coordinates displaying incorrect location coordinates

parent a2ce4b54
No related branches found
No related tags found
1 merge request!42Resolve "As a site administrator I want to be able to review submitted trail checkpoints by business owners, so that they might be added to the existing trails
......@@ -8,6 +8,8 @@ public interface LocationRepository {
List<Location> getAllLocation();
void addLocation(Location loc);
void updateApprovalStatus(int locID);
List<Location> getAllApprovedLocations();
int nametoLocationID(String name);
......
......@@ -127,6 +127,12 @@ public class LocationRepositoryJDBC implements LocationRepository {
}
@Override
public void updateApprovalStatus(int locID){
String updateSql = "update locations set locationApproved = true where locationID = ?";
jdbc.update(updateSql, locID);
}
// return jdbc.queryForObject("SELECT locationApproval FROM locations WHERE locationName=?", locationID);
// public JdbcTemplate getJdbc() {
// return jdbc;
......
......@@ -57,7 +57,7 @@ public class LandmarksController {
@GetMapping("/checkpointApproval")
public ModelAndView adminCheckpointApproval(){
List<Location> unapprovedLocations = locationRepository.getAllLocation(); //change to unauthorised once merger 68 accepted!! todo
List<Location> unapprovedLocations = locationRepository.getAllUnapprovedLocations(); //change to unauthorised once merger 68 accepted!! todo
ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html");
modelAndView.addObject("uLocs", unapprovedLocations);
......@@ -76,11 +76,13 @@ public class LandmarksController {
// return modelAndView;
//
// } else{
int locationID= locationRepository.nametoLocationID(location.getLocationName());
System.out.println( locationID);
// converts valid response using Location constructor into a submittable format to the sql table
LocationsCoordinates ALocCoord = new LocationsCoordinates(locationID,locCoord.getLocationCoordsLat(),locCoord.getLocationCoordsLong());
placesCoordinatesRepo.addLocationCoord(ALocCoord); // adds valid landmark to locations table
locationRepository.updateApprovalStatus(locationID); // updates approval status accordingly
System.out.println(placesCoordinatesRepo.getAllLocationCoords());
ModelAndView modelAndView = new ModelAndView("redirect:/home"); //todo redirect to trails?
return modelAndView;
......
......@@ -14,8 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
@Controller
public class PlacesController {
......@@ -51,7 +50,7 @@ public class PlacesController {
@GetMapping("/checkpoints/{location}")
public ModelAndView getResultBySearchKeyLocation(@PathVariable String location) {
List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords();
List<LocationsCoordinates> locCoords = reorderCoordsWRTLocations(placeRepo.getAllLocationCoords());
List<Location> approvedLocations = locationRepo.getAllApprovedLocations();
int locationID = 999;
......@@ -84,7 +83,7 @@ public class PlacesController {
modelAndView.addObject("trails", trailslocations);
modelAndView.addObject("locations", approvedLocations);
modelAndView.addObject("locationCoords", locCoords);
modelAndView.addObject("locationCoords", reorderCoordsWRTLocations(locCoords));
return modelAndView;
}
......@@ -106,11 +105,53 @@ public class PlacesController {
trailID=i;
break;}
}
List<LocationsCoordinates> aa=reorderCoordsWRTLocations(locCoords);
ModelAndView modelAndView= new ModelAndView("fragments/trailsPageFrags :: trailsSection");
modelAndView.addObject("trail", trailslocations.get(trailID));
modelAndView.addObject("locCoords", locCoords);
modelAndView.addObject("locCoords", aa);
modelAndView.addObject("locations", approvedLocations);
return modelAndView;
}
}
// public List<LocationsCoordinates> reorderCoordsWRTLocations(List<LocationsCoordinates> locCoords){
// List<Location> approvedList = locationRepo.getAllLocation();
//// List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords();
// List<Integer> locationID= new ArrayList<Integer>();
// System.out.println(locCoords);
// System.out.println("///////");
// Collections.swap(locCoords,0,10);
// for(int i=0;i<locCoords.size();i++){
// if (i==locCoords.size()-1){
// if (locCoords.get(i).getLocationID()<locCoords.get(i-1).getLocationID()){
// Collections.swap(locCoords,i,i--);
// i=0;
// }
//
// }
// if (locCoords.get(i).getLocationID()>locCoords.get(i++).getLocationID()){
// System.out.println("ASDSADASD");
// Collections.swap(locCoords,i,i++);
// i=0;
// }
//
// } System.out.println(locCoords);
// return locCoords;
//
//
//
// }
// When adding to the locationsCoordinates table, the order is not based on LocationID order, therefore it is needed to rearrange this list to
// follow ascending locationID so that any new coordinates match up with their intended locations.
public List<LocationsCoordinates> reorderCoordsWRTLocations(List<LocationsCoordinates> locCoords){
Collections.sort(locCoords,
Comparator.comparingInt(LocationsCoordinates::getLocationID));
System.out.println(locCoords);
return locCoords;
}
}
......@@ -19,8 +19,7 @@ import java.util.List;
import java.util.Objects;
import static junit.framework.TestCase.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.*;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@SpringBootTest
......@@ -117,4 +116,16 @@ public class LocationRepositoryTest {
} assertTrue(doTheyMatch);
}
@Test
public void doesApporvalUpdateTest(){
int approvedLocationsTotal = locationRepository.getAllApprovedLocations().size();
Location unapprovedLocation = new Location("test","test@email","","Caerphilly","301",false);
locationRepository.addLocation(unapprovedLocation);
int newID=locationRepository.nametoLocationID( unapprovedLocation.getLocationName());
locationRepository.updateApprovalStatus(newID);
int newApprovedLocationsTotal = locationRepository.getAllApprovedLocations().size();
assertEquals(1,(newApprovedLocationsTotal-approvedLocationsTotal));
}
}
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