package web.UserRelated;


import pojo.User;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/main/admin/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    UserService service = new UserService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        int user_id= Integer.parseInt(req.getParameter("user_id"));
        String name=req.getParameter("name");
        String telephone=req.getParameter("telephone");
        String user_type=req.getParameter("user_type");
        int parking_spot_id= Integer.parseInt(req.getParameter("parking_spot_id"));
        String address=req.getParameter("address");
        String gender=req.getParameter("gender");

        List<User> userlist=null;
        try {
            userlist=service.updateUser(user_id,name,telephone,user_type,parking_spot_id,address,gender);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        req.setAttribute("users",userlist);
        req.getRequestDispatcher("/main/admin/adminUser.jsp?").forward(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}



