diff --git a/sql/cda202601_jee_g3.sql b/sql/cda202601_jee_g3.sql new file mode 100644 index 0000000000000000000000000000000000000000..cc9169a6838a7414d824ca8f7bc199070a9fac64 --- /dev/null +++ b/sql/cda202601_jee_g3.sql @@ -0,0 +1,204 @@ +-- phpMyAdmin SQL Dump +-- version 5.2.3 +-- https://www.phpmyadmin.net/ +-- +-- Hôte : mariadb +-- Généré le : jeu. 15 oct. 2026 à 06:29 +-- Version du serveur : 11.2.6-MariaDB-ubu2204 +-- Version de PHP : 8.3.33 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Base de données : `cda202601_jee_g3` +-- + +-- -------------------------------------------------------- + +-- +-- Structure de la table `Comment` +-- + +CREATE TABLE `Comment` ( + `Id_Comment` int(11) NOT NULL, + `content` text NOT NULL, + `status_comment` int(11) NOT NULL, + `Id_Post` int(11) NOT NULL, + `Id_User` int(11) NOT NULL, + `date_publish` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- +-- Déchargement des données de la table `Comment` +-- + +INSERT INTO `Comment` (`Id_Comment`, `content`, `status_comment`, `Id_Post`, `Id_User`, `date_publish`) VALUES +(1, 'Grâce à ton tuto j ai enfin réussi à le plaquer ce matin ! Merci pour les conseils.', 1, 1, 4, '2026-10-12 12:01:50'), +(2, 'Trop propre le pop sur le ledge ! Tu roules avec quelle taille de planches ?', 1, 2, 6, '2026-10-12 12:01:50'); + +-- -------------------------------------------------------- + +-- +-- Structure de la table `Post` +-- + +CREATE TABLE `Post` ( + `Id_Post` int(11) NOT NULL, + `video` text NOT NULL, + `title` varchar(50) NOT NULL, + `description` text NOT NULL, + `date_post` date NOT NULL, + `Id_User` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- +-- Déchargement des données de la table `Post` +-- + +INSERT INTO `Post` (`Id_Post`, `video`, `title`, `description`, `date_post`, `Id_User`) VALUES +(1, 'zqKtch4dg94', 'Apprendre le Kickflip parfait', 'Tutoriel étape par étape pour réussir son premier kickflip en flat. Attention au positionnement du pied avant et au grattage !', '2026-10-12', 4), +(2, 'mphghjzquzA', 'Maitriser le 50-50 grind', 'Petite session de street ce weekend, focus sur l entrée et la sortie propre du 50-50 sur un ledge bas.', '2026-10-12', 5), +(33, 'kAioxXpNccg', 'Luan Oliveira présente l\'art du kickflip', 'Luan Oliveira possède l’un des meilleurs kickflips de tout le monde du skateboard, et nous ne pouvions pas imaginer de meilleure façon de lancer la Kickflip Week qu’avec The Art of The Kickflip de Luan.\n\nÉcoutez Luan raconter l’histoire de ce trick, parler de sa plus grande influence pour les kickflips et révéler son kickflip préféré parmi tous ceux qu’il a réussis, tout en démontrant la qualité exceptionnelle de son flick dans The Art of The Kickflip.\n\nRestez connectés pour découvrir encore plus de contenu sur les kickflips tout au long de cette semaine, jusqu’au #NationalDoAKickflipDay, le 29 avril. Et n’oubliez pas de vous procurer dès maintenant une planche Art of The Kickflip dédicacée par Luan Oliveira, disponible dans The Canteen !', '2026-02-14', 3), +(34, 'xOGbW67JTJM', 'INCROYABLE ! Les Heelflips de Neen Williams', 'Heelflip, heelflip, heelflip, heelflip et… HEEEEELFLIP !', '2026-07-23', 1), +(35, 'DZwSoGjdWgc', 'Le meilleur Varial Kickflip de tous les temps.', 'Oui, c’est un montage revisité.', '2026-03-08', 5), +(36, 'yyI_QzVNsCM', '360 Flips exécutés sans le moindre effort', 'Nyjah enchaîne quelques 360 Flips avec une facilité déconcertante et explique comment il a commencé à apprendre ce trick. Pour Nyjah, en réussir trois semble être l’une des choses les plus faciles au monde du skate.', '2026-11-19', 2), +(38, 'pK6KefrBR0A', 'SESSION DE SKATE ET PRESSURE FLIPS !', 'L’objectif de Braille Skateboarding est d’augmenter le nombre de personnes qui pratiquent le skateboard en enseignant, en motivant et en inspirant les skateurs.\n\nPour cela, nous réalisons des vidéos de tutoriels couvrant toutes les techniques de skateboard imaginables, du soleil à la lune, en passant par les étoiles.\n\nNous apprenons nous-mêmes et montrons qu’il est possible d’apprendre à skater à tout âge, que l’on soit jeune ou moins jeune. Cela passe notamment par la proposition d’un parcours d’apprentissage pour progresser en skateboard.', '2026-09-11', 2), +(39, '_SOLNidtfxY', 'Les Hardflips du Hall of Fame', 'Notre nouvelle série Hall of Fame commence avec l’un des tricks de skateboard les plus demandés.\n\nDites-nous en commentaire quel trick vous aimeriez voir dans le prochain épisode !', '2026-01-27', 5), +(40, 'baNXlQpNFyY', 'Skateology - Inward Heelflip', 'Joe Vizzaccero réalise des Inward Heelflips au ralenti.', '2026-08-06', 1), +(42, '_GjYnVc_XHY', 'Nightmare Flip en super slow mo', 'Un Nightmare Flip filmé avec une GoPro...', '2026-12-03', 3), +(44, 'T1eOo5Es8uo', 'Comment réaliser un Forward Flip', 'Découvrez comment réaliser un Forward Flip avec Robbie Tootle !', '2026-10-09', 5), +(45, 'taicrXUDiWI', 'Hospital Flip contre Casper Flip', 'La différence entre le Hospital Flip et le Casper Flip, c’est que le Hospital Flip se réalise avec un seul pied, tandis que le Casper Flip nécessite les deux pieds pour exécuter le trick.\n\nJe réalise des Hospital Flips très régulièrement, mais je fais rarement des Casper Flips.', '2026-02-28', 2), +(46, 'ZmLCSc5n43g', 'LE MEILLEUR BIGFLIP DANS UN ESCALIER', 'Kyle Billups relève le défi de réussir un Bigflip sur un double set en briques, en plein centre-ville de Portland.', '2026-05-26', 3); + +-- -------------------------------------------------------- + +-- +-- Structure de la table `Vote` +-- + +CREATE TABLE `Vote` ( + `Id_User` int(11) NOT NULL, + `Id_Post` int(11) NOT NULL, + `voted` tinyint(1) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- -------------------------------------------------------- + +-- +-- Structure de la table `Web_user` +-- + +CREATE TABLE `Web_user` ( + `Id_User` int(11) NOT NULL, + `username` varchar(50) NOT NULL, + `email` varchar(50) NOT NULL, + `password` varchar(50) NOT NULL, + `status_user` varchar(50) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- +-- Déchargement des données de la table `Web_user` +-- + +INSERT INTO `Web_user` (`Id_User`, `username`, `email`, `password`, `status_user`) VALUES +(1, 'Julien', 'julien@ldnr.fr', '123', 'admin'), +(2, 'Axel', 'axel@ldnr.fr', '123', 'admin'), +(3, 'Adrien', 'adrien@ldnr.fr', '123', 'admin'), +(4, 'Sophie', 'sophie@adrar.fr', '123', 'user'), +(5, 'KickflipKing', 'maxime@skate.fr', '123', 'user'), +(6, 'SkateGirl31', 'chloe@skate.fr', '123', 'user'), +(7, 'OllieMaster', 'leo@skate.fr', '123', 'user'); + +-- +-- Index pour les tables déchargées +-- + +-- +-- Index pour la table `Comment` +-- +ALTER TABLE `Comment` + ADD PRIMARY KEY (`Id_Comment`), + ADD KEY `Id_Post` (`Id_Post`), + ADD KEY `Id_User` (`Id_User`); + +-- +-- Index pour la table `Post` +-- +ALTER TABLE `Post` + ADD PRIMARY KEY (`Id_Post`), + ADD UNIQUE KEY `video` (`video`) USING HASH, + ADD KEY `Id_User` (`Id_User`); + +-- +-- Index pour la table `Vote` +-- +ALTER TABLE `Vote` + ADD PRIMARY KEY (`Id_User`,`Id_Post`), + ADD KEY `Id_Post` (`Id_Post`); + +-- +-- Index pour la table `Web_user` +-- +ALTER TABLE `Web_user` + ADD PRIMARY KEY (`Id_User`), + ADD UNIQUE KEY `username` (`username`), + ADD UNIQUE KEY `email` (`email`); + +-- +-- AUTO_INCREMENT pour les tables déchargées +-- + +-- +-- AUTO_INCREMENT pour la table `Comment` +-- +ALTER TABLE `Comment` + MODIFY `Id_Comment` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- +-- AUTO_INCREMENT pour la table `Post` +-- +ALTER TABLE `Post` + MODIFY `Id_Post` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=47; + +-- +-- AUTO_INCREMENT pour la table `Web_user` +-- +ALTER TABLE `Web_user` + MODIFY `Id_User` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17; + +-- +-- Contraintes pour les tables déchargées +-- + +-- +-- Contraintes pour la table `Comment` +-- +ALTER TABLE `Comment` + ADD CONSTRAINT `Comment_ibfk_1` FOREIGN KEY (`Id_Post`) REFERENCES `Post` (`Id_Post`), + ADD CONSTRAINT `Comment_ibfk_2` FOREIGN KEY (`Id_User`) REFERENCES `Web_user` (`Id_User`); + +-- +-- Contraintes pour la table `Post` +-- +ALTER TABLE `Post` + ADD CONSTRAINT `Post_ibfk_1` FOREIGN KEY (`Id_User`) REFERENCES `Web_user` (`Id_User`); + +-- +-- Contraintes pour la table `Vote` +-- +ALTER TABLE `Vote` + ADD CONSTRAINT `Vote_ibfk_1` FOREIGN KEY (`Id_User`) REFERENCES `Web_user` (`Id_User`), + ADD CONSTRAINT `Vote_ibfk_2` FOREIGN KEY (`Id_Post`) REFERENCES `Post` (`Id_Post`); +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/src/main/java/beans/Vote.java b/src/main/java/beans/Vote.java new file mode 100644 index 0000000000000000000000000000000000000000..8fdbb30c0718f631b2bf42bf0ae7b401c4e0e8a7 --- /dev/null +++ b/src/main/java/beans/Vote.java @@ -0,0 +1,51 @@ + +package beans; + +/** + * + * @author Julien + */ +public class Vote { + + private int id; + private Web_user user; + private Post post; + private int score; + + public Vote() {} + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Web_user getUser() { + return user; + } + + public void setUser(Web_user user) { + this.user = user; + } + + public Post getPost() { + return post; + } + + public void setPost(Post post) { + this.post = post; + } + + public int getScore() { + return score; + } + + public void setScore(int score) { + this.score = score; + } + + + +} diff --git a/src/main/java/dao/DaoFactory.java b/src/main/java/dao/DaoFactory.java index 404067faf54e0e2f9723302b5196a45a4a709244..debd4a9db71c4d05fe0262a264d479e0c2a024b7 100644 --- a/src/main/java/dao/DaoFactory.java +++ b/src/main/java/dao/DaoFactory.java @@ -9,6 +9,7 @@ public final class DaoFactory { private static Web_userDao wdao; private static PostDao pdao; private static CommentDao cdao; + private static VoteDao vdao; private DaoFactory() { @@ -23,6 +24,8 @@ public final class DaoFactory { dao = getPostDao(); case "comment" -> dao = getCommentDao(); + case "vote" -> + dao = getVoteDao(); default -> throw new AssertionError(); } @@ -40,6 +43,13 @@ public final class DaoFactory { public static CommentDao getCommentDao(){ return new CommentDao(); } + + public static VoteDao getVoteDao() { + return new VoteDao(); + } + + + } diff --git a/src/main/java/dao/VoteDao.java b/src/main/java/dao/VoteDao.java new file mode 100644 index 0000000000000000000000000000000000000000..46a39ac5d7ba9da36b43eef07ebf0b503ad0e4e7 --- /dev/null +++ b/src/main/java/dao/VoteDao.java @@ -0,0 +1,114 @@ + +package dao; + +import beans.Vote; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Julien + */ +public class VoteDao extends Dao { + + private static final Logger LOGGER = Logger.getLogger(VoteDao.class.getName()); + + // Compter les votes positifs (voted = 1 / true) + public int countPositiveForPost(long postId) { + int count = 0; + String sql = "SELECT COUNT(*) FROM Vote WHERE Id_Post = ? AND voted = 1"; + try (PreparedStatement pstmt = connexion.prepareStatement(sql)) { + pstmt.setLong(1, postId); + try (ResultSet rs = pstmt.executeQuery()) { + if (rs.next()) { + count = rs.getInt(1); + } + } + } catch (SQLException e) { + LOGGER.log(Level.SEVERE, "Erreur lors du comptage des votes positifs pour le post ID: " + postId, e); + } + return count; + } + + // Compter le total des votes pour un post + public int countTotalForPost(long postId) { + int count = 0; + String sql = "SELECT COUNT(*) FROM Vote WHERE Id_Post = ?"; + try (PreparedStatement pstmt = connexion.prepareStatement(sql)) { + pstmt.setLong(1, postId); + try (ResultSet rs = pstmt.executeQuery()) { + if (rs.next()) { + count = rs.getInt(1); + } + } + } catch (SQLException e) { + LOGGER.log(Level.SEVERE, "Erreur lors du comptage total des votes pour le post ID: " + postId, e); + } + return count; + } + + // Enregistrer ou mettre à jour un vote (Insert si absent, Update si l'utilisateur a déjà voté) + public void saveOrUpdateVote(long userId, long postId, boolean voteValue) { + String sql = "INSERT INTO Vote (Id_User, Id_Post, voted) VALUES (?, ?, ?) " + + "ON DUPLICATE KEY UPDATE voted = ?"; + try (PreparedStatement pstmt = connexion.prepareStatement(sql)) { + pstmt.setLong(1, userId); + pstmt.setLong(2, postId); + pstmt.setBoolean(3, voteValue); + pstmt.setBoolean(4, voteValue); + pstmt.executeUpdate(); + } catch (SQLException e) { + LOGGER.log(Level.SEVERE, "Erreur lors de l'enregistrement du vote", e); + } + } + + public Boolean getUserVote(long userId, long postId) { + String sql = "SELECT voted FROM Vote WHERE Id_User = ? AND Id_Post = ?"; + try (PreparedStatement pstmt = connexion.prepareStatement(sql)) { + pstmt.setLong(1, userId); + pstmt.setLong(2, postId); + try (ResultSet rs = pstmt.executeQuery()) { + if (rs.next()) { + return rs.getBoolean("voted"); // true (up) ou false (down) + } + } + } catch (SQLException e) { + LOGGER.log(Level.SEVERE, "Erreur lors de la récupération du vote de l'utilisateur", e); + } + return null; // Pas de vote trouvé +} + + @Override + public Vote find(Long id) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public Vote create(Vote obj) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public Vote update(Vote obj) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public void delete(Vote obj) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public int count() { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public List list() { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } +} diff --git a/src/main/java/servlet/HomeServlet.java b/src/main/java/servlet/HomeServlet.java index 5304b983d2810a0c308fbf7851ee0328abcf967a..958f4ed8353309adde8b081edeef08d320ede90a 100644 --- a/src/main/java/servlet/HomeServlet.java +++ b/src/main/java/servlet/HomeServlet.java @@ -5,6 +5,7 @@ import beans.Web_user; import dao.CommentDao; import dao.DaoFactory; import dao.PostDao; +import dao.VoteDao; import dao.Web_userDao; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; @@ -37,13 +38,22 @@ public class HomeServlet extends HttpServlet { request.setAttribute("users", users); CommentDao commentDao = DaoFactory.getCommentDao(); + VoteDao voteDao = DaoFactory.getVoteDao(); Map commentsCount = new HashMap<>(); for (Post post : posts) { commentsCount.put(post.getId(), commentDao.count(post.getId())); + + int totalVotes = voteDao.countTotalForPost(post.getId()); + int positiveVotes = voteDao.countPositiveForPost(post.getId()); + + double score = 0; + if (totalVotes > 0) { + score = ((double) positiveVotes / totalVotes) * 100; + } + post.setScore((int)Math.round(score)); } request.setAttribute("commentsCount", commentsCount); - this.getServletContext().getRequestDispatcher(VIEW).forward(request, response); } } diff --git a/src/main/java/servlet/ProfileServlet.java b/src/main/java/servlet/ProfileServlet.java index 00ad5a0b5001ad416c9995a4d081fdd902801d2b..dbc9413d5597f258b923cf2d1685bf62c765bb5a 100644 --- a/src/main/java/servlet/ProfileServlet.java +++ b/src/main/java/servlet/ProfileServlet.java @@ -5,6 +5,7 @@ import beans.Web_user; import dao.CommentDao; import dao.DaoFactory; import dao.PostDao; +import dao.VoteDao; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; @@ -40,12 +41,25 @@ public class ProfileServlet extends HttpServlet { try { PostDao postDao = DaoFactory.getPostDao(); + VoteDao voteDao = DaoFactory.getVoteDao(); List allPosts = postDao.list(); List userPosts = allPosts.stream() .filter(p -> p.getAuthor() != null && p.getAuthor().getId() == currentUser.getId()) .collect(Collectors.toList()); + + // Calcul du score pour chaque post de l'utilisateur + for (Post post : userPosts) { + int totalVotes = voteDao.countTotalForPost(post.getId()); + int positiveVotes = voteDao.countPositiveForPost(post.getId()); + double score = 0; + if (totalVotes > 0) { + score = ((double) positiveVotes / totalVotes) * 100; + } + post.setScore((int) Math.round(score)); + } + request.setAttribute("userPosts", userPosts); // Nombre de commentaires diff --git a/src/main/java/servlet/VideoServlet.java b/src/main/java/servlet/VideoServlet.java index f99898cf7674d84bca67f9daa9cc3d568be98537..bce72571ef4505a35699519f95dac0ce2f300a86 100644 --- a/src/main/java/servlet/VideoServlet.java +++ b/src/main/java/servlet/VideoServlet.java @@ -6,6 +6,7 @@ import beans.Web_user; import dao.CommentDao; import dao.DaoFactory; import dao.PostDao; +import dao.VoteDao; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; @@ -38,7 +39,6 @@ public class VideoServlet extends HttpServlet { } Long postId; - // Change le String en Long try { postId = Long.valueOf(idParam); } catch (NumberFormatException e) { @@ -48,6 +48,33 @@ public class VideoServlet extends HttpServlet { Post post = postDao.find(postId); + if (post != null) { + // Récupérer l'utilisateur connecté en session + HttpSession session = request.getSession(false); + Web_user currentUser = (session != null) ? (Web_user) session.getAttribute("sessionUser") : null; + + VoteDao voteDao = DaoFactory.getVoteDao(); + + // Récupérer le vote de l'utilisateur pour cette vidéo et l'envoyer à la JSP + if (currentUser != null) { + Boolean userVote = voteDao.getUserVote(currentUser.getId(), post.getId()); + System.out.println("DEBUG SERVLET - Valeur de userVote transmise à la JSP: " + userVote); + + // On passe directement la valeur booléenne en attribut unique + request.setAttribute("userVote", userVote); + } + + // CALCUL DU SCORE DE VOTE POUR CE POST + int totalVotes = voteDao.countTotalForPost(post.getId()); + int positiveVotes = voteDao.countPositiveForPost(post.getId()); + + double score = 0; + if (totalVotes > 0) { + score = ((double) positiveVotes / totalVotes) * 100; + } + post.setScore((int) Math.round(score)); + } + request.setAttribute("post", post); // COMMENTAIRES diff --git a/src/main/java/servlet/VoteServlet.java b/src/main/java/servlet/VoteServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..bc1ac8964f22219091c38dd83ebce9ae2d251d36 --- /dev/null +++ b/src/main/java/servlet/VoteServlet.java @@ -0,0 +1,70 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template + */ +package servlet; + +import beans.Web_user; +import dao.DaoFactory; +import dao.VoteDao; +import java.io.IOException; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +/** + * + * @author Julien + */ +@WebServlet(name = "VoteServlet", urlPatterns = {"/vote"}) +public class VoteServlet extends HttpServlet { + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + HttpSession session = request.getSession(false); + Web_user currentUser = (session != null) ? (Web_user) session.getAttribute("sessionUser") : null; + + if (currentUser == null) { + response.sendRedirect(request.getContextPath() + "/login"); + return; + } + + String postIdStr = request.getParameter("postId"); + String voteTypeStr = request.getParameter("voteType"); + + if (postIdStr != null && !postIdStr.trim().isEmpty() && voteTypeStr != null) { + try { + long postId = Long.parseLong(postIdStr); + long userId = currentUser.getId(); + + // "up" = true (1), "down" = false (0) + boolean voteValue = voteTypeStr.equals("up"); + + VoteDao voteDao = DaoFactory.getVoteDao(); + voteDao.saveOrUpdateVote(userId, postId, voteValue); + + } catch (NumberFormatException e) { + + } + } + + // Redirection vers la page précédente + String referer = request.getHeader("Referer"); + if (referer != null && !referer.isEmpty()) { + response.sendRedirect(referer); + } else { + response.sendRedirect(request.getContextPath() + "/home"); + } + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.sendRedirect(request.getContextPath() + "/home"); + } +} \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/home.jsp b/src/main/webapp/WEB-INF/home.jsp index 6df8b466e538d7c289f9eb99377c0df1a071e02c..5652d0b654ad8500bdbaf2bfdabc2d128e1cb92e 100644 --- a/src/main/webapp/WEB-INF/home.jsp +++ b/src/main/webapp/WEB-INF/home.jsp @@ -19,8 +19,15 @@

