Skip to content

Commit

Permalink
tag s 获取接口
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangjiu committed Jul 12, 2016
1 parent 275eec0 commit 683fcdc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
Binary file modified FE/src/assets/banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 4 additions & 17 deletions server-modules/api-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,17 @@ const router = require('express').Router();

// 添加一个模块
const content = require('./content')
const tags = require('./tags')

// 一个 API 路由下的 hello 接口,访问 /api/hello
router.get('/hello', content.hello);
// router.get('/hello', content.hello);

// 博客文章列表
router.get('/content-list', content.contentList)

router.get('/article/:id', content.article)


// 测试 async/await 支持
// const f = () => {
// return new Promise((resolve, reject) => {
// setTimeout(() => {
// resolve(123);
// }, 2000);
// });
// };
//
// const testAsync = async() => {
// const t = await f();
// console.log(t);
// };
//
// testAsync();
// tags
router.get('/tags', tags.tags)

module.exports = router;
45 changes: 45 additions & 0 deletions server-modules/tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 每位工程师都有保持代码优雅的义务
* Each engineer has a duty to keep the code elegant
*
* @author wangxiao
*/

// 一些工具方法

'use strict';

const tool = require('./tool');
const AV = require('leanengine')

let pub = {};

// 获取所有 tags
pub.tags = async(req, res) => {
const queryTags = () => {
const query = new AV.Query('Tags')
return query.find()
}

try {
const data = await queryTags()

if (data) {
let arr = []
for (let item of data) {
let result = {}
result.objectId = item.get('objectId')
result.tagName = item.get('tagName')
arr.push(result)
}
res.send(arr)

} else {
throw new Error("can not find tags")
}
} catch (error) {
tool.l(error)
}
}

module.exports = pub;

0 comments on commit 683fcdc

Please sign in to comment.