Merge branch 'feature/platform-basic' of git.yoho.cn:fe/yoho-activity-platform i…
…nto feature/platform-basic
Showing
3 changed files
with
41 additions
and
14 deletions
@@ -39,6 +39,8 @@ app.use(bodyParser.urlencoded({ | @@ -39,6 +39,8 @@ app.use(bodyParser.urlencoded({ | ||
39 | })); | 39 | })); |
40 | app.use(cookieParser()); | 40 | app.use(cookieParser()); |
41 | app.use(global.yoho.httpCtx()); | 41 | app.use(global.yoho.httpCtx()); |
42 | +app.enable('trust proxy'); | ||
43 | + | ||
42 | 44 | ||
43 | app.use((req, res, next) => { | 45 | app.use((req, res, next) => { |
44 | req.user = {}; // 全局的用户数据 | 46 | req.user = {}; // 全局的用户数据 |
@@ -20,19 +20,27 @@ const article = { | @@ -20,19 +20,27 @@ const article = { | ||
20 | * @param res | 20 | * @param res |
21 | */ | 21 | */ |
22 | list(req, res) { | 22 | list(req, res) { |
23 | - // const query = req.query; | ||
24 | - // const pageNo = query.pageNo; | ||
25 | - // const popular = query.popular || false; | ||
26 | - // const pageSize = query.pageSize; | ||
27 | - | ||
28 | - req.ctx(ArticleModel).articleList() | ||
29 | - .then(result => { | ||
30 | - res.json({ | ||
31 | - code: 200, | ||
32 | - data: result, | ||
33 | - message: GET_ARTICLES_SUCCESS | ||
34 | - }); | 23 | + const query = req.query; |
24 | + const pageNo = query.pageNo || 1; | ||
25 | + const pageSize = query.pageSize || 10; | ||
26 | + const isPopular = query.isPopular || false; | ||
27 | + const order = query.order || 'desc'; | ||
28 | + const orderBy = query.orderBy || 'create_time'; | ||
29 | + | ||
30 | + req.ctx(ArticleModel).articleList({ | ||
31 | + order, | ||
32 | + orderBy, | ||
33 | + pageNo, | ||
34 | + pageSize, | ||
35 | + isPopular | ||
36 | + }) | ||
37 | + .then(result => { | ||
38 | + res.json({ | ||
39 | + code: 200, | ||
40 | + data: result, | ||
41 | + message: GET_ARTICLES_SUCCESS | ||
35 | }); | 42 | }); |
43 | + }); | ||
36 | 44 | ||
37 | }, | 45 | }, |
38 | 46 |
@@ -21,8 +21,25 @@ class ArticleModel extends global.yoho.BaseModel { | @@ -21,8 +21,25 @@ class ArticleModel extends global.yoho.BaseModel { | ||
21 | * 获取文章列表 | 21 | * 获取文章列表 |
22 | * @returns {*} | 22 | * @returns {*} |
23 | */ | 23 | */ |
24 | - articleList() { | ||
25 | - return mysqlCli.query(`select * from ${TABLE_ACT_ARTICLE}`); | 24 | + articleList({pageNo, pageSize, isPopular, orderBy, order}) { |
25 | + let limitSql; | ||
26 | + let whereSql = ''; | ||
27 | + let orderSql = `ORDER BY AA.${orderBy} ${order}`; | ||
28 | + | ||
29 | + if (isPopular) { | ||
30 | + whereSql = 'WHERE AA.good_count > 10'; | ||
31 | + } | ||
32 | + | ||
33 | + limitSql = `LIMIT ${(pageNo - 1) * pageSize}, ${pageSize}`; | ||
34 | + | ||
35 | + return mysqlCli.query( | ||
36 | + `SELECT AA.id, AA.good_count goodCount, | ||
37 | + AAI.img_url imgUrl, AA.content | ||
38 | + FROM ${TABLE_ACT_ARTICLE} AS AA | ||
39 | + INNER JOIN ${TABLE_ACT_ARTICLE_IMG} AS AAI | ||
40 | + ON AA.id = AAI.article_id | ||
41 | + ${whereSql} ${orderSql} ${limitSql};` | ||
42 | + ); | ||
26 | } | 43 | } |
27 | 44 | ||
28 | /** | 45 | /** |
-
Please register or login to post a comment