From 873e67ac443628794b537357023917afce0bbea2 Mon Sep 17 00:00:00 2001 From: Rhys Evans <EvansRM17@cardiff.ac.uk> Date: Fri, 1 Dec 2023 22:50:46 +0000 Subject: [PATCH] form correctly adds valid submits to locations table, attemnpting to add Java alert to identify correct submission --- .../Data/locationRepositoryJDBC.java | 12 ++-------- .../Landmarks/LandmarkSuccessDialogue.java | 2 ++ .../Landmarks/LandmarksController.java | 23 +++++++++++++------ src/main/resources/schema.sql | 2 +- 4 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 src/main/java/Team5/SmartTowns/Landmarks/LandmarkSuccessDialogue.java diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java index 5870dd60..e6cc200e 100644 --- a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java @@ -33,20 +33,12 @@ public class locationRepositoryJDBC implements locationRepository { return jdbc.query(sql, locationMapper); } - @Override + @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 llocation) { String sql = "insert into locations(locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID) values (?,?,?,?,?,?)"; jdbc.update(sql, llocation.getLocationID(),llocation.getLocationName(),llocation.getLocationEmail(),llocation.getLocationDescription(),llocation.getLocationPlace(),llocation.getLocationTrailID()); } -// public void insertLocation(Landmarks landmark){ -// String sql = "INSERT INTO locations(locationID, locationName , locationEmail,locationDescription,locationPlace, locationTrailID)"+"VALUES("+ landmark.getLandmarkID()+","+","+landmark.getLandmarkName()+","+landmark.getLandmarkEmail()+","+landmark.getLandmarkDescription()+","+landmark.getLandmarkLocation()+","+landmark.getTrailID()+")"; -// try{ -// executeUpdate(sql); -// } -// catch(SQLException e){ -// -// } -// } + } diff --git a/src/main/java/Team5/SmartTowns/Landmarks/LandmarkSuccessDialogue.java b/src/main/java/Team5/SmartTowns/Landmarks/LandmarkSuccessDialogue.java new file mode 100644 index 00000000..49bb86bf --- /dev/null +++ b/src/main/java/Team5/SmartTowns/Landmarks/LandmarkSuccessDialogue.java @@ -0,0 +1,2 @@ +package Team5.SmartTowns.Landmarks; + diff --git a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java index 0efe043a..22a344bc 100644 --- a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java +++ b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java @@ -11,7 +11,9 @@ 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; @@ -30,7 +32,7 @@ public class LandmarksController { @Autowired private locationRepository locationRepository; @PostMapping("/landmarkSub") - public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model ) { + public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes ) { if (bindingResult.hasErrors()) { @@ -39,14 +41,21 @@ public class LandmarksController { } else{ System.out.println(landmarks); +// JFrame frame = new JFrame("Main Window"); +// +// JOptionPane.showMessageDialog(frame, "Message for the dialog box goes here.","Error", JOptionPane.ERROR_MESSAGE); +// +// frame.setSize(350,350); +// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); +// frame.setVisible(true); + location loc= new location(landmarks.getLandmarkID(),landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID()); + System.out.println(loc); locationRepository.addLocation(loc); - - - - - - ModelAndView modelAndView = new ModelAndView("redirect:/home"); +// redirectAttributes.addFlashAttribute("notification", +// String.format("Contractor \"%s\" successfully saved")); +// redirectAttributes.addFlashAttribute("msg", "Success"); + ModelAndView modelAndView = new ModelAndView("redirect:/home"); return modelAndView; } diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 79f42728..abb296cb 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -11,7 +11,7 @@ create table if not exists locations locationID bigint auto_increment primary key, locationName varchar(128), locationEmail varchar(128), - locationDescription longtext, #to store large text data + locationDescription longtext, locationPlace varchar(255), locationTrailID varchar(128) ) engine=InnoDB; -- GitLab