Commit fb699211 authored by 陈家荣's avatar 陈家荣

增加获取板块列表接口

parent a13a1377
...@@ -25,7 +25,7 @@ module.exports = function(app) { ...@@ -25,7 +25,7 @@ module.exports = function(app) {
app.use('/v1/forum', router); app.use('/v1/forum', router);
}; };
//新增论坛板块 //论坛板块
router.get('/info/list/all', function(req, res, next) { router.get('/info/list/all', function(req, res, next) {
var rs = {}; var rs = {};
var ent_code = req.session.user.ent_code; var ent_code = req.session.user.ent_code;
...@@ -794,3 +794,55 @@ router.get('/info/myAttend', function(req, res, next) { ...@@ -794,3 +794,55 @@ router.get('/info/myAttend', function(req, res, next) {
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
}) })
}); });
//论坛板块
router.get('/info/list/allWithThreadCount', function(req, res, next) {
var rs = {};
var ent_code = req.session.user.ent_code;
async.waterfall([
function(callback) {
forumInfoService.getAllByGid({ent_code: ent_code}, 1, 100, function(err, datas) {
callback(err, datas.items);
});
},
function(infos, callback) { //获取用户
var asyncTasks = [];
_.forEach(infos, function(info, i) {
asyncTasks.push(function(cont) {
var conditions = {
ent_code: ent_code,
info: info._id
};
forumThreadService.getAllCountByFid(conditions, function(err, count) {
if (err) {
console.error(err);
cont(err, null);
} else {
if (infos[i].toObject) {
infos[i] = infos[i].toObject();
}
infos[i].threadCount = count;
cont(null, info);
}
});
});
});
then.parallel(asyncTasks).then(function(cont, datas) {
callback(null, infos);
}).fail(function(err, cont) {
callback(err, null);
});
}
], function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
rs.data = result;
res.setHeader('Cache-Control', 'public, max-age=3600'); // 公共缓存一个小时
res.setHeader('Expires', new Date(Date.now() + 3600000).toUTCString());
res.json(_.assign(rs, returnCode.SUCCESS));
}
});
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment