Skip to content
Snippets Groups Projects
Commit 340ddd5d authored by Florine Lefebvre's avatar Florine Lefebvre :stuck_out_tongue_closed_eyes:
Browse files

suppression de thread en cascade

parent ade06394
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import modele.dao.DaoFollower;
import modele.dao.DaoThread;
import modele.dto.Follower;
@WebServlet("/thread")
......@@ -23,6 +24,7 @@ public class ThreadController extends HttpServlet {
String action = (String) req.getParameter("action");
String vue;
DaoFollower daoFollower = new DaoFollower();
DaoThread daoThread = new DaoThread();
int idThread = Integer.parseInt(req.getParameter("id"));
Follower follow = new Follower(username, idThread);
......@@ -39,6 +41,10 @@ public class ThreadController extends HttpServlet {
daoFollower.delete(follow);
vue = "WEB-INF/vue/filsSuivis.jsp";
break;
case "delete":
daoThread.delete(idThread);
vue = "WEB-INF/vue/accueil.jsp";
break;
default:
vue = "WEB-INF/vue/fils.jsp";
}
......
......@@ -113,7 +113,7 @@
</div>
<div class="d-flex">
<a class="me-3 align-self-center btn btn-primary" href="?chat=<%= thread.getId_thread() %>">Ouvrir <i class="bi-chat-fill"></i></a>
<a class="me-3 align-self-center btn btn-danger" href="?delete=<%= thread.getId_thread() %>">Supprimer <i class="bi-x-circle-fill"></i></a>
<a class="me-3 align-self-center btn btn-danger" href="thread?action=delete&id=<%= thread.getId_thread() %>">Supprimer <i class="bi-x-circle-fill"></i></a>
</div>
</div>
</div>
......
DROP TABLE IF EXISTS followers;
DROP TABLE IF EXISTS messages;
DROP TABLE IF EXISTS followers;
DROP TABLE IF EXISTS threads;
DROP TABLE IF EXISTS users;
......@@ -26,7 +25,7 @@ CREATE TABLE followers (
PRIMARY KEY (username, id_thread),
FOREIGN KEY (username) REFERENCES users(username),
FOREIGN KEY (id_thread) REFERENCES threads(id_thread)
FOREIGN KEY (id_thread) REFERENCES threads(id_thread) ON DELETE CASCADE
);
CREATE TABLE messages (
......@@ -37,6 +36,6 @@ CREATE TABLE messages (
time TIMESTAMP WITH TIME ZONE,
FOREIGN KEY (sender) REFERENCES users(username),
FOREIGN KEY (id_thread) REFERENCES threads(id_thread)
FOREIGN KEY (id_thread) REFERENCES threads(id_thread) ON DELETE CASCADE
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment