package com.ihooyah.modules.system.rest;

import com.ihooyah.auth.util.JwtTokenUtil;
import com.ihooyah.common.msg.ObjectRespInfo;
import com.ihooyah.common.util.jwt.JWTInfo;
import com.ihooyah.modules.system.dto.UserDto;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 描述
 *
 * @author fatiaojie
 * @date 2020/4/3 11:31
 */
@RestController
@RequestMapping("open")
@RefreshScope
public class OpenController {

    @Value("${test.content}")
    private String content;


    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation(value = "查询列表测试", notes = "说明文字", httpMethod = "GET")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public ObjectRespInfo list(){
        return ObjectRespInfo.mobiSuccess(content);
    }

    @RequestMapping(value = "token",method = RequestMethod.POST)
    public ObjectRespInfo token(@Valid UserDto userDto) throws Exception {
        return ObjectRespInfo.mobiSuccess(jwtTokenUtil.generateToken(new JWTInfo(userDto.getAccount(), userDto.getId().toString(), userDto.getName())));
    }
}
