Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • d1656298/client-project
  • d1634883/client-project
2 results
Show changes
Commits on Source (11)
Showing
with 157 additions and 71 deletions
......@@ -33,8 +33,8 @@ public class DatabaseController {
@GetMapping("locationList")
public ModelAndView locationList(){
ModelAndView mav2 = new ModelAndView("towns/locationData");
List<location> locations = locationRepository.getAllLocation();
mav2.addObject("location", locations);
List<Location> Locations = locationRepository.getAllLocation();
mav2.addObject("location", Locations);
return mav2;
}
}
//Holds variable data for the locations table (landmarks)
package Team5.SmartTowns.Data;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class Location {
// private int locationID;
private String locationName;
private String locationEmail;
private String locationDescription;
private String locationPlace;
private int locationTrailID;
@Override
public String toString() {
return "Location{" +
locationName + '\'' +
locationEmail + '\'' +
locationDescription + '\'' +
locationPlace + '\'' +
locationTrailID +
'}';
}
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;
}
}
//Holds variable data for the locations table
package Team5.SmartTowns.Data;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class location {
private int locationID;
private String name;
}
//Holds locations data repository
//Holds locations data repository (landmarks)
package Team5.SmartTowns.Data;
import java.util.List;
public interface locationRepository {
List<location> getAllLocation();
List<Location> getAllLocation();
void addLocation(Location loc);
}
......@@ -10,20 +10,33 @@ import java.util.List;
@Repository
public class locationRepositoryJDBC implements locationRepository {
private JdbcTemplate jdbc;
private RowMapper<location> locationMapper;
private RowMapper<Location> locationMapper;
public locationRepositoryJDBC(JdbcTemplate aJdbc) {
this.jdbc = aJdbc;
setlocationMapper();
}
private void setlocationMapper(){
locationMapper = (rs, i) -> new location(
rs.getInt("locationID"),
rs.getString("name")
locationMapper = (rs, i) -> new Location(
rs.getString("locationName"),
rs.getString("locationEmail"),
rs.getString("locationDescription"),
rs.getString("locationPlace"),
rs.getInt("locationTrailID")
);
}
public List<location> getAllLocation(){
public List<Location> getAllLocation(){
String sql= "SELECT * FROM locations";
return jdbc.query(sql, locationMapper);
}
@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) values (?,?,?,?,?)";
jdbc.update(sql,loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID());
}
}
......@@ -15,18 +15,19 @@ import java.util.List;
@NoArgsConstructor
public class Landmarks {
// Intialised object to getID from trail.
// Initialized object to getID from trail.
//Predefined Landmark for Dragons Tale.
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( 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 int landmarkID;
@NotEmpty(message = "You must type in a username.")
private String landmarkName;
@NotEmpty(message = "You must attach a contact address.") // Requires @NotEmpty for form validation
@Email(message = "You must attach a contact address.")
private String landmarkEmail;
private String landmarkDescription;
......
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;
......@@ -22,7 +25,8 @@ public class LandmarksController {
}
@Autowired
private locationRepository locationRepository;
@PostMapping("/landmarkSub")
public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model ) {
......@@ -32,11 +36,11 @@ public class LandmarksController {
return modelAndView;
} else{
System.out.println(landmarks);
// current functionality only prints successful Landmarks, (todo )database integration is necessary here
ModelAndView modelAndView = new ModelAndView("redirect:/test.html");
// converts valid response using Location constructor into a submittable format to the sql table
Location loc= new Location(landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID());
System.out.println(loc);
locationRepository.addLocation(loc); // adds valid landmark to locations table
ModelAndView modelAndView = new ModelAndView("redirect:/home");
return modelAndView;
}
......
......@@ -7,5 +7,28 @@ insert into trails (trailID, Name) value ('1', 'Caerphilly Coffee Trail');
insert into trails (trailID, Name) value ('2', 'Penarth Dragon Trail');
delete from locations;
insert into locations (locationID, Name) value ('1', 'Caerphilly');
insert into locations (locationID, Name) value ('2', 'Penarth');
\ No newline at end of file
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 (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 (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 (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 (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 (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 (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 (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 (17, 'Risca Colliery','','Location description here','Risca',0201);
insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (18, 'Black Vein Colliery Disaster','','Location description here','Risca',0201);
insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (19, 'The Esplanade','','Location description here','Penarth',0301);
insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) value (20, 'The Old Swimming Baths','','Location description here','Penarth',0301);
......@@ -5,10 +5,15 @@ create table if not exists trails
name varchar(128)
) engine=InnoDB;
drop table if exists locations;
create table if not exists locations
(
locationID bigint auto_increment primary key,
name varchar(128)
locationName varchar(128),
locationEmail varchar(128),
locationDescription longtext,
locationPlace varchar(255),
locationTrailID varchar(128)
) engine=InnoDB;
drop table if exists users;
create table if not exists users
......
// verification function of the above form
function landmarkFormValidation(){
var pass=true;
var trail = document.forms["landmarkSubmission"]["trailID"].value
var location = document.forms["landmarkSubmission"]["landmarkLocation"].value
var description = document.forms["landmarkSubmission"]["landmarkDescription"].value;
var descriptionWrdCount=description.split(" ").length
if (descriptionWrdCount>200){
alert('Please keep your description to a maximum of 200 words.');
pass = false;
}
if (trail==0){ // values of 0 and "" used to ensure default drop down option isn't submittable
alert('Invalid trail selected. \nPlease select the trail you wish to join.');
pass = false;
}
if (location==""){
alert('Invalid location selected. \nPlease select the location you wish to join.');
pass = false; // ensure correct trail is selected in accordance to the town it takes place in
} if ( (location=="Caerphilly" & (parseInt(trail/100)!==1)) ||
(location=="Risca" & (parseInt(trail/100)!==2)) ||
(location=="Penarth" & (parseInt(trail/100)!==3)) ){
alert('Trail unavailable in your current location. \nPlease choose an available trail');
pass = false;
}
return pass;
}
......@@ -5,6 +5,9 @@
<title>Landmark Sign Up</title>
<link rel="stylesheet" th:href="@{css/landmarkFormStyle.css}">
<link rel="stylesheet" th:href="@{css/templatingstyle.css}">
<!-- <link rel="script" th:href="@{scripts/landmarkFormThScript.js}">-->
<script src="scripts/landmarkFormThScript.js"></script>
<!-- <style in="scripts/landmarkFormThScript.js"></style>-->
</head>
......@@ -30,7 +33,8 @@
</label><br><br>
<label>Your Location:
<select th:field="*{landmarkLocation}">
<option value="" disabled selected>Select Location</option>
<option value="" hidden="true">Select Location</option>
<option value="" selected disabled>Select Location</option>
<option value="Caerphilly">Caerphilly</option>
<option value="Risca">Risca</option>
<option value="Penarth">Penarth</option>
......@@ -38,6 +42,7 @@
</label><br><br>
<label>Trail:
<select th:field="*{trailID}">
<option value=0 hidden="true">Select Trail</option>
<option value=0 disabled selected>Select Trail</option>
<option value=0101>(Caerphilly) Castle Trail</option>
<option value=0102>(Caerphilly) Pub Trail</option>
......@@ -56,45 +61,7 @@
<hr style="height:40px; visibility:hidden;" />
</main>
<script>
// verification function of the above form
function landmarkFormValidation(){
var pass=true;
var trail = document.forms["landmarkSubmission"]["trailID"].value
var location = document.forms["landmarkSubmission"]["landmarkLocation"].value
var description = document.forms["landmarkSubmission"]["landmarkDescription"].value;
var descriptionWrdCount=description.split(" ").length
if (descriptionWrdCount>200){
alert('Please keep your description to a maximum of 200 words.');
pass = false;
}
if (trail==0){ // values of 0 and "" used to ensure default drop down option isn't submittable
alert('Invalid trail selected. \nPlease select the trail you wish to join.');
pass = false;
}
if (location==""){
alert('Invalid location selected. \nPlease select the location you wish to join.');
pass = false; // ensure correct trail is selected in accordance to the town it takes place in
} if ( (location=="Caerphilly" & (parseInt(trail/100)!==1)) ||
(location=="Risca" & (parseInt(trail/100)!==2)) ||
(location=="Penarth" & (parseInt(trail/100)!==3)) ){
alert('Trail unavailable in your current location. \nPlease choose an available trail');
pass = false;
}
return pass;
}
</script>
<footer th:insert="~{/towns/Templating.html :: footer}"></footer>
</body>
</html>
\ No newline at end of file