Skip to content

Commit

Permalink
databaseDao methods for video editing and deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
tire95 committed Nov 30, 2020
1 parent ccc7fe8 commit 9a2aa64
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public List<VideoRecommendation> 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.
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 9a2aa64

Please sign in to comment.