From dbbfbe3b8bd83683d1c8a670cab1a57a46e642b4 Mon Sep 17 00:00:00 2001
From: Charlie Darques <charlie.darques.etu@univ-lille.fr>
Date: Mon, 17 Mar 2025 11:36:14 +0100
Subject: [PATCH] correction de bug pour unfollow

---
 WEB-INF/src/controleurs/FollowThread.java | 17 ++++++++---------
 WEB-INF/src/dao/UserDAO.java              |  6 +++++-
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/WEB-INF/src/controleurs/FollowThread.java b/WEB-INF/src/controleurs/FollowThread.java
index 8083319..53cd38a 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 f2e520a..2a32cdf 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) {
-- 
GitLab