package com.yonyou.microservice.gate.admin.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
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.bind.annotation.RestController;

import com.yonyou.cloud.common.controller.BaseController;
import com.yonyou.microservice.gate.admin.biz.UserBiz;
import com.yonyou.microservice.gate.admin.entity.User;
import com.yonyou.microservice.gate.admin.rpc.service.PermissionService;
import com.yonyou.microservice.gate.admin.vo.FrontUser;
import com.yonyou.microservice.gate.admin.vo.MenuTree;

/**
 * ${DESCRIPTION}
 *
 * @author joy
 * @create 2017-06-08 11:51
 */
@RestController
@RequestMapping("user")
public class UserController extends BaseController<UserBiz, User> {
	@Autowired
	private PermissionService permissionService;

	@RequestMapping(value = "/front/info", method = RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<?> getUserInfo(String token) throws Exception {
		FrontUser userInfo = permissionService.getUserInfo(token);
		if (userInfo == null) {
			return ResponseEntity.status(401).body(false);
		} else {
			return ResponseEntity.ok(userInfo);
		}
	}

	@RequestMapping(value = "/front/menus", method = RequestMethod.GET)
	public @ResponseBody List<MenuTree> getMenusByUsername(String token) throws Exception {
		return permissionService.getMenusByUsername(token);
	}
}
