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

Affiche seulement les threads non suivis dans la page pour suivre des threads

parent 13eda069
No related branches found
No related tags found
No related merge requests found
......@@ -81,4 +81,20 @@ public class DaoThread {
}
return res;
}
public List<Thread> findThreadNotFollow(String creator) {
DS bdd = DS.getInstance();
List<Thread> res = new ArrayList<>();
try(Connection con = bdd.getConnection()) {
PreparedStatement ps = con.prepareStatement("SELECT * FROM threads WHERE id_thread NOT IN (SELECT id_thread FROM followers WHERE username = ?)");
ps.setString(1, creator);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
res.add(new Thread(rs.getInt("id_thread"), rs.getString("creator"), rs.getString("name"), rs.getDate("date").toLocalDate()));
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return res;
}
}
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="modele.dao.DaoThread" %>
<%@ page import="modele.dto.Thread" %>
<%@ page import="modele.dao.DaoUser" %>
<%@ page import="modele.dto.User" %>
<%
// vérification de l'authentification
if(request.getSession().getAttribute("username") == null) response.sendRedirect("index.html");
......@@ -8,6 +10,7 @@
<%!
DaoThread daoThread = new DaoThread();
DaoUser daoUser = new DaoUser();
%>
<!DOCTYPE html>
......@@ -60,8 +63,11 @@
<h1>Liste des fils !</h1>
<hr />
<% for (Thread fil : daoThread.findAll()) { %>
<%
System.out.println((String) request.getSession().getAttribute("username"));
User user = daoUser.findByUsername((String) request.getSession().getAttribute("username"));
%>
<% for (Thread fil : daoThread.findThreadNotFollow(user.getUsername())) { %>
<div class="p-2 border border-primary border-3 rounded mb-3">
<div class="d-flex justify-content-between">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment