package com.qmth.exam.reserve.controller.admin;

import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.exam.reserve.bean.login.LoginReq;
import com.qmth.exam.reserve.bean.login.LoginUser;
import com.qmth.exam.reserve.controller.BaseController;
import com.qmth.exam.reserve.service.AuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "用户登录相关接口")
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/user")
@Aac(strict = false, auth = false)
public class UserLoginController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(UserLoginController.class);

    @Autowired
    private AuthService authService;

    @ApiOperation(value = "用户登录（账号）")
    @PostMapping(value = "/login")
    public LoginUser login(@RequestBody LoginReq req) {
        return authService.userLogin(req);
    }

    @Aac(strict = false, auth = true)
    @ApiOperation(value = "用户登出")
    @PostMapping(value = "/logout")
    public void logout() {
        authService.logout(curLoginUser());
    }

}
