package com.atguigu.ssyx.user.controller;

import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.user.User;
import com.atguigu.ssyx.user.service.LoginWxService;
import com.atguigu.ssyx.user.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: WeixinApiController
 * Package: com.atguigu.ssyx.user.controller
 *
 * @author yovinchen
 * @Create 2023/9/22 16:23
 */
@RestController
@RequestMapping("api/user/weixin")
public class WeixinApiController {

    @Autowired
    private LoginWxService loginWxService;

    @Autowired
    private UserService userService;

    //用户微信授权登录
    @ApiOperation(value = "微信登录获取openid(小程序)")
    @GetMapping("wxLogin/{code}")
    public Result loginWx(@PathVariable String code) {
        return Result.ok(loginWxService.loginWx(code));
    }

    @PostMapping("auth/updateUser")
    @ApiOperation(value = "更新用户昵称与头像")
    public Result updateUser(@RequestBody User user) {
        userService.updateUser(user);
        return Result.ok(null);
    }
}
