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

Further work on creating repositories for landamrk/location coordinates

parent d72430a5
No related branches found
No related tags found
1 merge request!30Resolve "As a user I would like to see a map of the landmarks, so that I can figure out where to go"
......@@ -8,10 +8,12 @@ public interface LocationRepository {
List<Location> getAllLocation();
void addLocation(Location loc);
<<<<<<< HEAD:src/main/java/Team5/SmartTowns/Data/locationRepository.java
List<Location> approvedLocations();
List<Location> unapprovedLocations();
// List<Location> approvedLocations();
=======
>>>>>>> main:src/main/java/Team5/SmartTowns/data/LocationRepository.java
}
......@@ -51,5 +51,24 @@ public class LocationRepositoryJDBC implements LocationRepository {
} return locationApprovalList;
}
@Override
public List<Location> unapprovedLocations(){
List<Location> locations = getAllLocation();
List<Location> locationUnapprovedList= new ArrayList<Location>();
for (Location loc :locations){
if (!loc.isLocationApproved()) {
locationUnapprovedList.add(loc);
}
} return locationUnapprovedList;
}
public LocationRepositoryJDBC() {
}
}
package Team5.SmartTowns.Data;
package Team5.SmartTowns.data;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.jdbc.core.JdbcTemplate;
@Data
@AllArgsConstructor
public class LocationsCoordinates {
@NoArgsConstructor
public class LocationsCoordinates extends LocationRepositoryJDBC {
/// separate class to location to cover all locations within trails that have been approved and have long/lat coords attached for mapping.
private int locationID;
private double locationCoordsLong;
private double locationCoordsLat;
private String locationCoordsLong;
private String locationCoordsLat;
public int getLocationID() {
return locationID;
}
public String getLocationCoordsLong() {
return locationCoordsLong;
}
public String getLocationCoordsLat() {
return locationCoordsLat;
}
public void setLocationCoordsLong(String locationCoordsLong) {
this.locationCoordsLong = locationCoordsLong;
}
public void setLocationCoordsLat(String locationCoordsLat) {
this.locationCoordsLat = locationCoordsLat;
}
public LocationsCoordinates(JdbcTemplate aJdbc, int locationID, String locationCoordsLong, String locationCoordsLat) {
super(aJdbc);
this.locationID = locationID;
this.locationCoordsLong = locationCoordsLong;
this.locationCoordsLat = locationCoordsLat;
}
public LocationsCoordinates(int locationID, String locationCoordsLong, String locationCoordsLat) {
this.locationID = locationID;
this.locationCoordsLong = locationCoordsLong;
this.locationCoordsLat = locationCoordsLat;
}
/// Need a constructor to create a lcoations list, approved lcoatiosn lsit, unapproved lcoations list.
}
package Team5.SmartTowns.data;
import java.util.List;
public interface LocationsCoordinatesRepository {
List<LocationsCoordinates> getAllLocationCoords();
void addLocationCoord(LocationsCoordinates locCoord);
}
package Team5.SmartTowns.data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import java.util.List;
public class LocationsCoordinatesRepositoryJDBC extends LocationsCoordinatesRepository{
private JdbcTemplate jdbc;
private RowMapper<LocationsCoordinates> locationCoordMapper;
public LocationsCoordinatesRepositoryJDBC(JdbcTemplate aJdbc) {
this.jdbc = aJdbc;
setlocationCoordsMapper();
}
private void setlocationCoordsMapper(){
locationCoordMapper = (rs, i) -> new LocationsCoordinates(
rs.getInt("locationID"),
rs.getString("locationCoordsLong"),
rs.getString("locationCoordsLat")
);
}
public List<LocationsCoordinates> getAllLocation(){
String sql= "SELECT * FROM locationCoordinates";
return jdbc.query(sql, locationCoordMapper);
}
@Override
public void addLocation(LocationsCoordinates locCoords) {
String sql = "insert into locationCoordinates(locationID, locationCoordsLong,locationCoordsLat) values (?,?,?)";
jdbc.update(sql,locCoords.getLocationID(), locCoords.getLocationCoordsLong(),locCoords.getLocationCoordsLat());
}
// private static JdbcTemplate jdbc;
// @BeforeAll
// public static void before() {
// location = new Location();
// locationRepo = new locationRepositoryJDBC(jdbc);}
// @BeforeAll
// public static void before2() {
// locationRepo = new locationRepositoryJDBC(jdbc); }
@Autowired
private locationRepository locationRepository;
public void approveLocationAndAddCoords(String town, String longCoords, String latCoords){ // need list too
List<Location> needApprovalList = new LocationsCoordinatesRepositoryJDBC.unapprovedLocations();
// unapproved list
// if matches name, approve
// add long/lat coords
//use to update table
}
}
package Team5.SmartTowns.webpages;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.Controller;
@Controller
......@@ -23,7 +26,7 @@ public class WebpageController {
ModelAndView modelAndView = new ModelAndView("Towns/risca");
return modelAndView;
}
<<<<<<< HEAD:src/main/java/Team5/SmartTowns/Webpages/WebpageController.java
@GetMapping("/maps")
public ModelAndView getMapTestAPI(){
......@@ -38,14 +41,10 @@ public class WebpageController {
// }
@RequestMapping(value="/test_ajax_frag", method=RequestMethod.POST)
public String sendHtmlFragment(Model map) {
//map.addAttribute("foo", "bar");
return "fragments/temp_frags.html :: trailInfo2";
}
=======
>>>>>>> main:src/main/java/Team5/SmartTowns/webpages/WebpageController.java
}
......@@ -7,7 +7,7 @@ insert into trails ( Name,tru) value ( 'Caerphilly Coffee Trail',false);
insert into trails ( Name,tru) value ( 'Penarth Dragon Trail',true);
delete from locations;
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved)value ( 'St Cenydd','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'St Cenydd','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Castle','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Medieval Trades','','Location description here','Caerphilly',0101, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Queen''s War','','Location description here','Caerphilly',0101, true);
......@@ -25,30 +25,26 @@ insert into locations ( locationName , locationEmail,locationDescription,locatio
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Medieval Courthouse','','Location description here','Caerphilly',0103, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ('Caerphilly Castle','','Location description here','Caerphilly',0103, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Ty Vaughan House','','Location description here','Caerphilly',0103, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Risca Colliery','','Location description here','Risca',0201, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'Black Vein Colliery Disaster','','Location description here','Risca',0201, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Esplanade','','Location description here','Penarth',0301, true);
insert into locations ( locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value ( 'The Old Swimming Baths','','Location description here','Penarth',0301, true);
# delete from badges;
# insert into badges (name, description, difficulty) value ('TownConnoisseur', 'You know the town very well!', '2');
# insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
# insert into badges (name, description, difficulty) value ('TownMaster', 'You visited the town 7 days in a row!', '1');
# insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
# insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
<<<<<<< HEAD
insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value (19, 'The Esplanade','','Location description here','Penarth',0301, true);
insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID, locationApproved) value (20, 'The Old Swimming Baths','','Location description here','Penarth',0301, true);
delete from badges;
insert into badges (name, description, difficulty) value ('TownConnoisseur', 'You know the town very well!', '2');
insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
insert into badges (name, description, difficulty) value ('TownMaster', 'You visited the town 7 days in a row!', '1');
insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
=======
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);
delete from packs;
insert into packs (name, description) value ('Wales Football Team', 'Pack of Welsh Football Players in the National Team');
insert into packs (name, description) value ('Wales Rugby Team', 'Pack of Welsh Rugby Players in the National Team');
insert into packs (name, description) value ('Welsh Heritage', 'Pack About Welsh Heritage');
>>>>>>> main
delete from stickers;
insert into stickers (packID, stickerID, name, description, rarity) value (1, 1, 'wayne_hennessey', 'Wales Football Team Player', '2');
......@@ -65,21 +61,20 @@ insert into stickers (packID, stickerID, name, description, rarity) value (3, 1,
insert into stickers (packID, stickerID, name, description, rarity) value (3, 2, 'Welsh Outline', 'Welsh Heritage', '1');
insert into stickers (packID, stickerID, name, description, rarity) value (3, 3, 'Welsh Spoon', 'Welsh Heritage', '1');
delete from stickerprogress;
<<<<<<< HEAD
# delete from stickerprogress;
# insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '1', true);
# insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '3', true);
# insert into stickerprogress (userID, stickerID, hasSticker) value ('2', '2', true);
delete from locationsCoordinates;
insert into locationsCoordinates(locationID, locationCoordsLong, locationCoordsLat) value (2,51.57623,-3.21910 );
insert into locationsCoordinates(locationID, locationCoordsLong, locationCoordsLat) value (3,51.575372, -3.219186 );
insert into locationsCoordinates(locationID, locationCoordsLong, locationCoordsLat) value (4,51.576363, -3.220712 );
=======
insert into stickerprogress (userID, packID, stickerID) value (1, 1, 1);
insert into stickerprogress (userID, packID, stickerID) value (1, 1, 2);
insert into stickerprogress (userID, packID, stickerID) value (1, 1, 3);
insert into stickerprogress (userID, packID, stickerID) value (1, 1, 5);
insert into stickerprogress (userID, packID, stickerID) value (1, 2, 1);
insert into stickerprogress (userID, packID, stickerID) value (1, 2, 3);
>>>>>>> main
delete from locationCoordinates;
insert into locationCoordinates(locationID, locationCoordsLong, locationCoordsLat) value (2,'51.57623','-3.21910' );
insert into locationCoordinates(locationID, locationCoordsLong, locationCoordsLat) value (3,'51.575372','-3.219186');
insert into locationCoordinates(locationID, locationCoordsLong, locationCoordsLat) value (4, '51.576363','-3.220712' );
#
# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 1);
# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 2);
# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 3);
# insert into stickerprogress (userID, packID, stickerID) value (1, 1, 5);
# insert into stickerprogress (userID, packID, stickerID) value (1, 2, 1);
# insert into stickerprogress (userID, packID, stickerID) value (1, 2, 3);
......@@ -6,6 +6,7 @@ create table if not exists trails
tru boolean
) engine=InnoDB;
drop table if exists locationCoordinates;
drop table if exists locations;
create table if not exists locations
(
......@@ -59,27 +60,24 @@ create table if not exists stickerProgress
(
id bigint auto_increment primary key,
userID bigint,
<<<<<<< HEAD
stickerID bigint,
hasSticker boolean /*Has sticker or not*/
stickerID bigint
) engine=InnoDB;
drop table if exists locationsCoordinates;
create table if not exists locationsCoordinates
(locationCoordID bigint auto_increment primary key,
locationID bigint,
locationCoordsLong double,
locationCoordsLat double,
Foreign Key (locationID) REFERENCES locations(locationID)
create table if not exists locationCoordinates
(
locationCoordID bigint auto_increment primary key,
locationID bigint,
Foreign Key (locationID) REFERENCES locations(locationID)
ON DELETE CASCADE
ON UPDATE RESTRICT,
locationCoordsLong varchar(128),
locationCoordsLat varchar(128)
)engine=InnoDB;
=======
packID bigint,
stickerID bigint
) engine=InnoDB;
>>>>>>> main
package Team5.SmartTowns;
import Team5.SmartTowns.Data.DatabaseController;
import Team5.SmartTowns.Data.Location;
import Team5.SmartTowns.Data.locationRepository;
import Team5.SmartTowns.Data.locationRepositoryJDBC;
import Team5.SmartTowns.Landmarks.Landmarks;
import Team5.SmartTowns.data.DatabaseController;
import Team5.SmartTowns.data.Location;
import Team5.SmartTowns.data.LocationRepository;
import Team5.SmartTowns.data.LocationRepositoryJDBC;
import Team5.SmartTowns.landmarks.Landmarks;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
......
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