package me.zhengjie.modules.front.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.annotation.Log;
import me.zhengjie.annotation.rest.AnonymousPostMapping;
import me.zhengjie.modules.front.domain.dto.LoginVo;
import me.zhengjie.modules.front.service.WeChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@Slf4j
@RestController("WeChatFrontController")
@RequestMapping("api/front/wechat")
@Api(tags = "微信：开放平台")
public class WeChatController {

    @Autowired private WeChatService weChatService;

    /**
     * 微信登录小程序授权登录
     */
    @Log("用户授权登录")
    @ApiOperation(value = "微信登录小程序授权登录")
    @AnonymousPostMapping(value = "/authorize/login")
    public ResponseEntity<LoginVo> authorizeLogin(@RequestParam String code, HttpServletRequest request){
        LoginVo loginVo = weChatService.authorizeLogin(code, request);
        return new ResponseEntity<>(loginVo, HttpStatus.OK);
    }
}