MONTRE-NOUS TON MEILLEUR TRICK

La référence des tricks de skate, partagés par la communauté.

@@ -37,7 +44,7 @@
Votes -

50

+

${thisPost.score}%

Votes -

50

+

${thisPost.score}%

<%@include file="jspf/header.jspf" %> - +
- +

Mes vidéos

@@ -39,7 +39,7 @@
Votes -

0

+

${post.score}%

Comments @@ -57,8 +57,7 @@
- - +

Ajouter une vidéo

diff --git a/src/main/webapp/WEB-INF/video.jsp b/src/main/webapp/WEB-INF/video.jsp index 6effb99aaf219f57aa089affa78386ddbc30d44f..76af3c7dc53f5ec5b38a60175a11048ddf9a8294 100644 --- a/src/main/webapp/WEB-INF/video.jsp +++ b/src/main/webapp/WEB-INF/video.jsp @@ -27,10 +27,39 @@

Publié le

-
- thumbs up -

${post.score}

- thumbs down +
+ +
+ + + +
+ +

${post.score}%

+ +
+ + + +

diff --git a/src/main/webapp/assets/css/style.css b/src/main/webapp/assets/css/style.css index 85bfea645e86f3c760c8539996b9a979f71ddc7d..26efb8958cc26c2218a937121764d4b7ea79b2fb 100644 --- a/src/main/webapp/assets/css/style.css +++ b/src/main/webapp/assets/css/style.css @@ -210,12 +210,12 @@ nav > img { opacity: 0.9; } -h2 { +/*h2 { font-size: 30px; margin: 20px; color: white; font-family: 'Permanent Marker', cursive; -} +}*/ .videos-container { display: flex; @@ -474,7 +474,44 @@ a, button, input[type="submit"], input[type="button"] { 0 0 10px rgba(232, 67, 147, 0.8); } + h2{ + display: inline-block; + /*background-color: #2c2f33;*/ + background-image: url('../img/grip.jpg'); + background-size: cover; + background-position: center; + color: #ffffff; + font-family: 'Permanent Marker', cursive, sans-serif; + font-size: 30px; + font-weight: normal; + text-align: center; + padding: 20px 60px; + border-radius: 50px; + border: 3px solid #c89d55; + box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3), inset 0 2px 4px rgba(255, 255, 255, 0.1); + position: relative; + margin: 40px auto; +} + + +/*------------------- Vote ------------ */ + +.vote-container{ + display: flex; + align-items: center; + gap: 10px +} + +.vote-container form{ + margin: 0; +} +.vote-container button{ + background: none; + border: none; + cursor: pointer; + padding: 0; +} /*------------------- JSP VIDEO ------------ */ .main-video { display: flex; @@ -671,3 +708,5 @@ a, button, input[type="submit"], input[type="button"] { #message { margin: 10px 0; } + + diff --git a/src/main/webapp/assets/img/grip.jpg b/src/main/webapp/assets/img/grip.jpg new file mode 100644 index 0000000000000000000000000000000000000000..594b8bc98e8377b0a87cf6c767a41572df22a50b Binary files /dev/null and b/src/main/webapp/assets/img/grip.jpg differ