fix UserType enum mapping and implement unified API response

- Fix UserType enum mapping issue by adding fromValue method and custom type handler
- Create unified API response structure with ErrorCode constants
- Update AuthController to use standardized response format with proper error codes
- Add verification code authentication system replacing password-based auth
- Improve Swagger documentation with detailed API annotations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yahaozhang
2025-07-20 14:45:43 +08:00
parent 479f671edc
commit 36c5d7f760
16 changed files with 618 additions and 72 deletions

View File

@@ -2,6 +2,12 @@ package com.yundage.chat.controller;
import com.yundage.chat.entity.User;
import com.yundage.chat.mapper.UserMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -10,22 +16,36 @@ import java.util.List;
@RestController
@RequestMapping("/api/users")
@Tag(name = "用户管理", description = "用户CRUD操作接口")
@SecurityRequirement(name = "Bearer Authentication")
public class UserController {
@Autowired
private UserMapper userMapper;
@GetMapping
@Operation(summary = "获取所有用户", description = "获取系统中所有用户列表")
@ApiResponse(responseCode = "200", description = "成功获取用户列表")
public List<User> getAllUsers() {
return userMapper.selectAll();
}
@GetMapping("/{id}")
public User getUserById(@PathVariable Long id) {
@Operation(summary = "根据ID获取用户", description = "根据用户ID获取用户信息")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "成功获取用户信息"),
@ApiResponse(responseCode = "404", description = "用户不存在")
})
public User getUserById(@Parameter(description = "用户ID") @PathVariable Long id) {
return userMapper.selectOneById(id);
}
@PostMapping
@Operation(summary = "创建用户", description = "创建新的用户")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "用户创建成功"),
@ApiResponse(responseCode = "400", description = "请求参数错误")
})
public User createUser(@RequestBody User user) {
user.setCreatedAt(LocalDateTime.now());
user.setUpdatedAt(LocalDateTime.now());
@@ -34,7 +54,13 @@ public class UserController {
}
@PutMapping("/{id}")
public User updateUser(@PathVariable Long id, @RequestBody User user) {
@Operation(summary = "更新用户", description = "更新指定用户的信息")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "用户更新成功"),
@ApiResponse(responseCode = "404", description = "用户不存在"),
@ApiResponse(responseCode = "400", description = "请求参数错误")
})
public User updateUser(@Parameter(description = "用户ID") @PathVariable Long id, @RequestBody User user) {
user.setId(id);
user.setUpdatedAt(LocalDateTime.now());
userMapper.update(user);
@@ -42,7 +68,12 @@ public class UserController {
}
@DeleteMapping("/{id}")
public void deleteUser(@PathVariable Long id) {
@Operation(summary = "删除用户", description = "根据ID删除用户")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "用户删除成功"),
@ApiResponse(responseCode = "404", description = "用户不存在")
})
public void deleteUser(@Parameter(description = "用户ID") @PathVariable Long id) {
userMapper.deleteById(id);
}
}