package com.suvalue.example.suvaluebootdemoapi.controller;



//import com.suvalue.boot.common.utils.RedisUtil;
import com.suvalue.boot.common.utils.JWTUtil;
import com.suvalue.example.suvaluebootdemoapi.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "用户API",produces="produces",consumes="consumes",protocols="protocols")
@RequestMapping("/user")
@RestController
public class UserController {

//    @Autowired
//    private UserService userServiceImpl;

    @GetMapping("index")
    public Object find() {
//        return userServiceImpl.findAll();
        return 1;
    }

    @ApiOperation("设置redis缓存")
    @PostMapping("redis/set")
    @ApiImplicitParams({@ApiImplicitParam(value = "value",
            name="key",
            defaultValue="defaultValue",
            required=true,
            allowableValues="1,2,3")})
    public Object set(String key, String value){
//        RedisUtil.set(key,value,10);
        return 1;
    }

    @PostMapping("login")
    public Object login(String logname,String password){
        return JWTUtil.createTokenWithAudience(password, logname,logname);
    }

    @PostMapping("check")
    public Object check(String token, String password){
        if(JWTUtil.verifier(token, password)){
            return JWTUtil.getAudience(token);
        }
        else{
            return false;
        }
    }
}
