-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: finish task #6
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,329 @@ | ||||||
AAAxianyu的API文档 | ||||||
1. 用户管理 | ||||||
(1)注册用户 | ||||||
请求方式: POST | ||||||
URL: /register | ||||||
功能: 创建一个新的用户账户。 | ||||||
请求参数: | ||||||
参数 类型 描述 | ||||||
username string 用户名 | ||||||
password string 密码 | ||||||
请求示例: | ||||||
Json | ||||||
{ | ||||||
"username": "testuser", | ||||||
"password": "securepassword" | ||||||
} | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"message": "User registered successfully!" | ||||||
} | ||||||
(2)登录用户 | ||||||
请求方式: POST | ||||||
URL: /login | ||||||
功能: 验证用户的用户名和密码。 | ||||||
请求参数: | ||||||
参数 类型 描述 | ||||||
username string 用户名 | ||||||
password string 密码 | ||||||
|
||||||
|
||||||
|
||||||
|
||||||
请求示例: | ||||||
Json | ||||||
{ | ||||||
"username": "testuser", | ||||||
"password": "securepassword" | ||||||
} | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"message": "Login successful!" | ||||||
} | ||||||
2. 问题管理 | ||||||
(1)获取问题列表 | ||||||
请求方式: GET | ||||||
URL: /api/question | ||||||
功能: 获取所有问题的列表。 | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "What is the meaning of life?", | ||||||
"best_answer": null | ||||||
} | ||||||
(2)创建问题 | ||||||
请求方式: POST | ||||||
URL: /api/question | ||||||
功能: 创建一个新的问题。 | ||||||
请求参数: | ||||||
参数 类型 描述 | ||||||
content string 问题内容 | ||||||
请求示例: | ||||||
Json | ||||||
{ | ||||||
"content": "What is the meaning of life?" | ||||||
} | ||||||
|
||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "What is the meaning of life?", | ||||||
"best_answer": null | ||||||
} | ||||||
(3)获取指定问题 | ||||||
请求方式: GET | ||||||
URL: /api/question/:id | ||||||
功能: 获取指定ID的问题详情。 | ||||||
路径参数: | ||||||
参数 类型 描述 | ||||||
id integer 问题ID | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "What is the meaning of life?", | ||||||
"best_answer": null | ||||||
} | ||||||
(4)修改指定问题 | ||||||
请求方式: PUT | ||||||
URL: /api/question/:id | ||||||
功能: 修改指定ID的问题内容。 | ||||||
路径参数: | ||||||
参数 类型 描述 | ||||||
id integer 问题ID | ||||||
请求参数: | ||||||
参数 类型 描述 | ||||||
content string 新问题内容 | ||||||
|
||||||
|
||||||
|
||||||
|
||||||
请求示例: | ||||||
Json | ||||||
{ | ||||||
"content": "What is the purpose of life?" | ||||||
} | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "What is the purpose of life?", | ||||||
"best_answer": null | ||||||
} | ||||||
(5)删除指定问题 | ||||||
请求方式: DELETE | ||||||
URL: /api/question/:id | ||||||
功能: 删除指定ID的问题。 | ||||||
路径参数: | ||||||
参数 类型 描述 | ||||||
id integer 问题ID | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"message": "Question deleted successfully!" | ||||||
} | ||||||
3. 答案管理 | ||||||
(1)创建答案 | ||||||
请求方式: POST | ||||||
URL: /api/question/:id/answer | ||||||
功能: 对指定问题创建一个新的答案。 | ||||||
路径参数: | ||||||
参数 类型 描述 | ||||||
id integer 问题ID | ||||||
|
||||||
|
||||||
|
||||||
请求参数: | ||||||
参数 类型 描述 | ||||||
content string 答案内容 | ||||||
请求示例: | ||||||
Json | ||||||
{ | ||||||
"content": "The meaning of life is to find your purpose." | ||||||
} | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "The meaning of life is to find your purpose.", | ||||||
"question_id": 1, | ||||||
"votes": 0 | ||||||
} | ||||||
(2)获取指定问题的答案列表 | ||||||
请求方式: GET | ||||||
URL: /api/question/:id/answer | ||||||
功能: 获取指定问题的所有答案。 | ||||||
路径参数: | ||||||
参数 类型 描述 | ||||||
id integer 问题ID | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "The meaning of life is to find your purpose.", | ||||||
"question_id": 1, | ||||||
"votes": 0 | ||||||
} | ||||||
(3)获取指定答案 | ||||||
请求方式: GET | ||||||
URL: /api/question/:id/answer/:answerID | ||||||
功能: 获取指定问题指定ID的答案详情。 | ||||||
|
||||||
路径参数: | ||||||
参数 类型 描述 | ||||||
id integer 问题ID | ||||||
answerID integer 答案ID | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "The meaning of life is to find your purpose.", | ||||||
"question_id": 1, | ||||||
"votes": 0 | ||||||
} | ||||||
(4)修改指定答案 | ||||||
请求方式: PUT | ||||||
URL: /api/question/:id/answer/:answerID | ||||||
功能: 修改指定问题指定ID的答案内容。 | ||||||
路径参数: | ||||||
参数 类型 描述 | ||||||
id integer 问题ID | ||||||
answerID integer 答案ID | ||||||
请求参数: | ||||||
参数 类型 描述 | ||||||
content string 新答案内容 | ||||||
请求示例: | ||||||
Json | ||||||
{ | ||||||
"content": "Life's purpose is subjective." | ||||||
} | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "Life's purpose is subjective.", | ||||||
"question_id": 1, | ||||||
"votes": 0} | ||||||
(5)删除指定答案 | ||||||
请求方式: DELETE | ||||||
URL: /api/question/:id/answer/:answerID | ||||||
功能: 删除指定问题指定ID的答案。 | ||||||
路径参数: | ||||||
参数 类型 描述 | ||||||
id integer 问题ID | ||||||
answerID integer 答案ID | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"message": "Answer deleted successfully!" | ||||||
} | ||||||
4. 最佳答案管理 | ||||||
(1)选择最佳答案 | ||||||
请求方式: PUT | ||||||
URL: /api/question/:id/best-answer | ||||||
功能: 为指定问题选择最佳答案。 | ||||||
路径参数: | ||||||
参数 类型 描述 | ||||||
id integer 问题ID | ||||||
请求参数: | ||||||
参数 类型 描述 | ||||||
best_answer_id integer 答案ID | ||||||
请求示例: | ||||||
Json | ||||||
{ | ||||||
"best_answer_id": 1 | ||||||
} | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{"message": "Best answer selected successfully!"} | ||||||
|
||||||
(2)获取问题的最佳答案 | ||||||
请求方式: GET | ||||||
URL: /api/question/:id/best-answer | ||||||
功能: 获取指定问题的最佳答案。 | ||||||
路径参数: | ||||||
参数 类型 描述 | ||||||
id integer 问题ID | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "Life's purpose is subjective.", | ||||||
"question_id": 1, | ||||||
"votes": 0 | ||||||
} | ||||||
5. 关键词检索 | ||||||
(1)检索关键词相关的问题 | ||||||
请求方式: GET | ||||||
URL: /api/search/question | ||||||
功能: 搜索包含特定关键词的问题。 | ||||||
查询参数: | ||||||
参数 类型 描述 | ||||||
keyword string 搜索关键词 | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "What is the purpose of life?", | ||||||
"best_answer": null | ||||||
} | ||||||
(2)检索关键词相关的答案 | ||||||
请求方式: GET | ||||||
URL: /api/search/answer | ||||||
功能: 搜索包含特定关键词的答案。 | ||||||
查询参数: | ||||||
参数 类型 描述 | ||||||
keyword string 搜索关键词 | ||||||
响应: | ||||||
• 状态码: 200 (OK) | ||||||
• 响应数据: | ||||||
Json | ||||||
{ | ||||||
"id": 1, | ||||||
"content": "Life's purpose is subjective.", | ||||||
"question_id": 1, | ||||||
"votes": 0 | ||||||
} | ||||||
|
||||||
|
||||||
总结:这段代码实现了(1)用户的注册和登陆 | ||||||
(2)问题的创建,搜索,更新,删除 | ||||||
(3)答案的创建,搜错,更新,删除 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the typo in "搜错" to "搜索" In line 325, the term "搜错" (search error) should be corrected to "搜索" (search) to accurately describe the functionality related to answers. Apply this diff to fix the typo: - (3)答案的创建,搜错,更新,删除
+ (3)答案的创建,搜索,更新,删除 📝 Committable suggestion
Suggested change
|
||||||
(4)最佳答案的选择和获取 | ||||||
(5)通过关键词搜索相关的问题和答案 | ||||||
(6)违规词过滤,在检测到违规词时自动删去该词 | ||||||
(7)一个简单的前端欢迎页面(也许算?) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module github.com/AAAxianyu/website | ||
|
||
go 1.23.0 | ||
|
||
require ( | ||
github.com/bytedance/sonic v1.11.6 // indirect | ||
github.com/bytedance/sonic/loader v0.1.1 // indirect | ||
github.com/cloudwego/base64x v0.1.4 // indirect | ||
github.com/cloudwego/iasm v0.2.0 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/gin-gonic/gin v1.10.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.20.0 // indirect | ||
github.com/go-sql-driver/mysql v1.7.0 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/jinzhu/inflection v1.0.0 // indirect | ||
github.com/jinzhu/now v1.1.5 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect | ||
github.com/leodido/go-urn v1.4.0 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.12 // indirect | ||
golang.org/x/arch v0.8.0 // indirect | ||
golang.org/x/crypto v0.23.0 // indirect | ||
golang.org/x/net v0.25.0 // indirect | ||
golang.org/x/sys v0.20.0 // indirect | ||
golang.org/x/text v0.15.0 // indirect | ||
google.golang.org/protobuf v1.34.1 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
gorm.io/driver/mysql v1.5.7 // indirect | ||
gorm.io/gorm v1.25.12 // indirect | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix JSON formatting in the response example
In line 232, the closing brace
}
is on the same line as the last property, which may cause confusion and inconsistency with other examples. It should be placed on a new line for better readability and consistent formatting.Apply this diff to fix the formatting:
📝 Committable suggestion