diff --git a/WEB-INF/src/controleur/Navigation.java b/WEB-INF/src/controleur/Navigation.java index 7fd9b746131ef25f95b52bb398bd896fb5da5187..fb22dba3a4429fd2e905306a89098fe73dc22020 100644 --- a/WEB-INF/src/controleur/Navigation.java +++ b/WEB-INF/src/controleur/Navigation.java @@ -14,7 +14,7 @@ public class Navigation extends HttpServlet{ public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String page = (String) req.getParameter("page"); String vue; - + // vérification de l'authentification if(req.getSession().getAttribute("username") == null){ resp.sendRedirect("index.html"); @@ -32,6 +32,9 @@ public class Navigation extends HttpServlet{ case "compte": vue = "WEB-INF/vue/compte.jsp"; break; + case "filsSuivis": + vue = "WEB-INF/vue/filsSuivis.jsp"; + break; default: vue = "WEB-INF/vue/accueil.jsp"; } diff --git a/WEB-INF/src/modele/dao/DaoThread.java b/WEB-INF/src/modele/dao/DaoThread.java index b02e88b482d9ed218e602f0127796723726354c7..ad0b632de7a2f4dabef05af612b8921e5421eb29 100644 --- a/WEB-INF/src/modele/dao/DaoThread.java +++ b/WEB-INF/src/modele/dao/DaoThread.java @@ -97,4 +97,20 @@ public class DaoThread { } return res; } + + public List<Thread> findThreadFollow(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 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; + } } diff --git a/WEB-INF/vue/filsSuivis.jsp b/WEB-INF/vue/filsSuivis.jsp new file mode 100644 index 0000000000000000000000000000000000000000..141308c12bb6dfd3e3867a7b0d0480484c584b0d --- /dev/null +++ b/WEB-INF/vue/filsSuivis.jsp @@ -0,0 +1,88 @@ +<%@ 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" %> + +<%! + DaoThread daoThread = new DaoThread(); + DaoUser daoUser = new DaoUser(); +%> + +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-type" content="text/html; charset=utf-8"> + <title>Villeneuve Chat - Fils suivis</title> + <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css"> + <link href="res/font.css" rel="stylesheet"> + </head> + <body> + <div class="container-fluid"> + <div class="row"> + <div class="col-md-auto bg-light sticky-top"> + <div class="d-flex flex-md-column flex-row flex-nowrap bg-light align-items-center sticky-top"> + <ul class="nav nav-pills nav-flush flex-md-column flex-row flex-nowrap mb-auto mx-auto text-center justify-content-between w-100 px-3 align-items-center"> + <div class="d-block p-3 pt-3"> + <img src="res/mini_logo.png" width="45px"> + </div> + <li class="nav-item"> + <a href="navigation?page=accueil" class="nav-link py-3 px-2" title="accueil" data-bs-toggle="tooltip" data-bs-placement="right"> + <i class="bi-house fs-1"></i> + </a> + </li> + <li> + <a href="navigation?page=fils" class="nav-link py-3 px-2" title="Fils" data-bs-toggle="tooltip" data-bs-placement="right"> + <i class="bi-threads fs-1"></i> + </a> + </li> + <li> + <a class="nav-link py-3 px-2" title="Fils suivis" data-bs-toggle="tooltip" data-bs-placement="right"> + <i class="bi-chat-heart-fill fs-1"></i> + </a> + </li> + <li> + <a href="navigation?page=creerFil" class="nav-link py-3 px-2" title="Créer un fil" data-bs-toggle="tooltip" data-bs-placement="right"> + <i class="bi-plus-square fs-1"></i> + </a> + </li> + <li> + <a href="navigation?page=compte" class="link-dark py-3 px-2" title="Compte" data-bs-toggle="tooltip" data-bs-placement="right"> + <i class="bi-person-circle h2"></i> + </a> + </li> + </ul> + </div> + </div> + <div class="col-sm p-3 min-vh-100"> + + <h1>Fils suivis !</h1> + <hr /> + + <% + System.out.println((String) request.getSession().getAttribute("username")); + User user = daoUser.findByUsername((String) request.getSession().getAttribute("username")); + %> + <% for (Thread fil : daoThread.findThreadFollow(user.getUsername())) { %> + + <div class="p-2 border border-primary border-3 rounded mb-3"> + <div class="d-flex justify-content-between"> + <div class="ms-2"> + <p class="fs-3"><%= fil.getName() %></p> + <span class="text-secondary">Par <%= fil.getCreator()%> le <%=fil.getDate()%></span> + </div> + <a class="me-3 align-self-center btn btn-primary" href="?follow=1">Suivre <i class="bi-heart-fill"></i></a> + </div> + </div> + + <% } %> + + <div class="bg-light p-3 d-flex justify-content-center border-top border-3"> + <a href="#" class="btn btn-outline-secondary">Remonter <i class="bi-arrow-up"></i></a> + </div> + </div> + </div> + </div> + </body> +</html> \ No newline at end of file