Skip to content

Commit

Permalink
文档编写完成
Browse files Browse the repository at this point in the history
  • Loading branch information
leftjs committed Jan 25, 2016
1 parent 958a41d commit f4e6405
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 19 deletions.
156 changes: 154 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## The Server for UpHall (尚食堂)

> uphall is a simple app of dinner management ,and this repo is the server of the app, it can make cook(or worker for hall) to publish the infos of foods ,and people want to have a meal in hall can order the food that she/he want to eat refrain from the long queue. Read the restful api references for more details
> Uphall is a simple app of dinner management ,and this repo is the server of the app, it can make cook(or worker for hall) to publish the infos of foods ,and people want to have a meal in hall can order the food that she/he want to eat refrain from the long queue. Read the restful api references for more details


Expand All @@ -23,7 +23,7 @@ $ gulp (for serve)

## RESTful API References (v1)

**访问处login/register两个api外的api均需要在headers中传入'x-token'以判断用户身份,不传一律拒绝操作,返回401
> 访问除login/register两个api外的api均需要在headers中传入'x-token'以判断用户身份,不传一律拒绝操作,返回401
#### user(用户)

Expand Down Expand Up @@ -387,8 +387,160 @@ $ gulp (for serve)
#### 评价(comment)

1. 发表评价

description: 传入订单id 发表相应的评价,消费者评价可以上传图片,窗口管理员评价不需要传入图片,图片上传有两种方式,暂时不支持客户端自行上传到云数据库而只传递url到服务器,目前是调用上传部分的api进行图片上传到本服务器的操作,这点请注意一下

url: /api/comments/:id

method: POST

params:

* id [required,query] 订单id
* rating: [required,number(0.0~5.0)] 评分
* content: [optional,string] 评价内容,可以不传使用默认评价

return:

* 404/400
* 200 {id:评价的id}

2. 获取窗口的评价

description: 获取指定窗口的评价,包括消费者和窗口管理员的评价

url: /api/comments/window/:id

method: GET

params:

* id: [required,query] 窗口id

return:

* 404
* 200 [{commentObj},{commentObj},...]

3. 获取单个订单的评价

descripiton: 获取单个订单的双方评价

url: /api/comments/order/:id

method: GET

params:

* id: [required,query] 订单id

return:

* 404
* 200 [{commentObj},{commentObj},…]

#### 图片上传(upload)

1. 窗口的icon上传

description: 窗口的icon的上传,身份认证必须是该窗口的拥有者

headers:

* Content-Type: multipart-form-data 除上传api外都默认是application/x-www-form-urlencoded
* x-token: 默认必传

url: /api/upload/window/:id

method: POST

params:

* id: [required,query] 窗口的id
* file: [required,file] 可以传入一张image,大小不超过200K,不限制属性名

return:

* 400/401
* 200 body.text = 'success'

2. 评论的图片上传

description: 某订单评论的图片上传,必须是该订单的消费者

headers:

* Content-Type: multipart-form-data 除上传api外都默认是application/x-www-form-urlencoded
* x-token: 默认必传

url: /api/upload/comment/:id

method: POST

params:

* id: [required,query] 订单的id
* files: [required,file] 可以传入多张图片,注意属性名不能相同,可用file1,file2... 代替,不限制属性名,可自由发挥

return

* 400/401
* 200 body.text = 'success'

3. 用户头像上传

description: 用户头像的上传

headers:

- Content-Type: multipart-form-data 除上传api外都默认是application/x-www-form-urlencoded
- x-token: 默认必传

url: /api/upload/avatar

method: POST

params:

- file: [required,file] 文件名称无所谓,只需要传递一张图片即可,大小不超过200K

return:

- 400
- 200 body.text = 'success'

4. 食物的展示图片上传

description: 食物的展示图片的上传,图片最大尺寸为1M,规定自由该食物的拥有者能够上传食物的图片

headers:

- Content-Type: multipart-form-data 除上传api外都默认是application/x-www-form-urlencoded
- x-token: 默认必传

url: /api/upload/food/:id

method: POST

params:

- id: [required,query] 食物的id
- file: [required,file] 可以传入一张image,大小不超过200K,不限制属性名

return:

- 400/401
- 200 body.text = 'success'







### NOTES

