package com.nokia.hb.controller;

import com.nokia.common.R;
import com.nokia.hb.pojo.dto.LoginDto;
import com.nokia.hb.pojo.vo.LoginVo;
import com.nokia.hb.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

@Tag(name = "授权")
@RestController
public class AuthController {
    private final AuthService authService;

    public AuthController(AuthService authService) {
        this.authService = authService;
    }

    /**
     * 用户登录
     */
    @Operation(summary = "登录")
    @PostMapping("/api/userLogin")
    public R<LoginVo> userLogin(@Valid @RequestBody LoginDto dto, HttpSession session) {
        return authService.userLogin(dto, session);
    }

    /**
     * 退出登录
     */
    @Operation(summary = "退出登录")
    @PostMapping("/api/logout")
    public R<Object> logout(HttpSession session) {
        return authService.logout(session);
    }
}
