diff --git a/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/Data/locationRepositoryJDBC.java index 5870dd6035161a9ddd8590f3cdea1b14c9930a7b..e6cc200e46d72be07f37bd41286795bb2174c7a8 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 0000000000000000000000000000000000000000..49bb86bfeda0dfc387abc6f99d79d1fab8b96311 --- /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 0efe043a724e2a38de7dec408b28b6c0a48e8f95..22a344bc42e1dd643d10e2f05c9905ea083ce888 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 79f42728981a7e2b2d66f954e336544e97af6f87..abb296cb3ddc14856259de8efe5819cabb19f505 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;