package com.qy.worksheetsystem.controller;

import com.qy.worksheetsystem.model.MessageResult;
import com.qy.worksheetsystem.model.MessageResultV2;
import com.qy.worksheetsystem.service.FeishuAuthorizeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

import java.util.Map;

/**
 * @BelongsProject: workSheetSystem
 * @BelongsPackage: com.qy.worksheetsystem.controller
 * @Author: lhbj
 * @CreateTime: 2024-11-26  20:11
 * @Description: TODO
 * @Version: 1.0
 */
@Api(value = "飞书" ,tags="飞书")    //将类标记为 Swagger 资源。
@RestController
@RequestMapping("/timeSheet")
public class AuthorizeControtor {

    @Autowired
    private FeishuAuthorizeService feishuAuthorizeService;

    @ApiOperation(value = "构造网页授权链接", notes = "构造网页授权链接")
    @RequestMapping(value ="/getRedirectUri",method = RequestMethod.GET)
    public MessageResult authorize(@RequestParam("redirect_uri") String redirect_uri) {
        return MessageResult.success().add("url", feishuAuthorizeService.authorize(redirect_uri, "RANDOMSTRING"));
    }
    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    @RequestMapping(value ="/getUserInfo",method = RequestMethod.GET)
    public MessageResult getUserInfo(@RequestParam("redirect_uri") String redirect_uri,@RequestParam("code") String code) {
        Map<String,String> map = feishuAuthorizeService.getUserInfo(redirect_uri,code);
        MessageResultV2 messageResult= MessageResultV2.success();
        messageResult.setData(map);
        return messageResult;
    }


}
