package com.ruoyi.web.work.api;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.work.api.config.BaseController;
import com.ruoyi.web.work.domain.dto.AuthenticationDto;
import com.ruoyi.web.work.domain.dto.LoginDto;
import com.ruoyi.web.work.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app/user")
public class Api_UserController extends BaseController {

    @Autowired
    IUserService userService;

    @Autowired
    private Environment env;

    @PostMapping("/login")
    public AjaxResult login(@Validated @RequestBody LoginDto dto) {
        return userService.login(dto);
    }

    @PostMapping("/authentication")
    public AjaxResult authentication(@Validated @RequestBody AuthenticationDto dto) {
        return userService.authentication(dto);
    }

    @GetMapping("/info")
    public AjaxResult info() {
        return AjaxResult.success(userService.getById(getUser().getId()));
    }

}

