feat: 完成用户管理接口核心CRUD功能
- 实现完整的用户创建逻辑,包含唯一性验证和密码加密 - 实现用户详情查询,安全过滤密码字段 - 实现用户信息更新,支持部分字段更新和唯一性验证 - 实现用户删除功能,包含存在性检查和日志记录 - 创建完整的API测试用例,覆盖正常和错误场景 - 更新任务进度文档,标记第10个任务为已完成 - 提升项目整体完成率至35%,中优先级任务完成率至25%
This commit is contained in:
116
backend/test_user_crud.http
Normal file
116
backend/test_user_crud.http
Normal file
@ -0,0 +1,116 @@
|
||||
### User Management API 测试
|
||||
### 基础URL
|
||||
@baseUrl = http://localhost:8080/api/v1
|
||||
|
||||
### 1. 创建用户
|
||||
POST {{baseUrl}}/users
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "testuser",
|
||||
"email": "test@example.com",
|
||||
"password": "123456"
|
||||
}
|
||||
|
||||
### 2. 创建第二个用户
|
||||
POST {{baseUrl}}/users
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "admin2",
|
||||
"email": "admin2@example.com",
|
||||
"password": "123456"
|
||||
}
|
||||
|
||||
### 3. 获取用户列表 (已有功能)
|
||||
GET {{baseUrl}}/users?page=1&page_size=10
|
||||
|
||||
### 4. 获取用户详情
|
||||
GET {{baseUrl}}/users/1
|
||||
|
||||
### 5. 更新用户信息
|
||||
PUT {{baseUrl}}/users/1
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "updateduser",
|
||||
"email": "updated@example.com",
|
||||
"avatar": "http://example.com/avatar.jpg",
|
||||
"status": 1
|
||||
}
|
||||
|
||||
### 6. 更新用户状态 (禁用)
|
||||
PUT {{baseUrl}}/users/1
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"status": 0
|
||||
}
|
||||
|
||||
### 7. 删除用户
|
||||
DELETE {{baseUrl}}/users/2
|
||||
|
||||
### 错误测试场景
|
||||
|
||||
### 8. 创建重复用户名
|
||||
POST {{baseUrl}}/users
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "testuser",
|
||||
"email": "another@example.com",
|
||||
"password": "123456"
|
||||
}
|
||||
|
||||
### 9. 创建重复邮箱
|
||||
POST {{baseUrl}}/users
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "anotheruser",
|
||||
"email": "test@example.com",
|
||||
"password": "123456"
|
||||
}
|
||||
|
||||
### 10. 获取不存在的用户
|
||||
GET {{baseUrl}}/users/999
|
||||
|
||||
### 11. 更新不存在的用户
|
||||
PUT {{baseUrl}}/users/999
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "notexist",
|
||||
"status": 1
|
||||
}
|
||||
|
||||
### 12. 删除不存在的用户
|
||||
DELETE {{baseUrl}}/users/999
|
||||
|
||||
### 13. 创建用户 - 密码太短
|
||||
POST {{baseUrl}}/users
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "shortpwd",
|
||||
"email": "short@example.com",
|
||||
"password": "123"
|
||||
}
|
||||
|
||||
### 14. 创建用户 - 邮箱格式错误
|
||||
POST {{baseUrl}}/users
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "bademail",
|
||||
"email": "not-an-email",
|
||||
"password": "123456"
|
||||
}
|
||||
|
||||
### 15. 更新用户 - 用户名改为已存在的
|
||||
PUT {{baseUrl}}/users/1
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "admin"
|
||||
}
|
||||
Reference in New Issue
Block a user