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

créer un fil

parent b8ea3583
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,9 @@ public class Navigation extends HttpServlet{
case "filsSuivis":
vue = "WEB-INF/vue/filsSuivis.jsp";
break;
case "creerFil":
vue = "WEB-INF/vue/creerFil.jsp";
break;
default:
vue = "WEB-INF/vue/accueil.jsp";
}
......
package controleur;
import java.io.IOException;
import java.time.LocalDate;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
......@@ -10,6 +11,7 @@ import jakarta.servlet.http.HttpServletResponse;
import modele.dao.DaoFollower;
import modele.dao.DaoThread;
import modele.dto.Follower;
import modele.dto.Thread;
@WebServlet("/thread")
public class ThreadController extends HttpServlet {
......@@ -25,9 +27,13 @@ public class ThreadController extends HttpServlet {
String vue;
DaoFollower daoFollower = new DaoFollower();
DaoThread daoThread = new DaoThread();
int idThread = Integer.parseInt(req.getParameter("id"));
Follower follow = new Follower(username, idThread);
int idThread;
if(req.getParameter("id") == null) idThread = -1;
else idThread = Integer.parseInt(req.getParameter("id"));
Follower follow = new Follower(username, idThread);
switch (action){
case "follow":
if(daoFollower.checkFollowerExist(follow)){
......@@ -48,6 +54,13 @@ public class ThreadController extends HttpServlet {
case "open":
vue = "WEB-INF/vue/chat.jsp?id=" + idThread;
break;
case "create":
String name = req.getParameter("name");
idThread = daoThread.create(new Thread(idThread, username, name, LocalDate.now()));
follow = new Follower(username, idThread);
daoFollower.create(follow);
vue = "WEB-INF/vue/chat.jsp?id=" + idThread;
break;
default:
vue = "WEB-INF/vue/fils.jsp";
}
......
......@@ -42,17 +42,23 @@ public class DaoThread {
return null;
}
public void create(Thread thread) {
// créer un thread et renvoie l'id
public int create(Thread thread) {
DS bdd = DS.getInstance();
int id = -1;
try (Connection con = bdd.getConnection()) {
PreparedStatement ps = con.prepareStatement("INSERT INTO threads (creator, name, date) VALUES (?, ?, ?)");
PreparedStatement ps = con.prepareStatement("INSERT INTO threads (creator, name, date) VALUES (?, ?, ?) RETURNING id_thread;");
ps.setString(1, thread.getCreator());
ps.setString(2, thread.getName());
ps.setDate(3, java.sql.Date.valueOf(thread.getDate()));
ps.executeUpdate();
ResultSet rs = ps.executeQuery();
if(rs.next()){
id = rs.getInt("id_thread");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return id;
}
public void delete(int idThread) {
......
<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Villeneuve Chat - Créer un fil</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="<%= request.getContextPath() %>/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="<%= request.getContextPath() %>/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 href="navigation?page=filsSuivis" class="nav-link py-3 px-2" title="Fils suivis" data-bs-toggle="tooltip" data-bs-placement="right">
<i class="bi-chat-heart fs-1"></i>
</a>
</li>
<li>
<a 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-fill 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">
<div><i class="bi-person-circle h2"></i></div>
</a>
</li>
</ul>
</div>
</div>
<div class="col-sm p-3 min-vh-100">
<h1>Créer un fil !</h1>
<hr />
<p>
Sur cette page, vous pouvez créer un fil que vous suivrez automatiquement.
Vous avez juste à lui donner un nom et le tour est joué !
</p>
<div class="d-flex justify-content-center mt-5">
<form id="creatingThreadForm" action="thread" method="post" class="w-75">
<input type="hidden" name="action" value="create"/>
<div>
<div class="mt-2 mb-3">
<p class="mb-1">Nom du fil</p>
<input class="form-control" name="name" type="text" placeholder="Chasse & pêche" maxlength="75">
</div>
<div class="mb-3">
<p class="mb-1">Créateur / Créatrice</p>
<input class="form-control" name="username" type="text" value="<%= (String) session.getAttribute("username")%>" disabled>
</div>
</div>
<div class="mt-5 d-flex flex-column justify-content-center">
<input class="btn btn-primary flex-fill" type="submit" value="Créer un fil">
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
\ 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