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

Commiting requried modifications to merge with main per git merge erro message

parents 157545ca cd693090
No related branches found
No related tags found
1 merge request!20Resolve "As a user I want to see a list of all available towns with trails so I can plan where to go"
Showing
with 251 additions and 29 deletions
......@@ -24,14 +24,15 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.mariadb.jdbc:mariadb-java-client:2.1.2'
compileOnly 'org.projectlombok:lombok'
testImplementation 'org.projectlombok:lombok:1.18.28'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-validation'
// implementation 'org.springframework.boot:spring-boot-starter-jdbc'
// implementation 'org.mariadb.jdbc:mariadb-java-client:2.1.2'
}
tasks.named('bootBuildImage') {
......
File added
package Team5.SmartTowns.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.*;
@Controller
public class DatabaseController {
@Autowired
private UserRepository userRepository;
@Autowired
private locationRepository locationRepository;
@Autowired
private trailsRepository trailsRepository;
@GetMapping("/userList")
public ModelAndView userList() {
ModelAndView mav = new ModelAndView("towns/userData");
List<user> users = userRepository.getAllUsers();
mav.addObject("users", users);
return mav;
}
@GetMapping("/trailList")
public ModelAndView trailList() {
ModelAndView mav1 = new ModelAndView("towns/trailsData");
List<trail> trail = trailsRepository.getAllTrails();
mav1.addObject("trails", trail);
return mav1;
}
@GetMapping("locationList")
public ModelAndView locationList(){
ModelAndView mav2 = new ModelAndView("towns/locationData");
List<location> locations = locationRepository.getAllLocation();
mav2.addObject("location", locations);
return mav2;
}
}
//Holds users data repository
package Team5.SmartTowns.Data;
import java.util.List;
public interface UserRepository {
List<user> getAllUsers();
}
//Implements the users repository using JDBC
package Team5.SmartTowns.Data;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class UserRepositoryJDBC implements UserRepository{
private JdbcTemplate jdbc;
private RowMapper<user> userMapper;
public UserRepositoryJDBC(JdbcTemplate aJdbc){
this.jdbc = aJdbc;
setuserMapper();
}
private void setuserMapper(){
userMapper = (rs, i) -> new user(
rs.getInt("userID"),
rs.getString("name")
);
}
@Override
public List<user> getAllUsers(){
String sql= "SELECT * FROM users";
return jdbc.query(sql, userMapper);
}
}
//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
package Team5.SmartTowns.Data;
import java.util.List;
public interface locationRepository {
List<location> getAllLocation();
}
//Implements the locations repository using JDBC
package Team5.SmartTowns.Data;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class locationRepositoryJDBC implements locationRepository {
private JdbcTemplate jdbc;
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")
);
}
public List<location> getAllLocation(){
String sql= "SELECT * FROM locations";
return jdbc.query(sql, locationMapper);
}
}
//Holds variable data for the trails table
package Team5.SmartTowns.Data;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class trail {
private int trailsId;
private String name;
}
//Holds trails data repository
package Team5.SmartTowns.Data;
import java.util.List;
public interface trailsRepository {
List<trail> getAllTrails();
}
//Implements the trails repository using JDBC
package Team5.SmartTowns.Data;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class trailsRepositoryJDBC implements trailsRepository{
private JdbcTemplate jdbc;
private RowMapper<trail> trailMapper;
public trailsRepositoryJDBC(JdbcTemplate aJdbc){
this.jdbc = aJdbc;
settrailsMapper();
}
private void settrailsMapper(){
trailMapper = (rs, i) -> new trail(
rs.getInt("trailID"),
rs.getString("name")
);
}
public List<trail> getAllTrails(){
String sql= "SELECT * FROM trails";
return jdbc.query(sql, trailMapper);
}
}
//Holds variable data for the users table
package Team5.SmartTowns.Data;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class user {
private int userId;
private String name;
}
package Team5.SmartTowns.Landmarks;
import Team5.SmartTowns.trails.Trail;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Landmarks {
// Intialised 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")
);
private Integer trailID;
private int landmarkID;
@NotEmpty(message = "You must type in a username.")
private String landmarkName;
@Email(message = "You must attach a contact address.")
private String landmarkEmail;
private String landmarkDescription;
private String landmarkLocation;
private Integer trailID;
private String landmarkPicture;
public Landmarks(){
this.landmarkName ="";
this.landmarkEmail="";
this.landmarkDescription ="";
this.landmarkLocation ="";
this.trailID =0;
}
// Constructor for List above.
public Landmarks( int landmarkID, String landmarkName, String landmarkDescription, String landmarkLocation) {
this.landmarkID = landmarkID;
this.landmarkName = landmarkName;
this.landmarkDescription = landmarkDescription;
this.landmarkLocation = landmarkLocation; }
}
......@@ -36,7 +36,7 @@ public class LandmarksController {
// current functionality only prints successful Landmarks, (todo )database integration is necessary here
ModelAndView modelAndView = new ModelAndView("redirect:/allTrails");
ModelAndView modelAndView = new ModelAndView("redirect:/test.html");
return modelAndView;
}
......
package Team5.SmartTowns.trailcontrollers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class DragonsTale {
@GetMapping("/dragonstale")
public ModelAndView getDragonsTale(){
ModelAndView modelAndView = new ModelAndView("src/main/resources/templates/Towns/trails/dragonstale/index.html");
return modelAndView;
}
}
......@@ -12,7 +12,7 @@ public class Trail {
new Trail(2,"Trail2", "This is trail two"),
new Trail(3,"Trail3", "This is trail three"),
new Trail(4,"Trail4", "This is trail four"),
new Trail(5,"Trail5", "EDITING THIS")
new Trail(5,"A Dragon's Tale", "EDITING THIS")
);
int id;
String name;
......
package Team5.SmartTowns.trails;
import Team5.SmartTowns.Landmarks.Landmarks;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -12,6 +13,8 @@ import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.List;
import static Team5.SmartTowns.Landmarks.Landmarks.landmarksDragonstrail;
@Controller
public class TrailsController {
@GetMapping("/allTrails")
......@@ -32,7 +35,16 @@ public class TrailsController {
List<Trail> trailList= Trail.trails;//results from db
ModelAndView mv= new ModelAndView("fragments/allTrailsFrags :: trailSection");
mv.addObject("trail", trailList.get(id-1));
return mv;
}
@GetMapping("/dragonstale")
public ModelAndView getDragonsTale(){
List<Landmarks> landmarksList = landmarksDragonstrail;
ModelAndView modelAndView = new ModelAndView("towns/trails/dragonstale/index");
modelAndView.addObject("landmarksList", landmarksList);
return modelAndView;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>QR Camera</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
spring.datasource.url=jdbc:mariadb://localhost:3306/towns
spring.datasource.username=root
spring.datasource.password=comsc
spring.sql.init.mode=always
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