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

Further work on form result integration, working on debuggin slight issues

parent ccec7d61
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
......@@ -10,6 +10,7 @@ public interface LocationRepository {
List<Location> getAllApprovedLocations();
int nametoLocationID(String name);
// List<Location> getApprovedLocations2(List<Location> list);
......
......@@ -121,9 +121,9 @@ public class LocationRepositoryJDBC implements LocationRepository {
// } return locationUnapprovedList;
// }
@Override
public int nametoLocationID(String name){
int locationID = jdbc.queryForObject("SELECT locationID FROM locations WHERE locationName=?", Integer.class, name);
return jdbc.queryForObject("SELECT locationID FROM locations WHERE locationName=?", Integer.class, name);
}
......
......@@ -61,27 +61,31 @@ public class LandmarksController {
ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html");
modelAndView.addObject("uLocs", unapprovedLocations);
modelAndView.addObject("location", new Location());
modelAndView.addObject("locationCoord", new LocationsCoordinates());
return modelAndView;
}
// @ModelAttribute("locationCoord")
@PostMapping("/checkpointSubmitted")
public ModelAndView checkpointSent(@Valid @ModelAttribute("locationCoord") LocationsCoordinates locCoord, BindingResult bindingResult, Model model ) {
if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html", model.asMap());
return modelAndView;
} else{
public ModelAndView checkpointSent(@Valid LocationsCoordinates locCoord, Location location, BindingResult bindingResult, Model model ) {
System.out.println(111);
// if (bindingResult.hasErrors()) {
// ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html", model.asMap());
// 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(locCoord.getLocationID(),locCoord.getLocationCoordsLat(),locCoord.getLocationCoordsLong());
LocationsCoordinates ALocCoord = new LocationsCoordinates(locationID,locCoord.getLocationCoordsLat(),locCoord.getLocationCoordsLong());
placesCoordinatesRepo.addLocationCoord(ALocCoord); // adds valid landmark to locations table
System.out.println(placesCoordinatesRepo.getAllLocationCoords());
ModelAndView modelAndView = new ModelAndView("redirect:/home"); //todo redirect to trails?
return modelAndView;
}
// }
}
......
......@@ -104,8 +104,13 @@ public class LocationsCoordinates {
/// Need a constructor to create a locations list, approved collation list, unapproved locations list.
@Override
public String toString() {
return "LocationsCoordinates{" +
"locationID=" + locationID +
", locationCoordsLat=" + locationCoordsLat +
", locationCoordsLong=" + locationCoordsLong +
", jdbc=" + jdbc +
'}';
}
}
......@@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.JdbcUserDetailsManager;
......@@ -23,6 +24,7 @@ public class SecurityConfiguration {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests((requests) -> requests
.requestMatchers("/user/**", "/userProfile").authenticated()
.anyRequest().permitAll()
......
......@@ -8,21 +8,22 @@
<main>
<form action="/checkpointSubmitted" method="post" th:object="${locationCoord}">
<label> Location To Be Approved:
<select >
<!-- <select th:field="*{locationName}">-->
<option value="" hidden="true">Select Location</option>
<option value="" selected disabled>Select Location</option>
<option th:each="uloc:${uLocs}" th:value="${uloc.getLocationName()}" th:text="${uloc.getLocationName()}">
</option>
</select>
</label>
<br><label> Location Latitude:
<input type="text" th:field="*{locationCoordsLat}" placeholder="Latitude Here">
<br><label> Location Longitude:
<input type="text" th:field="*{locationCoordsLong}" placeholder="Latitude Here">
</label><br>
<input type="submit">
<label> Location To Be Approved:
<select th:object="${location}" th:field="*{locationName}"}>
<!-- <select th:field="*{locationName}">-->
<option value="" hidden="true">Select Location</option>
<option value="" selected disabled>Select Location</option>
<option value="Caerphilly">Caerphilly</option>
<option th:each="uloc:${uLocs}" th:value="${uloc.getLocationName()}" th:text="${uloc.getLocationName()}">
</option>
</select>
</label>
<br><label> Location Latitude:
<input type="text" th:field="*{locationCoordsLat}" placeholder="Latitude Here">
<br><label> Location Longitude:
<input type="text" th:field="*{locationCoordsLong}" placeholder="Latitude Here">
</label><br>
<input type="submit">
</form>
......
......@@ -83,6 +83,14 @@
<!-- <div th:each="locationCoord:${locationCoords}" >-->
<!-- <div th:each="location:${locations}">-->
<!-- <div th:if="${location.getLocationTrailID()==trail.getTrailsId()}">-->
<!-- <li style="list-style: none">-->
<!-- <a th:href="'/checkpoints/'+${location.getLocationName().replace(' ', '-')}" th:text="${location.getLocationName()}"></a>-->
<!-- <ul></ul>-->
<!-- </li></div>-->
</div>
......
package Team5.SmartTowns.placeswithcoordinates;
import Team5.SmartTowns.data.Location;
import Team5.SmartTowns.data.LocationRepository;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -16,6 +18,9 @@ class PlacesCoordinatesTest {
@Autowired
PlacesCoordinatesRepository placesCoordinatesRepository;
@Autowired
LocationRepository locationRepository;
@Autowired
JdbcTemplate jdbcTemplate;
......@@ -79,4 +84,22 @@ class PlacesCoordinatesTest {
@Test
void getLocationTableIDValue() {
}
@Test
public void nameToLocationIDTest(){
List<Location> locationList = locationRepository.getAllLocation();
String firstLocationName=locationList.get(0).getLocationName();
String lastLocationName=locationList.get(locationList.size()-1).getLocationName();
int firstLocationID= locationRepository.nametoLocationID(firstLocationName);
int lastLocationID= locationRepository.nametoLocationID(lastLocationName);
// if first and last location are chosen and if SQL ID starts at 1 , while an array index starts at 0, then the following should be equal;
String firstLocationTest=locationList.get(firstLocationID-1).getLocationName();
String lastLocationTest=locationList.get(lastLocationID-1).getLocationName();
assertEquals(firstLocationName,firstLocationTest);
assertEquals(lastLocationName,lastLocationTest);
}
}
\ No newline at end of file
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