package controller;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//**************************************************
//********************CONTROLLER********************
//*****METHODE doGET & doPOST d'AJOUT D'UN FILM*****
//**************************************************

@WebServlet("/AjoutFilm")
public class AjoutFilm extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public AjoutFilm() {
		super();
	}

	// ****************doGET***********************

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String JSPURL = "ajoutFilm.jsp";

		String[] natio = request.getParameterValues("natio[]");
		String[] genre = request.getParameterValues("genre[]");
		
		String titre = (String) request.getParameter("titre");
		String annee = (String) request.getParameter("annee");

		if (titre != null && natio != null && annee != null
				&& genre != null) {
			MongoControl.ajoutFilm(titre, annee, genre, natio);
		}

		RequestDispatcher rd = request.getRequestDispatcher(JSPURL);
		rd.forward(request, response);
	}

	
	// ****************doPOST***********************	
	
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
