From 57c601c1b0d5358bf174367c7bb7c47aa45e14f5 Mon Sep 17 00:00:00 2001 From: Maxime Gosselin~ <maxime.gosselin.etu@univ-lille.fr> Date: Fri, 28 Feb 2025 10:00:43 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20du=20bug:=20follow=20un=20fils=20d?= =?UTF-8?q?=C3=A9j=C3=A0=20follow=20ne=20fais=20plus=20cracher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB-INF/src/controleur/ThreadController.java | 4 ++++ WEB-INF/src/modele/dao/DaoFollower.java | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/WEB-INF/src/controleur/ThreadController.java b/WEB-INF/src/controleur/ThreadController.java index 3e68542..b6e99aa 100644 --- a/WEB-INF/src/controleur/ThreadController.java +++ b/WEB-INF/src/controleur/ThreadController.java @@ -30,6 +30,10 @@ public class ThreadController extends HttpServlet { switch (action){ case "follow": + if(daoFollower.checkFollowerExist(follow)){ + resp.sendRedirect("index.html"); + return ; + } daoFollower.create(follow); vue = "WEB-INF/vue/filsSuivis.jsp"; break; diff --git a/WEB-INF/src/modele/dao/DaoFollower.java b/WEB-INF/src/modele/dao/DaoFollower.java index 837db24..2870eeb 100644 --- a/WEB-INF/src/modele/dao/DaoFollower.java +++ b/WEB-INF/src/modele/dao/DaoFollower.java @@ -53,7 +53,7 @@ public class DaoFollower { } } - public List<User> findByThreadID(int idThread){ + public List<User> findUsersByThreadID(int idThread){ DS bdd = DS.getInstance(); List<User> res = new ArrayList<>(); try(Connection con = bdd.getConnection()) { @@ -69,7 +69,7 @@ public class DaoFollower { return res; } - public List<Thread> findByUsername(String username){ + public List<Thread> findThreadsByUsername(String username){ DS bdd = DS.getInstance(); List<Thread> res = new ArrayList<>(); try(Connection con = bdd.getConnection()) { @@ -84,4 +84,19 @@ public class DaoFollower { } return res; } + + public boolean checkFollowerExist(Follower follower){ + DS bdd = DS.getInstance(); + boolean res = false; + try(Connection con = bdd.getConnection()) { + PreparedStatement ps = con.prepareStatement("SELECT * FROM followers WHERE username = ? AND id_thread = ?"); + ps.setString(1, follower.getUsername()); + ps.setInt(2, follower.getId_thread()); + ResultSet rs = ps.executeQuery(); + res = rs.next(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + return res; + } } -- GitLab