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;
import agilpizza.modelo.Pizza;

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

	private Pizza pizza;
	private Pedido pedido;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
		pizza = (Pizza) req.getSession().getAttribute("pizza");
		Object obj = req.getSession().getAttribute("pedido");
		if(obj == null) {
			pedido = new Pedido();
			req.getSession().setAttribute("pedido", pedido);
		} else {
			pedido = (Pedido) req.getSession().getAttribute("pedido"); 
		}
		if(pizza != null)
			pedido.addPizza(pizza);
		
		resp.sendRedirect("pedido.jsp");
	}

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

