Authored by 李奇

发布文章修改

... ... @@ -7,7 +7,9 @@ const ArticleModel = require('../models/article');
const ADD_ARTICLE_SUCCESS = '文章发表成功';
const GET_ARTICLES_SUCCESS = '获取文章列表成功';
const INVALID_IMG_OR_CONTENT = '图片和内容都不能为空';
const INVALID_ACTIVITY_ID = '活动ID[actId]不能为空';
const INVALID_IMG = '图片[imgUrl]不能为空';
const INVALID_CONTENT = '内容[content]都不能为空';
const article = {
/**
... ... @@ -33,17 +35,24 @@ const article = {
* @param res
*/
publish(req, res) {
let errorMsg = '';
const actId = req.body.actId;
const imgUrl = req.body.imgUrl;
const content = req.body.content;
if (!imgUrl || !content) {
!imgUrl && (errorMsg = INVALID_IMG);
!content && (errorMsg = INVALID_CONTENT);
!actId && (errorMsg = INVALID_ACTIVITY_ID);
if (errorMsg) {
return res.json({
code: 400,
message: INVALID_IMG_OR_CONTENT
message: errorMsg
});
}
const params = {
actId,
imgUrl,
content
};
... ...
... ... @@ -25,17 +25,19 @@ class ArticleModel extends global.yoho.BaseModel {
/**
* 发表文章
* @param content
* @param imgUrl
* @param actId 活动ID
* @param content 文章内容
* @param imgUrl 图片链接
* @returns {*}
*/
createArticle({content, imgUrl}) {
createArticle({actId, content, imgUrl}) {
const session = this.ctx.req.session;
const userId = _.get(session, 'user.id');
return mysqlCli.insert(
`insert into ${TABLE_ACT_ARTICLE} (user_id, content) values (:userId, :content);`,
`insert into ${TABLE_ACT_ARTICLE} (act_id, user_id, content) values (:actId, :userId, :content);`,
{
actId,
userId,
imgUrl,
content
... ...
... ... @@ -85,12 +85,14 @@
|名称 | 类型 |必填| 描述
|------|-------|-----|----
|actId|string |是|活动Id
|imgUrl|string |是|图片链接
|content | string |是|内容
### Request (JSON)
{
"actId": 1
"imgUrl": 'http://img12.static.yhbimg.com/imserver/2016/11/17/11/02bc3c3de856432175c01d937342a1f2ce.jpg'
"content":'测试评论内容'
}
... ... @@ -101,6 +103,5 @@
}
### 六、图片详情
... ...