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

ajout fonctionnalités : abonnement, poster un msg, réagir à un msg

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