diff --git a/WEB-INF/src/controleurs/FollowThread.java b/WEB-INF/src/controleurs/FollowThread.java index 80833190a8e7a20f348b9cb473e8524a07d18145..53cd38ab4dbbe8aa2bf5cbc2036ac2b4feaf769b 100644 --- a/WEB-INF/src/controleurs/FollowThread.java +++ b/WEB-INF/src/controleurs/FollowThread.java @@ -33,17 +33,15 @@ public class FollowThread extends HttpServlet { } boolean followed = false; - try { - if (threadsFollowed.contains(threadDao.getThreadById((Integer.parseInt(req.getParameter("threadid")))))) { - followed = true; - } - else { - followed = false; - } + + if (threadsFollowed.contains(Integer.parseInt(req.getParameter("threadid")))) { + followed = true; } - catch (SQLException sqle) { - sqle.getStackTrace(); + else { + followed = false; } + + System.out.println(followed); if (!followed) { try { @@ -55,6 +53,7 @@ public class FollowThread extends HttpServlet { } } else if (followed) { + System.out.println("déjà suivi"); try { userDao.unfollowThread(user, threadDao.getThreadById((Integer.parseInt(req.getParameter("threadid"))))); res.sendRedirect("http://localhost:8080/s4a021-web-backend/Discover"); diff --git a/WEB-INF/src/dao/UserDAO.java b/WEB-INF/src/dao/UserDAO.java index f2e520aae825ecdbf5f0bc039634e499d042e8f3..2a32cdf083281b93d35ed51f47db5c81cbcc630a 100644 --- a/WEB-INF/src/dao/UserDAO.java +++ b/WEB-INF/src/dao/UserDAO.java @@ -192,6 +192,7 @@ public class UserDAO { ps.setInt(2, thread.getId()); Date date = Date.valueOf(LocalDate.now()); ps.setDate(3, date); + ps.executeUpdate(); } catch (SQLException sqle) { @@ -200,10 +201,13 @@ public class UserDAO { } 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 { ps.setInt(1, user.getId()); ps.setInt(2, thread.getId()); + System.out.println(ps); + ps.executeUpdate(); } catch (SQLException sqle) {