Showing
3 changed files
with
20 additions
and
8 deletions
@@ -7,7 +7,9 @@ const ArticleModel = require('../models/article'); | @@ -7,7 +7,9 @@ const ArticleModel = require('../models/article'); | ||
7 | 7 | ||
8 | const ADD_ARTICLE_SUCCESS = '文章发表成功'; | 8 | const ADD_ARTICLE_SUCCESS = '文章发表成功'; |
9 | const GET_ARTICLES_SUCCESS = '获取文章列表成功'; | 9 | const GET_ARTICLES_SUCCESS = '获取文章列表成功'; |
10 | -const INVALID_IMG_OR_CONTENT = '图片和内容都不能为空'; | 10 | +const INVALID_ACTIVITY_ID = '活动ID[actId]不能为空'; |
11 | +const INVALID_IMG = '图片[imgUrl]不能为空'; | ||
12 | +const INVALID_CONTENT = '内容[content]都不能为空'; | ||
11 | 13 | ||
12 | const article = { | 14 | const article = { |
13 | /** | 15 | /** |
@@ -33,17 +35,24 @@ const article = { | @@ -33,17 +35,24 @@ const article = { | ||
33 | * @param res | 35 | * @param res |
34 | */ | 36 | */ |
35 | publish(req, res) { | 37 | publish(req, res) { |
38 | + let errorMsg = ''; | ||
39 | + const actId = req.body.actId; | ||
36 | const imgUrl = req.body.imgUrl; | 40 | const imgUrl = req.body.imgUrl; |
37 | const content = req.body.content; | 41 | const content = req.body.content; |
38 | 42 | ||
39 | - if (!imgUrl || !content) { | 43 | + !imgUrl && (errorMsg = INVALID_IMG); |
44 | + !content && (errorMsg = INVALID_CONTENT); | ||
45 | + !actId && (errorMsg = INVALID_ACTIVITY_ID); | ||
46 | + | ||
47 | + if (errorMsg) { | ||
40 | return res.json({ | 48 | return res.json({ |
41 | code: 400, | 49 | code: 400, |
42 | - message: INVALID_IMG_OR_CONTENT | 50 | + message: errorMsg |
43 | }); | 51 | }); |
44 | } | 52 | } |
45 | 53 | ||
46 | const params = { | 54 | const params = { |
55 | + actId, | ||
47 | imgUrl, | 56 | imgUrl, |
48 | content | 57 | content |
49 | }; | 58 | }; |
@@ -25,17 +25,19 @@ class ArticleModel extends global.yoho.BaseModel { | @@ -25,17 +25,19 @@ class ArticleModel extends global.yoho.BaseModel { | ||
25 | 25 | ||
26 | /** | 26 | /** |
27 | * 发表文章 | 27 | * 发表文章 |
28 | - * @param content | ||
29 | - * @param imgUrl | 28 | + * @param actId 活动ID |
29 | + * @param content 文章内容 | ||
30 | + * @param imgUrl 图片链接 | ||
30 | * @returns {*} | 31 | * @returns {*} |
31 | */ | 32 | */ |
32 | - createArticle({content, imgUrl}) { | 33 | + createArticle({actId, content, imgUrl}) { |
33 | const session = this.ctx.req.session; | 34 | const session = this.ctx.req.session; |
34 | const userId = _.get(session, 'user.id'); | 35 | const userId = _.get(session, 'user.id'); |
35 | 36 | ||
36 | return mysqlCli.insert( | 37 | return mysqlCli.insert( |
37 | - `insert into ${TABLE_ACT_ARTICLE} (user_id, content) values (:userId, :content);`, | 38 | + `insert into ${TABLE_ACT_ARTICLE} (act_id, user_id, content) values (:actId, :userId, :content);`, |
38 | { | 39 | { |
40 | + actId, | ||
39 | userId, | 41 | userId, |
40 | imgUrl, | 42 | imgUrl, |
41 | content | 43 | content |
@@ -85,12 +85,14 @@ | @@ -85,12 +85,14 @@ | ||
85 | 85 | ||
86 | |名称 | 类型 |必填| 描述 | 86 | |名称 | 类型 |必填| 描述 |
87 | |------|-------|-----|---- | 87 | |------|-------|-----|---- |
88 | +|actId|string |是|活动Id | ||
88 | |imgUrl|string |是|图片链接 | 89 | |imgUrl|string |是|图片链接 |
89 | |content | string |是|内容 | 90 | |content | string |是|内容 |
90 | 91 | ||
91 | 92 | ||
92 | ### Request (JSON) | 93 | ### Request (JSON) |
93 | { | 94 | { |
95 | + "actId": 1 | ||
94 | "imgUrl": 'http://img12.static.yhbimg.com/imserver/2016/11/17/11/02bc3c3de856432175c01d937342a1f2ce.jpg' | 96 | "imgUrl": 'http://img12.static.yhbimg.com/imserver/2016/11/17/11/02bc3c3de856432175c01d937342a1f2ce.jpg' |
95 | "content":'测试评论内容' | 97 | "content":'测试评论内容' |
96 | } | 98 | } |
@@ -101,6 +103,5 @@ | @@ -101,6 +103,5 @@ | ||
101 | } | 103 | } |
102 | 104 | ||
103 | 105 | ||
104 | - | ||
105 | ### 六、图片详情 | 106 | ### 六、图片详情 |
106 | 107 |
-
Please register or login to post a comment