From c9da67962e48fd30d405f5c1d934deed06c24a78 Mon Sep 17 00:00:00 2001
From: Charlie Darques <charlie.darques.etu@univ-lille.fr>
Date: Fri, 28 Feb 2025 13:48:42 +0100
Subject: [PATCH] =?UTF-8?q?ajout=20m=C3=A9thode=20r=C3=A9cup=C3=A9rer=20le?=
 =?UTF-8?q?s=20abonn=C3=A9s=20d'un=20thread?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 WEB-INF/src/dao/ThreadDAO.java | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/WEB-INF/src/dao/ThreadDAO.java b/WEB-INF/src/dao/ThreadDAO.java
index f59390f..eed9043 100644
--- a/WEB-INF/src/dao/ThreadDAO.java
+++ b/WEB-INF/src/dao/ThreadDAO.java
@@ -56,6 +56,29 @@ public class ThreadDAO {
         return messages;
     }
 
+    public List<User> getFollowersOfThread(int threadId) throws SQLException{
+        ArrayList<User> followers = new ArrayList<>();
+        try {
+            PreparedStatement ps = this.con.prepareStatement("""
+            SELECT u.userID, u.username, u.password FROM userAccount AS u
+            INNER JOIN follow AS f ON f.userID=u.userID
+            WHERE f.threadID_follow = ?
+            """);
+            ps.setInt(1, threadId);
+            ResultSet rs = ps.executeQuery();
+            while(rs.next()){
+                int userId = rs.getInt(1);
+                String username = rs.getString(2);
+                String password = rs.getString(3);
+
+                followers.add(new User(userId, username, password));
+            }
+        } catch (SQLException sqle) {
+            sqle.getStackTrace();
+        }
+        return followers;
+    }
+
     // Créer un thread
     public void createThread(User user, String threadName) throws SQLException {
         PreparedStatement ps = this.con.prepareStatement("INSERT INTO thread (userID_thread, threadName) VALUES(?, ?)");
-- 
GitLab