package cn.feast.coding.controller.generator;


import cn.feast.coding.controller.BaseController;
import cn.feast.coding.model.generator.Colunm;
import cn.feast.coding.service.generator.ColunmService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/colunm")
public class ColunmController extends BaseController {
    @Autowired
    private ColunmService colunmService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list(Colunm colunm, Integer curPage, Integer pageSize, ModelMap model, HttpServletRequest request) {
        PageInfo<Colunm> pageInfo = colunmService.queryPage(colunm, pageNum(curPage), pageSize(request, pageSize));
        model.put("pages", pageInfo);
        model.put("colunm", colunm);
        return "colunm/colunm_list";
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String add(Colunm colunm, ModelMap model) {
        colunmService.save(colunm);
        model.put("flag", 1);
        return "colunm/colunm_add";
    }


    @RequestMapping(value = "/update", method = RequestMethod.GET)
    public String update(Colunm colunm, ModelMap model) {
        colunm = colunmService.queryById(colunm.getId());
        model.put("colunm", colunm);
        return "colunm/colunm_edit";
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(Colunm colunm, HttpServletRequest request, ModelMap model) {
        colunmService.update(colunm);
        model.put("flag", 1);
        return "colunm/colunm_edit";
    }

    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    @ResponseBody
    public void delete(Colunm colunm) {
        colunmService.deleteById(colunm.getId());
    }
}
