package com.ads.business.controller;

import com.ads.business.service.LoginService;
import com.ads.business.service.data.GetLoginInData;
import com.ads.business.service.data.GetLoginOutData;
import com.ads.common.data.JsonResult;
import com.ads.common.util.UtilConst;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @Return
 * @Author hou
 * @Date 2021/10/21 16:14
 * @Destription
 */

@RestController
@RequestMapping("/")
@Api(tags = "登录模块")
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("login")
    @ApiOperation("登录")
    private JsonResult<GetLoginOutData> login(@RequestBody @Valid GetLoginInData inData) {
        return loginService.login(inData);
    }

    @ApiOperation("登出")
    @GetMapping("logout")
    public JsonResult logout(HttpServletRequest request) {
        String token = request.getHeader(UtilConst.LOGIN_TOKEN);
        return loginService.logout(token);
    }

    @ApiOperation("重置密码")
    @PostMapping("reset")
    public JsonResult resetPassword(@RequestBody @Valid GetLoginInData inData) {
        return loginService.resetPassword(inData);
    }

    @ApiOperation("修改密码")
    @PostMapping("update")
    public JsonResult updatePassword(@RequestBody @Valid GetLoginInData inData) {
        return loginService.updatePassword(inData);
    }
}
