package course;

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 java.io.IOException;

@WebServlet("/CourseDeleteAction")
public class CourseDeleteAction extends HttpServlet {
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String path = req.getContextPath();
        if (req.getSession().getAttribute("user") == null){
            resp.sendRedirect(path+"/login/login.jsp");
            return;
        }
        int id = Integer.parseInt(req.getParameter("id"));
        CourseDB.deleteCourse(id);
        resp.sendRedirect(path+"/course/course.jsp");
    }
}
