问答文档
欣略
1. 创建问题
Description
用户创建问题
Method and URL Structure
| Method |
Resource URL |
| POST |
/qa/questions/ |
Request Parameters
| Name |
Description |
Required |
Default |
| node |
所属分类资源的pk/id |
No |
|
| title |
问题题目 |
Yes |
|
| content |
问题内容 |
NO |
|
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
Request
{ "node":1, "title":"今天", "content":"今天怎么样?",}
cURL Example
curl -X POST -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' \-d '{"node":1, "title":"今天", "content":"天怎么样?"}' \http://127.0.0.1:8000/qa/questions/
JSON Response
{ "pk": 5, "author": "15670502158", "node": 1, "title": "今天", "content": "今天怎么样?", "click": 0, "reply_count": 0, "create_time": "2016-04-14T02:43:29.501034Z", "last_replied": "2016-04-14T02:43:29.501073Z", "profile": { "pk": 2, "owner": "18516271364", "nickname": "小明", "avatar_url": "http://example.com/n.png", "website": "http://www.example.com", }}
2. 修改问题
Description
用户修改问题信息
Method and URL Structure
| Method |
Resource URL |
| PUT |
/qa/questions/${pk}/ |
Request Parameters
| Name |
Description |
Required |
Default |
| node |
所属分类资源的pk/id |
No |
|
| title |
问题题目 |
Yes |
|
| content |
问题内容 |
NO |
|
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
Request
{ "node":2, "title":"我好", "content":"今天过的很happy",}
cURL Example
curl -X PUT -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' \-d '{"title":"我好","content":"今天很快乐?"}' \http://127.0.0.1:8000/qa/questions/1/
JSON Response
{ "pk": 1, "author": "teacher", "node": 2, "title": "我好", "content": "今天很快乐?", "click": 0, "reply_count": 0, "create_time": "2016-04-14T02:19:48.935635Z", "last_replied": "2016-04-14T02:19:48.935678Z", "profile": { "pk": 2, "owner": "18516271364", "nickname": "小明", "avatar_url": "http://wwww.example/image/1.png", "website": "http://www.exmple.com/" }}
3. 删除问题
Description
用户删除问题信息
Method and URL Structure
| Method |
Resource URL |
| DELETE |
/qa/questions/${pk}/ |
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X DELETE -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/qa/questions/1/
JSON Response
| Name |
Description |
Default |
| detail |
失败原因 |
Not found |
| status |
成功 |
204 |
4. 查看具体问题
Description
用户查询某一问题信息
Method and URL Structure
| Method |
Resource URL |
| GET |
/qa/questions/${pk}/ |
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X GET -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/qa/questions/1/
JSON Response
{ "pk": 1, "author": "15670502158", "node": null, "title": "数学问题1", "content": "1+ 1=?\r\n从哲学的角度来说,1+1=?,然后从数学的角度又是多少", "click": 5, "reply_count": 2, "create_time": "2016-05-31T07:43:36.002513Z", "last_replied": "2016-06-03T08:24:42.245772Z", "profile": { "pk": 2, "owner": "18516271364", "nickname": "小明", "avatar_url": "http://www.example.cm/3.png", "website": "http://www.example.com/", }}
5. 获取所有问题
Description
用户查看所有问题信息
Method and URL Structure
| Method |
Resource URL |
| GET |
/qa/questions/ |
Request Parameters
默认分页取数据库中最新的10条数据
| Name |
Description |
Required |
Default |
| page |
page Number |
Yes |
1 |
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X GET -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/qa/questions/?page=1
JSON Response
{ "count": 4, "next": null, "previous": null, "results": [ { "pk": 5, "author": "teacher", "node": 1, "title": "今天", "content": "今天怎么样?", "click": 0, "reply_count": 0, "create_time": "2016-04-14T02:43:29.501034Z", "last_replied": "2016-04-14T02:43:29.501073Z", "profile": { "pk": 3, "username": "15670502158", "nickname": "小花", "avatar_url": "http://pic.example.com/img/3.png", "website": "http://www.example.com/", } }, { "pk": 4, "author": "teacher", "node": null, "title": "今天", "content": "今天怎么样?", "click": 0, "reply_count": 0, "create_time": "2016-04-14T02:43:13.574751Z", "last_replied": "2016-04-14T02:43:13.574794Z", "profile": { "pk": 2, "owner": "18516271364", "nickname": "小明", "avatar_url": "http://pic3.example.com/3.png", "website": "http://www.example.com", }, }, ...... ]}
6. 根据关键字搜索和排序问题
Description
用户根据关键字搜索和排序相关问题
Method and URL Structure
| Method |
Resource URL |
| GET |
/qa/questions/ |
Request Parameters
默认分页取数据库中最新的10条数据
| Name |
Description |
Required |
Default |
| page |
page Number |
Yes |
1 |
| search |
搜索字段 |
No |
|
| ordering |
排序字段 |
No |
|
- search,搜索字段,模糊搜索,根据问题标题、问题作者、问题内容
- ordering,排序字段,问题点击数(click)、问题回复数(reply_count)、
- ordering=click,代表从小到大,ordering=-click,代表从大到小
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X GET -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/qa/questions/?search=辰&ordering=-click&page=1
JSON Response
{ "count": 2, "next": null, "previous": null, "results": [ { "pk": 2, "author": "15201052252", "node": null, "title": "今天", "content": "请以今天为题目写一篇不少于500字的作文", "click": 4, "reply_count": 0, "create_time": "2016-05-31T07:49:58.702588Z", "last_replied": "2016-05-31T07:49:58.702627Z", "profile": { "pk": 2, "owner": "18516271364", "nickname": "小明", "avatar_url": "http://www.example.com/3.png", "website": "http://example.com", }, }, { "pk": 3, "author": "15201052252", "node": null, "title": "明天", "content": "明天怎么样?", "click": 0, "reply_count": 0, "create_time": "2016-06-03T07:52:34.402926Z", "last_replied": "2016-06-03T07:52:34.402965Z", "profile": { "pk": 1, "owner": "18516271364", "nickname": "小明", "avatar_url": "http://example.com/3.png", "website": "http://www.example.com/" } } ]}
1. 给问题添加答案
Description
用户给问题添加答案
Method and URL Structure
| Method |
Resource URL |
| POST |
/qa/answers/ |
Request Parameters
| Name |
Description |
Required |
Default |
| question |
问题资源的pk/id |
Yes |
|
| content |
答案内容 |
NO |
|
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
Request
{ "question":1, "content":"今天怎么样?",}
cURL Example
curl -X POST -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' -d 'question=1&content=开心就好' http://127.0.0.1:8000/qa/answers/
JSON Response
{ "pk": 2, "author": "teacher", "question": 1, "content": "开心就好", "create_time": "2016-04-14T03:49:50.504486Z", "adopt": false, "highlight": false, "profile": { "pk": 1, "username": "15201052252", "nickname": "晓辰", "avatar_url": "http://123.jpg", "website": "http://123.html", }}
2. 修改答案
Description
用户修改答案信息
Method and URL Structure
| Method |
Resource URL |
| PUT |
/qa/answers/${pk}/ |
Request Parameters
| Name |
Description |
Required |
Default |
| content |
问题内容 |
NO |
|
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
Request
{ "content":"今天过的很happy",}
cURL Example
curl -X PUT -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' -d '&content=今天很快乐?' http://127.0.0.1:8000/qa/answers/1/
JSON Response
{ "pk": 1, "author": "teacher", "question": 1, "content": "今天很快乐?", "create_time": "2016-04-14T03:48:58.201482Z", "adopt": true, "highlight": true, "profile": { "pk": 1, "username": "15201052252", "nickname": "晓辰", "avatar_url": "http://123.jpg", "website": "http://123.html", }}
3. 删除答案
Description
用户删除答案信息
Method and URL Structure
| Method |
Resource URL |
| DELETE |
/qa/answers/${pk}/ |
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X DELETE -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/qa/answers/1/
JSON Response
| Name |
Description |
Default |
| detail |
失败原因 |
Not found |
| status |
成功 |
204 |
4. 查看具体答案
Description
用户查询某一答案信息
Method and URL Structure
| Method |
Resource URL |
| GET |
/qa/answers/${pk}/ |
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X GET -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/qa/answers/1/
JSON Response
{ "pk": 1, "author": "15201052252", "question": 1, "content": "从数学的角度说,1 1=2,从哲学上说,1 1=田。这是我的想法。", "create_time": "2016-05-31T07:54:59.148429Z", "adopt": true, "highlight": true, "profile": { "pk": 1, "owner": "15201052252", "nickname": "晓辰", "avatar_url": "http://123.jpg", "website": "http://123.html", }}
5. 获取某一问题所有答案
Description
用户查看问题所有答案
Method and URL Structure
| Method |
Resource URL |
| GET |
/qa/answers/ |
Request Parameters
默认分页取数据库中最新的10条数据
| Name |
Description |
Required |
Default |
| page |
page Number |
Yes |
1 |
| question |
某一问题资源的pk/id |
Yes |
|
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X GET -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' -d 'page=1' http://127.0.0.1:8000/qa/answers/?question=1
JSON Response
{ "count": 2, "next": null, "previous": null, "results": [ { "pk": 4, "author": "teacher", "question": 1, "content": "开心就好", "create_time": "2016-04-14T04:01:03.766729Z", "adopt": true, "highlight": true, "profile": { "pk": 1, "owner": "15201052252", "nickname": "晓辰", "avatar_url": "http://123.jpg", "website": "http://123.html", } }, { "pk": 3, "author": "teacher", "question": 1, "content": "开心就好", "create_time": "2016-04-14T04:01:03.766729Z", "adopt": true, "highlight": true, "profile": { "pk": 1, "owner": "15201052252", "nickname": "晓辰", "avatar_url": "http://123.jpg", "website": "http://123.html", } } ]}
1. 给答案添加评论
Description
用户给答案添加评论
Method and URL Structure
| Method |
Resource URL |
| POST |
/qa/comments/ |
Request Parameters
| Name |
Description |
Required |
Default |
| answer |
答案资源的pk/id |
Yes |
|
| content |
评论内容 |
Yes |
|
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
Request
{ "answer":1, "content":"今天怎么样?",}
cURL Example
curl -X POST -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' -d 'answer=2&content=开心就好' http://127.0.0.1:8000/qa/comments/
JSON Response
{ "pk": 1, "author": "teacher", "content": "hello", "answer": 2, "create_time": "2016-04-14T05:56:44.514812Z"}
2. 删除评论
Description
用户删除评论信息
Method and URL Structure
| Method |
Resource URL |
| DELETE |
/qa/comments/${pk}/ |
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X DELETE -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/qa/comments/1/
JSON Response
| Name |
Description |
Default |
| detail |
失败原因 |
Not found |
| status |
成功 |
204 |
4. 查看具体评论
Description
用户查询某一评论信息
Method and URL Structure
| Method |
Resource URL |
| GET |
/qa/comments/${pk}/ |
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X GET -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' http://127.0.0.1:8000/qa/comments/2/
JSON Response
{ "pk": 2, "author": "teacher", "content": "hello", "answer": 2, "create_time": "2016-04-14T05:59:04.089674Z"}
5. 获取某一答案所有评论
Description
用户查看答案所有评论
Method and URL Structure
| Method |
Resource URL |
| GET |
/qa/comments/ |
Request Parameters
默认分页取数据库中最新的10条数据
| Name |
Description |
Required |
Default |
| page |
page Number |
Yes |
1 |
| answer |
某一答案资源的pk/id |
Yes |
|
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X GET -H 'Authorization: Token 7309fabd207c22e0a00eada158989b89ffe839ef' -d 'page=1' http://127.0.0.1:8000/qa/comments/?answer=2
JSON Response
{ "count": 3, "next": null, "previous": null, "results": [ { "pk": 4, "author": "teacher", "content": "hello", "answer": 2, "create_time": "2016-04-14T05:59:11.765788Z" }, { "pk": 3, "author": "teacher", "content": "hello", "answer": 2, "create_time": "2016-04-14T05:59:06.878130Z" }, { "pk": 2, "author": "teacher", "content": "hello", "answer": 2, "create_time": "2016-04-14T05:59:04.089674Z" } ]}
01. 采纳答案
Description
用户采纳了回答者的答案
Method and URL Structure
| Method |
Resource URL |
| PATCH |
/qa/adopt/${pk}/ |
| Name |
Description |
Required |
Default |
| Authorization |
Token 7309fabd207c22e0a00eada158989b89ffe839ef |
Yes |
|
*Authorization的值为登录成功后返回值
cURL Example
curl -X PATCH -H 'Authorization: Token 646bae225c36ee8edb8c93d88a5f52c054a3fbeb' http://127.0.0.1:8000/qa/adopt/1/
JSON Response
{ "pk": 1, "author": "15201052252", "question": 1, "content": "从数学的角度说,1 1=2,从哲学上说,1 1=田。这是我的想法。", "create_time": "2016-05-31T07:54:59.148429Z", "adopt": true, "highlight": true, "profile": { "pk": 1, "owner": "15201052252", "nickname": "晓辰", "avatar_url": "http://123.jpg", "website": "http://123.html", }}