diff --git a/src/main/java/recommendation_library/dao/DatabaseRecommendationDao.java b/src/main/java/recommendation_library/dao/DatabaseRecommendationDao.java index 8ac09a0..f5bda92 100644 --- a/src/main/java/recommendation_library/dao/DatabaseRecommendationDao.java +++ b/src/main/java/recommendation_library/dao/DatabaseRecommendationDao.java @@ -225,7 +225,7 @@ public void editBookRecommendation(String title, String fieldToBeEdited, String } } - public int searchViedoByTitle(String title) { + public int searchVideoByTitle(String title) { String sql = "SELECT id FROM videos WHERE title = ?"; int id = 0; try { @@ -254,5 +254,37 @@ public void deleteBookByTitle(String title) { System.out.println(e.getMessage()); } } + + @Override + public void editVideoRecommendation(String title, String fieldToBeEdited, String newValue) { + String sql = "UPDATE videos SET " + fieldToBeEdited + " = ? WHERE title = ?"; + try { + Connection conn = this.connect(); + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setString(1, newValue); + pstmt.setString(2, title); + pstmt.executeUpdate(); + } catch (SQLException e) { + System.out.println(e.getMessage()); + } + } + + @Override + public void deleteVideoByTitle(String title) { + int videoId = searchVideoByTitle(title); + String deleteTimeStamps = "DELETE * FROM timestamps WHERE video_id = ?"; + String deleteVideo = "DELETE * FROM videos WHERE id = ?"; + try { + Connection conn = this.connect(); + PreparedStatement stmt = conn.prepareStatement(deleteTimeStamps); + stmt.setInt(1, videoId); + stmt.executeUpdate(); + stmt = conn.prepareStatement(deleteVideo); + stmt.setInt(1, videoId); + stmt.executeUpdate(); + } catch (SQLException e) { + System.out.println(e.getMessage()); + } + } } diff --git a/src/main/java/recommendation_library/dao/InMemoryRecommendationDao.java b/src/main/java/recommendation_library/dao/InMemoryRecommendationDao.java index 4b94100..677a73e 100644 --- a/src/main/java/recommendation_library/dao/InMemoryRecommendationDao.java +++ b/src/main/java/recommendation_library/dao/InMemoryRecommendationDao.java @@ -66,6 +66,16 @@ public List getAllVideoRecommendations() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + @Override + public void editVideoRecommendation(String title, String fieldToBeEdited, String newValue) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void deleteVideoByTitle(String title) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + } diff --git a/src/main/java/recommendation_library/dao/RecommendationDao.java b/src/main/java/recommendation_library/dao/RecommendationDao.java index 42cdd7e..129651f 100644 --- a/src/main/java/recommendation_library/dao/RecommendationDao.java +++ b/src/main/java/recommendation_library/dao/RecommendationDao.java @@ -24,4 +24,7 @@ public interface RecommendationDao { void editBookRecommendation(String title, String fieldToBeEdited, String newValue); void deleteBookByTitle(String title); + + void editVideoRecommendation(String title, String fieldToBeEdited, String newValue); + void deleteVideoByTitle(String title); }