package projet;

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;

import java.io.IOException;

@WebServlet("/Partage")
public class Partage extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public Partage() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		Utilisateur u = (Utilisateur) session.getAttribute("utilisateur");
		
		String idPStr = request.getParameter("idP");
		String idPageStr = request.getParameter("idPage");
		
		if(u != null && idPStr != null) {
			int idP = Integer.parseInt(idPStr);
			int idPage = Integer.parseInt(idPageStr);
			
			Page.partagerPage(idPage, u.getId(), idP);
			response.sendRedirect("AfficherPage?id="+idPageStr);
		}else {
			response.sendRedirect("/Projet/");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
