package com.example.demo.controller;

import com.example.demo.dto.request.AddUserRequest;
import com.example.demo.dto.request.UserRequest;
import com.example.demo.dto.response.BaseResponse;
import com.example.demo.dto.response.UserDto;
import com.example.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = {"用户接口"})
@RestController
@RequestMapping("/wx/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户登录,提交用户名密码,用户名不存在返回code 110，密码错误返回111，成功返回200")
    @PostMapping("/login")
    public BaseResponse<UserDto> login(@RequestBody UserRequest req) {
        return userService.login(req);
    }

    @ApiOperation(value = "用户注册，提交用户名 密码 呢称，用户名已存在返回code 110，注册成功返回200")
    @PostMapping("/register")
    public BaseResponse<UserDto> login(@RequestBody AddUserRequest req) {
        return userService.register(req);
    }

}
