package com.ruoyi.wx.web.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.WxUser;
import com.ruoyi.framework.web.service.WxLoginService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 登录服务
 */
@Tag(name = "登录服务")
@RestController
@RequestMapping("/wx")
@Slf4j
public class WxLoginController {
    @Autowired
    private WxLoginService wxLoginService;

    @ApiOperation("微信小程序登录")
    @GetMapping("/login")
    public AjaxResult minLogin(String code) {
        // 生成令牌
        return wxLoginService.minLogin(code);
    }

    @ApiOperation("微信小程序更新用户信息")
    @PostMapping("/update/user")
    public AjaxResult updateUser(@RequestBody WxUser user) {
        // 生成令牌
        String result = wxLoginService.updateUser(user);
        return AjaxResult.success(result);
    }

    @ApiOperation("查询用户信息")
    @GetMapping("/find/user/{wxOpenId}")
    public AjaxResult findUser(@PathVariable("wxOpenId") String openId) {
        // 生成令牌
        WxUser result = wxLoginService.findUser(openId);
        return AjaxResult.success(result);
    }
}
