fix
This commit is contained in:
@@ -4,6 +4,7 @@ import com.tailbet.model.dto.LoginDTO;
|
||||
import com.tailbet.model.dto.RegisterDTO;
|
||||
import com.tailbet.model.dto.UpdateUserDTO;
|
||||
import com.tailbet.model.vo.LoginUserVo;
|
||||
import com.tailbet.model.vo.LoginVo;
|
||||
import com.tailbet.model.vo.R;
|
||||
import com.tailbet.model.vo.UserContext;
|
||||
import com.tailbet.service.IUserService;
|
||||
@@ -24,10 +25,10 @@ public class UserController {
|
||||
* 注册
|
||||
*/
|
||||
@PostMapping("/register")
|
||||
public R<?> register(@RequestBody RegisterDTO dto) {
|
||||
public R<Void> register(@RequestBody RegisterDTO dto) {
|
||||
try {
|
||||
userService.register(dto.getUsername(), dto.getPassword());
|
||||
return R.ok("注册成功");
|
||||
return R.ok();
|
||||
} catch (RuntimeException e) {
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
@@ -37,10 +38,12 @@ public class UserController {
|
||||
* 登录
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public R<?> login(@RequestBody LoginDTO dto) {
|
||||
public R<LoginVo> login(@RequestBody LoginDTO dto) {
|
||||
try {
|
||||
String token = userService.login(dto.getUsername(), dto.getPassword());
|
||||
return R.ok("登录成功", java.util.Map.of("token", token));
|
||||
LoginVo vo = new LoginVo();
|
||||
vo.setToken(token);
|
||||
return R.ok("登录成功", vo);
|
||||
} catch (RuntimeException e) {
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
@@ -50,7 +53,7 @@ public class UserController {
|
||||
* 获取当前用户信息
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
public R<?> getInfo() {
|
||||
public R<LoginUserVo> getInfo() {
|
||||
LoginUserVo user = UserContext.getUser();
|
||||
return R.ok(user);
|
||||
}
|
||||
@@ -59,11 +62,11 @@ public class UserController {
|
||||
* 更新用户信息
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public R<?> update(@RequestBody UpdateUserDTO dto) {
|
||||
public R<Void> update(@RequestBody UpdateUserDTO dto) {
|
||||
try {
|
||||
Long userId = UserContext.getUserId();
|
||||
userService.updateUserInfo(userId, dto);
|
||||
return R.ok("更新成功");
|
||||
return R.ok();
|
||||
} catch (RuntimeException e) {
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
@@ -73,8 +76,8 @@ public class UserController {
|
||||
* 退出登录
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
public R<?> logout() {
|
||||
public R<Void> logout() {
|
||||
// 可以在这里清理Redis中的token
|
||||
return R.ok("退出成功");
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user