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("/courseAddAction")
public class courseAddAction extends HttpServlet {
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        courseDB coursedb = new courseDB();
        int id = Integer.parseInt(req.getParameter("id"));
        courseInfo course = new courseInfo();
        String name = req.getParameter("name");
        int type = Integer.parseInt(req.getParameter("type"));
        float credit = Float.parseFloat(req.getParameter("credit"));
        int grade = Integer.parseInt(req.getParameter("grade"));
        int major = Integer.parseInt(req.getParameter("major"));
        String detail = req.getParameter("detail");
        course.setName(name);
        course.setType(type);
        course.setCredit(credit);
        course.setGrade(grade);
        course.setMajor(major);
        course.setDetail(detail);
        coursedb.insertCourse(course);
        String path = req.getContextPath();
        resp.sendRedirect(path+"/course/course.jsp");
    }
}
