package web.IcCardRelated;

import pojo.IcCard;
import pojo.ParkingRecord;
import pojo.User;
import service.IcCardService;
import service.ParkingRecordService;

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 javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/main/get_IC")
public class get_IC extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session=request.getSession();
        User user=(User)session.getAttribute("user");
        IcCardService service=new IcCardService();
        ParkingRecordService recordService=new ParkingRecordService();
        try {
            List<ParkingRecord> record=recordService.GetAllRecordbySpot_Id(user.getSpot_id());
            IcCard card=service.get_IcCardById(user.getUser_id());
            session.setAttribute("Ic-card",card);
            session.setAttribute("spot_record",record);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        request.getRequestDispatcher("/main/user/Ic-card.jsp").forward(request,response);
    }

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

    }
}



