package com.house365.web;

import com.house365.beans.vo.Department;
import com.house365.common.searchBeans.CommonSearchResponse;
import com.house365.common.searchBeans.QueryParams;
import com.house365.service.interfaces.DepartmentClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Date: 2017/1/9</p>
 *
 * @author XN
 * @version 1.0
 */
@Controller
@EnableAutoConfiguration
@RequestMapping("department")
public class DepartmentController {
    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private DepartmentClient departmentClient;

    @RequestMapping(value = "list", method = RequestMethod.GET)
    public String list(HttpServletRequest request, Model model) {
        QueryParams queryParams = QueryParams.getQueryParams(request, "id", "desc");
        CommonSearchResponse<Department> result = departmentClient.list(queryParams);
        model.addAttribute("list", result.getObjectList());
        model.addAttribute("pager", result.getPaging());
        return "config/department";
    }
}
