package controller.rest;

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

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import bean.AppVariables;
import bean.filters.ContiFilterBean;
import common.controller.BaseController;
import dao.ContiDAO;

@Controller
@RequestMapping("conti")
public class ContoRestController extends BaseController {
	
	@Autowired
	ContiDAO contiDao;
	
	@RequestMapping("list")
	private ResponseEntity<Object> list(@RequestBody ContiFilterBean filterBean, HttpServletRequest reques) {
		try {
			setRequest(reques);
			if (getUserData()==null)
				return new ResponseEntity(null, HttpStatus.UNAUTHORIZED);
			
			AppVariables appVariables = (AppVariables) getSessionAttribute("appVariables");
			return new ResponseEntity<Object>(contiDao.list(filterBean, appVariables), HttpStatus.OK);
		} catch(Exception ex) {
			ex.printStackTrace();
			Logger.getRootLogger().error(ex);
			return new ResponseEntity<Object>(null, HttpStatus.INTERNAL_SERVER_ERROR);
		}
	}
}