*api(v1)如上,其余功能v2中陆续增加,推送以及IM拟采用[leancloud](https://leancloud.cn/docs/index.html),文档可以提前阅读*



Expand Down
30 changes: 15 additions & 15 deletions dist/database/users.db
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{"name":"匿名","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"","expiredTime":1453655189780,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"puiyhrrGmZN2V1Fr"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"","expiredTime":1453655189791,"is_admin":false,"is_windower":true,"avatar_uri":"","score":0,"_id":"3g060xAcf4i3o6bh"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"","expiredTime":1453655189799,"is_admin":true,"is_windower":false,"avatar_uri":"","score":0,"_id":"BUoAmFnrG3iOGoOr"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IkJVb0FtRm5yRzNpT0dvT3IiLCJpYXQiOjE0NTM2NTUxODl9.ZSV1gnF1Y1xqa_zwIFpttig7OaqT4qJ2HETbbFgusMc","expiredTime":1454259989825,"is_admin":true,"is_windower":false,"avatar_uri":"","score":0,"_id":"BUoAmFnrG3iOGoOr"}
{"name":"匿名","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InB1aXlocnJHbVpOMlYxRnIiLCJpYXQiOjE0NTM2NTUxODl9.Bu2aK4RA71-9LWXmlDYKBvFrpW_BlvFrYiyMvf4OJUY","expiredTime":1454259989837,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"puiyhrrGmZN2V1Fr"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjNnMDYweEFjZjRpM282YmgiLCJpYXQiOjE0NTM2NTUxODl9.f2C3Rx1YbvrPrRtO5AcgWKd0WccpsHzsN_Zr0eX5NLA","expiredTime":1454259989846,"is_admin":false,"is_windower":true,"avatar_uri":"","score":0,"_id":"3g060xAcf4i3o6bh"}
{"name":"张三","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InB1aXlocnJHbVpOMlYxRnIiLCJpYXQiOjE0NTM2NTUxODl9.Bu2aK4RA71-9LWXmlDYKBvFrpW_BlvFrYiyMvf4OJUY","expiredTime":1454259989837,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"puiyhrrGmZN2V1Fr"}
{"name":"张三","username":"customer","password":"f5bb0c8de146c67b44babbf4e6584cc0","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InB1aXlocnJHbVpOMlYxRnIiLCJpYXQiOjE0NTM2NTUxODl9.Bu2aK4RA71-9LWXmlDYKBvFrpW_BlvFrYiyMvf4OJUY","expiredTime":1454259989837,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"puiyhrrGmZN2V1Fr"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IkJVb0FtRm5yRzNpT0dvT3IiLCJpYXQiOjE0NTM2NTUxODl9.ZSV1gnF1Y1xqa_zwIFpttig7OaqT4qJ2HETbbFgusMc","expiredTime":1454259989825,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"BUoAmFnrG3iOGoOr"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IkJVb0FtRm5yRzNpT0dvT3IiLCJpYXQiOjE0NTM2NTUxODl9.ZSV1gnF1Y1xqa_zwIFpttig7OaqT4qJ2HETbbFgusMc","expiredTime":1454259989825,"is_admin":true,"is_windower":false,"avatar_uri":"","score":0,"_id":"BUoAmFnrG3iOGoOr"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjNnMDYweEFjZjRpM282YmgiLCJpYXQiOjE0NTM2NTUxODl9.f2C3Rx1YbvrPrRtO5AcgWKd0WccpsHzsN_Zr0eX5NLA","expiredTime":1454259989846,"is_admin":false,"is_windower":true,"avatar_uri":"","score":0,"_id":"3g060xAcf4i3o6bh"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjNnMDYweEFjZjRpM282YmgiLCJpYXQiOjE0NTM2NTUxODl9.f2C3Rx1YbvrPrRtO5AcgWKd0WccpsHzsN_Zr0eX5NLA","expiredTime":1454259989846,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"3g060xAcf4i3o6bh"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjNnMDYweEFjZjRpM282YmgiLCJpYXQiOjE0NTM2NTUxODl9.f2C3Rx1YbvrPrRtO5AcgWKd0WccpsHzsN_Zr0eX5NLA","expiredTime":1454259989846,"is_admin":false,"is_windower":true,"avatar_uri":"","score":0,"_id":"3g060xAcf4i3o6bh"}
{"name":"张三","username":"customer","password":"f5bb0c8de146c67b44babbf4e6584cc0","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InB1aXlocnJHbVpOMlYxRnIiLCJpYXQiOjE0NTM2NTUxODl9.Bu2aK4RA71-9LWXmlDYKBvFrpW_BlvFrYiyMvf4OJUY","expiredTime":1454259989837,"is_admin":false,"is_windower":false,"avatar_uri":"http://localhost:7410/api/images/avatar/0ade89f64874bb4462c43740e715dd82.jpg","score":0,"_id":"puiyhrrGmZN2V1Fr"}
{"name":"张三","username":"customer","password":"f5bb0c8de146c67b44babbf4e6584cc0","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InB1aXlocnJHbVpOMlYxRnIiLCJpYXQiOjE0NTM2NTUxODl9.Bu2aK4RA71-9LWXmlDYKBvFrpW_BlvFrYiyMvf4OJUY","expiredTime":1454259989837,"is_admin":false,"is_windower":false,"avatar_uri":"http://localhost:7410/api/images/avatar/0ade89f64874bb4462c43740e715dd82.jpg","score":25,"_id":"puiyhrrGmZN2V1Fr"}
{"name":"匿名","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"","expiredTime":1453697174195,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"d0GrbREQcWbjcgal"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"","expiredTime":1453697174199,"is_admin":false,"is_windower":true,"avatar_uri":"","score":0,"_id":"pVCBn2S4ssoMSeeD"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"","expiredTime":1453697174203,"is_admin":true,"is_windower":false,"avatar_uri":"","score":0,"_id":"QtE8pb7eLJdmWMCG"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IlF0RThwYjdlTEpkbVdNQ0ciLCJpYXQiOjE0NTM2OTcxNzR9.HndOf-YG8lA7-gfROjQx84VgeHeuFwa1RSxozgxwD_o","expiredTime":1454301974213,"is_admin":true,"is_windower":false,"avatar_uri":"","score":0,"_id":"QtE8pb7eLJdmWMCG"}
{"name":"匿名","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImQwR3JiUkVRY1diamNnYWwiLCJpYXQiOjE0NTM2OTcxNzR9.-JXpFXAr7AGbkzSL_oajHPXDu8dOud5kU-U2vtDHp48","expiredTime":1454301974221,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"d0GrbREQcWbjcgal"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InBWQ0JuMlM0c3NvTVNlZUQiLCJpYXQiOjE0NTM2OTcxNzR9.1XxPMRNMPG2lkW3WseLc2-9hEEmPwpNjwGTs_8RPFZM","expiredTime":1454301974228,"is_admin":false,"is_windower":true,"avatar_uri":"","score":0,"_id":"pVCBn2S4ssoMSeeD"}
{"name":"张三","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImQwR3JiUkVRY1diamNnYWwiLCJpYXQiOjE0NTM2OTcxNzR9.-JXpFXAr7AGbkzSL_oajHPXDu8dOud5kU-U2vtDHp48","expiredTime":1454301974221,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"d0GrbREQcWbjcgal"}
{"name":"张三","username":"customer","password":"f5bb0c8de146c67b44babbf4e6584cc0","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImQwR3JiUkVRY1diamNnYWwiLCJpYXQiOjE0NTM2OTcxNzR9.-JXpFXAr7AGbkzSL_oajHPXDu8dOud5kU-U2vtDHp48","expiredTime":1454301974221,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"d0GrbREQcWbjcgal"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IlF0RThwYjdlTEpkbVdNQ0ciLCJpYXQiOjE0NTM2OTcxNzR9.HndOf-YG8lA7-gfROjQx84VgeHeuFwa1RSxozgxwD_o","expiredTime":1454301974213,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"QtE8pb7eLJdmWMCG"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IlF0RThwYjdlTEpkbVdNQ0ciLCJpYXQiOjE0NTM2OTcxNzR9.HndOf-YG8lA7-gfROjQx84VgeHeuFwa1RSxozgxwD_o","expiredTime":1454301974213,"is_admin":true,"is_windower":false,"avatar_uri":"","score":0,"_id":"QtE8pb7eLJdmWMCG"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InBWQ0JuMlM0c3NvTVNlZUQiLCJpYXQiOjE0NTM2OTcxNzR9.1XxPMRNMPG2lkW3WseLc2-9hEEmPwpNjwGTs_8RPFZM","expiredTime":1454301974228,"is_admin":false,"is_windower":true,"avatar_uri":"","score":0,"_id":"pVCBn2S4ssoMSeeD"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InBWQ0JuMlM0c3NvTVNlZUQiLCJpYXQiOjE0NTM2OTcxNzR9.1XxPMRNMPG2lkW3WseLc2-9hEEmPwpNjwGTs_8RPFZM","expiredTime":1454301974228,"is_admin":false,"is_windower":false,"avatar_uri":"","score":0,"_id":"pVCBn2S4ssoMSeeD"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InBWQ0JuMlM0c3NvTVNlZUQiLCJpYXQiOjE0NTM2OTcxNzR9.1XxPMRNMPG2lkW3WseLc2-9hEEmPwpNjwGTs_8RPFZM","expiredTime":1454301974228,"is_admin":false,"is_windower":true,"avatar_uri":"","score":0,"_id":"pVCBn2S4ssoMSeeD"}
{"name":"张三","username":"customer","password":"f5bb0c8de146c67b44babbf4e6584cc0","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImQwR3JiUkVRY1diamNnYWwiLCJpYXQiOjE0NTM2OTcxNzR9.-JXpFXAr7AGbkzSL_oajHPXDu8dOud5kU-U2vtDHp48","expiredTime":1454301974221,"is_admin":false,"is_windower":false,"avatar_uri":"http://localhost:7410/api/images/avatar/8d2d4ecafec71960331b073b6af145e0.jpg","score":0,"_id":"d0GrbREQcWbjcgal"}
{"name":"张三","username":"customer","password":"f5bb0c8de146c67b44babbf4e6584cc0","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImQwR3JiUkVRY1diamNnYWwiLCJpYXQiOjE0NTM2OTcxNzR9.-JXpFXAr7AGbkzSL_oajHPXDu8dOud5kU-U2vtDHp48","expiredTime":1454301974221,"is_admin":false,"is_windower":false,"avatar_uri":"http://localhost:7410/api/images/avatar/8d2d4ecafec71960331b073b6af145e0.jpg","score":25,"_id":"d0GrbREQcWbjcgal"}
28 changes: 28 additions & 0 deletions src/bizs/commentBiz.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ addCommentToOrder = (req,res,next) ->
# TODO 卖家评分的使用场景暂定
db.comments.insert({
content: content ?= '这家伙很懒,没有写评价'
windowId: doc.windowId
orderId: orderId
userId: req.userInfo._id
is_windower: true
},(err,comment) ->
return next(err) if err
return next(commonBiz.customError(400,'评价失败')) if not comment
Expand All @@ -51,6 +54,9 @@ addCommentToOrder = (req,res,next) ->
db.comments.insert({
content: content ?= '这家伙很懒,没有写评价'
userId: req.userInfo._id
windowId: doc.windowId
orderId: orderId
is_windower: false
pics: []
},(err,comment) ->
return next(err) if err
Expand Down Expand Up @@ -107,10 +113,32 @@ addCommentToOrder = (req,res,next) ->



# 获取窗口所有的评价
getWindowComments = (req,res,next) ->
windowId = req.params['id']
db.comments.find({windowId: windowId},(err,doc) ->
return next(err) if err
return next(commonBiz.customError(404,'找不到该窗口的评价')) if not doc
return res.json(doc)
)



# 获取订单的评价
getOrder = (req,res,next) ->
# console.log('asdfasdfs')
orderId = req.params['id']
db.comments.find({orderId:orderId},(err,doc) ->
return next(err) if err
return next(commonBiz.customError(404,'找不到该订单的评价')) if not doc
return res.json(doc)
)


module.exports = {
addCommentToOrder: addCommentToOrder
getWindowComments: getWindowComments
getOrder:getOrder
}


Expand Down
2 changes: 1 addition & 1 deletion src/bizs/uploadBiz.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ uploadFoodIcon = (req,res,next) ->
form.keepExtensions = true
form.encoding = 'utf-8'
# 窗口icon的最大尺寸为200k
form.maxFieldsSize = 200 * 1024
form.maxFieldsSize = 1024 * 1024

form.parse(req,(err,fields,files) ->
return next(err) if err
Expand Down
18 changes: 18 additions & 0 deletions src/routes/comment.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ router.post(
)


# 获取单个评论
router.get(
'/order/:id'
commonBiz.authAndSetUserInfo
commentBiz.getOrder
)

# 获取窗口的所有评价
router.get(
'/window/:id'
commonBiz.authAndSetUserInfo
commentBiz.getWindowComments
)






module.exports = router

Expand Down
24 changes: 23 additions & 1 deletion test/users.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,32 @@ describe('上传相关', ->
).end(done)

)
)


)

describe('评价相关',->
it('获取窗口的所有评价',(done) ->
request(app)
.get('/api/comments/window/' + windowId )
.set('x-token',windowerToken)
.expect(200)
.expect((res) ->
console.log(res.body)

).end(done)
)
it('获取该订单的所有评价',(done) ->
request(app)
.get('/api/comments/order/' + orderId)
.set('x-token',windowerToken)
.expect(200)
.expect((res) ->
console.log(res.body)

).end(done)
)
)



Expand Down

0 comments on commit f4e6405

Please sign in to comment.