Skip to content
Snippets Groups Projects
Commit 7b7419a7 authored by Charlie Darques's avatar Charlie Darques
Browse files

bouton follow s'affiche différemment si l'user follow déjà le thread

parent 27d83f6d
No related branches found
No related tags found
No related merge requests found
......@@ -39,27 +39,29 @@ public class Discover extends HttpServlet {
out.println(PageGeneration.generateNavMenu());
List<MyThread> followedThreads = null;
List<Integer> followedThreads = null;
try {
followedThreads = userDao.getThreadsFollowedByUser(user);
System.out.println(followedThreads.get(2));
}
catch (SQLException sqle) {
sqle.getStackTrace();
}
if (!messages.isEmpty()) {
for (Message message : messages) {
MyThread msgThread = null;
try {
msgThread = threadDao.getThreadById(message.getThreadId());
System.out.println(msgThread.getId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
User sender = userDao.getUserById(message.getSenderId());
String senderName = sender.getUserName();
boolean followed = followedThreads.contains(msgThread);
boolean followed = followedThreads.contains(msgThread.getId());
System.out.println("suivi : " + followed);
out.println("<div class=\"message\">");
out.println("<h3 class=\"msgThread\">" + msgThread.getThreadName() + "</h3>");
......@@ -70,10 +72,10 @@ public class Discover extends HttpServlet {
out.println("<input name=\"threadid\" type=\"hidden\" value=\"" + msgThread.getId() +"\">");
if (followed) {
out.println("<button type=\"submit\">Followed</button>");
out.println("<button class=\"followed\" type=\"submit\">Followed</button>");
}
else {
out.println("<button type=\"submit\">Follow</button>");
out.println("<button class=\"unfollowed\" type=\"submit\">Follow</button>");
}
out.println("</form>");
}
......
......@@ -24,7 +24,7 @@ public class FollowThread extends HttpServlet {
ThreadDAO threadDao = new ThreadDAO();
List<MyThread> threadsFollowed = null;
List<Integer> threadsFollowed = null;
try {
threadsFollowed = userDao.getThreadsFollowedByUser(user);
}
......
......@@ -209,17 +209,15 @@ public class UserDAO {
}
// Récupérer les thread auxquels un utilisateur est abonné
public List<MyThread> getThreadsFollowedByUser(User user) throws SQLException {
List<MyThread> threads = new ArrayList<>();
ThreadDAO threadDAO = new ThreadDAO();
public List<Integer> getThreadsFollowedByUser(User user) throws SQLException {
List<Integer> threads = new ArrayList<>();
PreparedStatement ps = this.con.prepareStatement("SELECT threadID_follow FROM follow WHERE userID_follow = ?");
try {
ps.setInt(1, user.getId());
ResultSet rs = ps.executeQuery();
while(rs.next()){
int threadId = rs.getInt(1);
String threadname = threadDAO.getThreadById(threadId).getThreadName();
threads.add(new MyThread(threadId, threadname));
threads.add(threadId);
}
}
catch (SQLException sqle) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment