From e28df0deea07141c0cc11329d144f8ccd3c70777 Mon Sep 17 00:00:00 2001 From: Charlie Darques <charlie.darques.etu@univ-lille.fr> Date: Fri, 28 Feb 2025 10:04:18 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20fonctionnalit=C3=A9s=20:=20abonnement,?= =?UTF-8?q?=20poster=20un=20msg,=20r=C3=A9agir=20=C3=A0=20un=20msg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB-INF/src/dao/UserDAO.java | 45 ++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/WEB-INF/src/dao/UserDAO.java b/WEB-INF/src/dao/UserDAO.java index 9455f4d..a24270e 100644 --- a/WEB-INF/src/dao/UserDAO.java +++ b/WEB-INF/src/dao/UserDAO.java @@ -1,7 +1,9 @@ package dao; import java.sql.*; +import java.time.LocalDate; +import dto.Message; import dto.User; import jakarta.servlet.http.*; @@ -56,7 +58,7 @@ public class UserDAO extends HttpServlet{ public void addUser(User nUser){ try{ PreparedStatement stmt = this.con.prepareStatement("INSERT INTO userAccount VALUES (?,?,?)"); - stmt.setInt(1, nUser.getID()); + stmt.setInt(1, nUser.getId()); stmt.setString(2, nUser.getUserName()); stmt.setString(3, nUser.getPwd()); @@ -70,7 +72,7 @@ public class UserDAO extends HttpServlet{ public void removeUser(User nUser){ try{ PreparedStatement stmt = this.con.prepareStatement("DELETE FROM userAccount WHERE userID=?"); - stmt.setInt(1, nUser.getID()); + stmt.setInt(1, nUser.getId()); stmt.executeUpdate(); @@ -78,4 +80,43 @@ public class UserDAO extends HttpServlet{ sqle.getStackTrace(); } } + + // S'abonner à un thread + public void followThread(User user, Thread thread) throws SQLException { + PreparedStatement ps = this.con.prepareStatement("INSERT INTO follow VALUES(?, ?, ?)"); + try { + ps.setString(1, ""+user.getId()); + ps.setString(2, ""+thread.getId()); + ps.setString(3, LocalDate.now().toString()); + } + catch (SQLException sqle) { + sqle.getStackTrace(); + } + } + + // Poster un message dans un thread + public void postMessage(User user, Thread thread, String message) throws SQLException { + PreparedStatement ps = this.con.prepareStatement("INSERT INTO msg (userID_msg, threadID, msg) VALUES(?, ?, ?)"); + try { + ps.setInt(1, user.getId()); + ps.setInt(2, (int) thread.getId()); + ps.setString(3, message); + } + catch (SQLException sqle) { + sqle.getStackTrace(); + } + } + + // Réagir à un message + public void reactToMsg(User user, Message msg) throws SQLException { + PreparedStatement ps = this.con.prepareStatement("INSERT INTO reactions VALUES(?, ?, ?)"); + try { + ps.setInt(1, user.getId()); + ps.setInt(2, msg.getId()); + ps.setString(3, "true"); + } + catch (SQLException sqle) { + sqle.getStackTrace(); + } + } } \ No newline at end of file -- GitLab