package agilpizza.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import agilpizza.modelo.Pedido;

public class RemoverBebidaDoPedidoServlet extends HttpServlet {
	private static final long serialVersionUID = -2022384804075410287L;

	private Pedido pedido;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
		Object obj = req.getSession().getAttribute("pedido");
		if(obj == null) {
			pedido = new Pedido();
			req.getSession().setAttribute("pedido", pedido);
		} else {
			pedido = (Pedido) req.getSession().getAttribute("pedido"); 
		}
		int id;
		try{
			id = Integer.valueOf(req.getParameter("id"));
		pedido.removeBebida(id);
		}
		catch(Exception ex){
			resp.getOutputStream().println(ex.getMessage()+" "+ex.getStackTrace());
			
			return;
		}
		
		resp.sendRedirect("pedido.jsp");
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
	throws ServletException, IOException {
		doGet(req,resp);
	}
}

