package com.uas.account.controller;

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.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.uas.account.entity.Setting;
import com.uas.account.service.SettingService;
import com.uas.account.web.BaseController;

@Controller
public class SettingController extends BaseController {

	@Autowired
	private SettingService settingService;

	/**
	 * @return
	 */
	@RequestMapping(value = "/console/setting", method = RequestMethod.GET)
	public ModelAndView getPage(ModelMap model) {
		return new ModelAndView("console/setting", success(settingService.findAll()));
	}

	/**
	 * 查找全部
	 * 
	 */
	@RequestMapping(value = "/api/setting/list", method = RequestMethod.GET)
	@ResponseBody
	public ModelMap findAll() {
		return success(settingService.findAll());
	}

	/**
	 * 查找
	 * 
	 * @param key
	 */
	@RequestMapping(value = "/api/setting", method = RequestMethod.GET)
	@ResponseBody
	public ModelMap findOne(String key) {
		return success(settingService.findOne(key));
	}

	/**
	 * 更新
	 * 
	 * @param app
	 */
	@RequestMapping(value = "/api/setting", method = RequestMethod.POST)
	@ResponseBody
	public ModelMap save(Setting setting) {
		settingService.save(setting);
		return success();
	}

	/**
	 * 删除
	 * 
	 * @param uid
	 */
	@RequestMapping(value = "/api/setting", method = RequestMethod.DELETE)
	@ResponseBody
	public ModelMap delete(String key) {
		settingService.delete(key);
		return success();
	}

}
