Skip to content
Snippets Groups Projects
Commit dbbfbe3b authored by Charlie Darques's avatar Charlie Darques
Browse files

correction de bug pour unfollow

parent bda83feb
No related branches found
No related tags found
No related merge requests found
...@@ -33,17 +33,15 @@ public class FollowThread extends HttpServlet { ...@@ -33,17 +33,15 @@ public class FollowThread extends HttpServlet {
} }
boolean followed = false; boolean followed = false;
try {
if (threadsFollowed.contains(threadDao.getThreadById((Integer.parseInt(req.getParameter("threadid")))))) { if (threadsFollowed.contains(Integer.parseInt(req.getParameter("threadid")))) {
followed = true; followed = true;
}
else {
followed = false;
}
} }
catch (SQLException sqle) { else {
sqle.getStackTrace(); followed = false;
} }
System.out.println(followed);
if (!followed) { if (!followed) {
try { try {
...@@ -55,6 +53,7 @@ public class FollowThread extends HttpServlet { ...@@ -55,6 +53,7 @@ public class FollowThread extends HttpServlet {
} }
} }
else if (followed) { else if (followed) {
System.out.println("déjà suivi");
try { try {
userDao.unfollowThread(user, threadDao.getThreadById((Integer.parseInt(req.getParameter("threadid"))))); userDao.unfollowThread(user, threadDao.getThreadById((Integer.parseInt(req.getParameter("threadid")))));
res.sendRedirect("http://localhost:8080/s4a021-web-backend/Discover"); res.sendRedirect("http://localhost:8080/s4a021-web-backend/Discover");
......
...@@ -192,6 +192,7 @@ public class UserDAO { ...@@ -192,6 +192,7 @@ public class UserDAO {
ps.setInt(2, thread.getId()); ps.setInt(2, thread.getId());
Date date = Date.valueOf(LocalDate.now()); Date date = Date.valueOf(LocalDate.now());
ps.setDate(3, date); ps.setDate(3, date);
ps.executeUpdate(); ps.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
...@@ -200,10 +201,13 @@ public class UserDAO { ...@@ -200,10 +201,13 @@ public class UserDAO {
} }
public void unfollowThread(User user, MyThread thread) throws SQLException { public void unfollowThread(User user, MyThread thread) throws SQLException {
PreparedStatement ps = this.con.prepareStatement("DELETE FROM follow WHERE userID_follow = ? AND threadID_follow = ?)"); System.out.println("dans méthode");
PreparedStatement ps = this.con.prepareStatement("DELETE FROM follow WHERE userID_follow=? AND threadID_follow=?");
try { try {
ps.setInt(1, user.getId()); ps.setInt(1, user.getId());
ps.setInt(2, thread.getId()); ps.setInt(2, thread.getId());
System.out.println(ps);
ps.executeUpdate(); ps.executeUpdate();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment