Skip to content
Snippets Groups Projects
Commit 57c601c1 authored by Maxime Gosselin's avatar Maxime Gosselin
Browse files

Correction du bug: follow un fils déjà follow ne fais plus cracher

parent 96197b21
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment