From bd9eb068cd19ab92d0e30710bb3ce6ab0cc8b959 Mon Sep 17 00:00:00 2001
From: Rhys Evans <EvansRM17@cardiff.ac.uk>
Date: Sun, 3 Dec 2023 17:23:33 +0000
Subject: [PATCH] Renamed location.class to Location.class for better
 disinguishment. Followed feedback provided by RN and removed unnecessary
 locationID variable within Location class

---
 .../SmartTowns/Data/DatabaseController.java   |  4 +--
 .../Data/{location.java => Location.java}     | 25 +++++----------
 .../SmartTowns/Data/locationRepository.java   |  6 ++--
 .../Data/locationRepositoryJDBC.java          | 18 +++++------
 .../Team5/SmartTowns/Landmarks/Landmarks.java |  4 +--
 .../Landmarks/LandmarksController.java        | 10 ++----
 src/main/resources/data.sql                   | 32 +++++++++----------
 7 files changed, 41 insertions(+), 58 deletions(-)
 rename src/main/java/Team5/SmartTowns/Data/{location.java => Location.java} (56%)

diff --git a/src/main/java/Team5/SmartTowns/Data/DatabaseController.java b/src/main/java/Team5/SmartTowns/Data/DatabaseController.java
index b91d7d88..0eed9aca 100644
--- a/src/main/java/Team5/SmartTowns/Data/DatabaseController.java
+++ b/src/main/java/Team5/SmartTowns/Data/DatabaseController.java
@@ -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;
     }
 }
diff --git a/src/main/java/Team5/SmartTowns/Data/location.java b/src/main/java/Team5/SmartTowns/Data/Location.java
similarity index 56%
rename from src/main/java/Team5/SmartTowns/Data/location.java
rename to src/main/java/Team5/SmartTowns/Data/Location.java
index 660a7f96..01ba2932 100644
--- a/src/main/java/Team5/SmartTowns/Data/location.java
+++ b/src/main/java/Team5/SmartTowns/Data/Location.java
@@ -3,13 +3,10 @@ package Team5.SmartTowns.Data;
 
 import lombok.AllArgsConstructor;
 import lombok.Data;
-//insert into locations (locationID, locationName , locationEmail,locationDescription,locationPlace,
-//        locationTrailID
-//        ) value ('1', 'St Cenydd','','location description here','Caerphilly',0101);
 @Data
 @AllArgsConstructor
-public class location {
-    private int locationID;
+public class Location {
+//    private int locationID;
     private String locationName;
     private String locationEmail;
     private String locationDescription;
@@ -18,21 +15,15 @@ public class location {
 
     @Override
     public String toString() {
-        return "location{" +
-                "" + locationID +
-                ", '" + locationName + '\'' +
-                ", '" + locationEmail + '\'' +
-                ", '" + locationDescription + '\'' +
-                ", '" + locationPlace + '\'' +
-                ", " + locationTrailID +
+        return "Location{" +
+                 locationName + '\'' +
+                 locationEmail + '\'' +
+                 locationDescription + '\'' +
+                 locationPlace + '\'' +
+                 locationTrailID +
                 '}';
     }
 
-
-    public int getLocationID() {
-        return locationID;
-    }
-
     public String getLocationName() {
         return locationName;
     }
diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepository.java b/src/main/java/Team5/SmartTowns/Data/locationRepository.java
index 47c2f327..822a18cb 100644
--- a/src/main/java/Team5/SmartTowns/Data/locationRepository.java
+++ b/src/main/java/Team5/SmartTowns/Data/locationRepository.java
@@ -1,14 +1,12 @@
 //Holds locations data repository (landmarks)
 package Team5.SmartTowns.Data;
 
-import Team5.SmartTowns.Landmarks.Landmarks;
-
 import java.util.List;
 
 
 public interface locationRepository {
-    List<location> getAllLocation();
-    void addLocation(location loc);
+    List<Location> getAllLocation();
+    void addLocation(Location loc);
 
 
 }
diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java
index 3f86131a..a5e79d44 100644
--- a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java
+++ b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java
@@ -1,26 +1,24 @@
 //Implements the locations repository using JDBC
 package Team5.SmartTowns.Data;
 
-import Team5.SmartTowns.Landmarks.Landmarks;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.stereotype.Repository;
 
-import java.sql.SQLException;
 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"),
+        locationMapper = (rs, i) -> new Location(
+
                 rs.getString("locationName"),
                 rs.getString("locationEmail"),
                 rs.getString("locationDescription"),
@@ -28,16 +26,16 @@ public class locationRepositoryJDBC implements locationRepository {
                 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, todo change location class to Location as its better code grammar and looks funky otherwise.
-    public void addLocation(location loc) {
-        String sql = "insert into locations(locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) values (?,?,?,?,?,?)";
+    @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.getLocationID(),loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID());
+        jdbc.update(sql,loc.getLocationName(),loc.getLocationEmail(),loc.getLocationDescription(),loc.getLocationPlace(),loc.getLocationTrailID());
     }
 
 
diff --git a/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java b/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java
index c173fdf2..381ccf04 100644
--- a/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java
+++ b/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java
@@ -15,12 +15,12 @@ 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;
diff --git a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java
index a9f13567..a94feef8 100644
--- a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java
+++ b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java
@@ -1,6 +1,6 @@
 package Team5.SmartTowns.Landmarks;
 
-import Team5.SmartTowns.Data.location;
+import Team5.SmartTowns.Data.Location;
 import Team5.SmartTowns.Data.locationRepository;
 import jakarta.validation.Valid;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -11,10 +11,6 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.servlet.ModelAndView;
-import org.springframework.web.servlet.mvc.support.RedirectAttributes;
-
-import javax.swing.*;
-import java.sql.PreparedStatement;
 //import jakarta.validation.Valid;
 
 @Controller
@@ -40,8 +36,8 @@ public class LandmarksController {
             return modelAndView;
 
         } else{
-
-            location loc= new location(landmarks.getLandmarkID(),landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID());
+            // 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");
diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql
index 099498b3..c095af09 100644
--- a/src/main/resources/data.sql
+++ b/src/main/resources/data.sql
@@ -7,21 +7,21 @@ 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, 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 (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 (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 (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);
-- 
GitLab