Skip to content

Commit 05502bb

Browse files
committed
implemented semantic unit API
1 parent 2683b2b commit 05502bb

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

lib/contentAPI.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,10 @@ module.exports = [
153153
desc: "Keywords",
154154
route: '/api/v2/keywords/:lang',
155155
func: require('../routes/semantics').keywords,
156+
},
157+
{
158+
desc: "Unit",
159+
route: '/api/v2/unit/:semanticId',
160+
func: require('../routes/semantics').unit,
156161
}
157162
];

routes/semantics.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,25 @@ function keywords(req) {
292292
});
293293
};
294294

295+
function unit(req) {
296+
const semanticId = req.params.semanticId;
297+
debug("semantic unit query: %s", semanticId);
298+
return Promise.all([
299+
mongo.read(nconf.get('schema').semantics, { semanticId: semanticId }),
300+
mongo.read(nconf.get('schema').summary, { semanticId: semanticId })
301+
])
302+
.then(function(e) {
303+
debug("Found %d semantics and %d posts!",
304+
_.size(e[0]), _.size(e[1]) );
305+
return {
306+
json: {
307+
labels: _.map(e[0], function(semantic) { return _.omit(semantic, ['_id']); }),
308+
posts: _.map(e[1], function(post) { return _.omit(post, ['_id']); })
309+
}
310+
};
311+
})
312+
}
313+
295314
module.exports = {
296315
labels,
297316
semantics,
@@ -300,5 +319,6 @@ module.exports = {
300319
noogle,
301320
langinfo,
302321
languages,
303-
keywords
322+
keywords,
323+
unit
304324
};

0 commit comments

Comments
 (0)