Authored by 邱骏

详情查询

... ... @@ -7,9 +7,11 @@ const ArticleModel = require('../models/article');
const ADD_ARTICLE_SUCCESS = '文章发表成功';
const GET_ARTICLES_SUCCESS = '获取文章列表成功';
const GET_ARTICLE_SUCCESS = '获取文章详情成功';
const INVALID_ACTIVITY_ID = '活动ID[actId]不能为空';
const INVALID_IMG = '图片[imgUrl]不能为空';
const INVALID_CONTENT = '内容[content]都不能为空';
const MISS_PARAMS = '缺少参数';
const article = {
/**
... ... @@ -74,6 +76,36 @@ const article = {
});
});
});
},
/**
* 查询单个article详情
* @param req
* @param res
*/
querySingle(req, res) {
let errorMsg = '';
const actId = req.query.actId;
const articleId = req.query.articleId;
!actId && (errorMsg = MISS_PARAMS);
!articleId && (errorMsg = MISS_PARAMS);
if (errorMsg) {
return res.json({
code: 400,
message: errorMsg
});
}
req.ctx(ArticleModel).getSingleArticle(actId, articleId)
.then(ret => {
res.json({
code: 200,
data: ret,
message: GET_ARTICLE_SUCCESS
});
});
}
};
... ...
... ... @@ -9,6 +9,7 @@ const mysqlCli = global.yoho.utils.mysqlCli;
const TABLE_ACT_ARTICLE = 'act_article';
const TABLE_ACT_ARTICLE_IMG = 'act_article_img';
const TABLE_ACT_ARTICLE_GOOD = 'act_article_good';
class ArticleModel extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -60,6 +61,25 @@ class ArticleModel extends global.yoho.BaseModel {
}
);
}
/**
* 获取单个文章详情
* @param articleId
* @returns {*}
*/
getSingleArticle(articleId, actId) {
return mysqlCli.query(`select act_article.id,content,good_count,
act_article_img.img_url from ${TABLE_ACT_ARTICLE}
join ${TABLE_ACT_ARTICLE_IMG}
where act_article_img.article_id = act_article.id
and act_article.act_id = :actId
and act_article.id = :articleId;`,
{
actId,
articleId
}
);
}
}
module.exports = ArticleModel;
... ...
... ... @@ -10,5 +10,6 @@ const article = require('./controllers/article');
router.get('/list', article.list);
router.post('/publish', auth, article.publish);
router.get('/querySingle', article.querySingle);
module.exports = router;
... ...