Skip to content

Commit

Permalink
implemented semantic unit API
Browse files Browse the repository at this point in the history
  • Loading branch information
vecna committed Sep 10, 2019
1 parent 2683b2b commit 05502bb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/contentAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,10 @@ module.exports = [
desc: "Keywords",
route: '/api/v2/keywords/:lang',
func: require('../routes/semantics').keywords,
},
{
desc: "Unit",
route: '/api/v2/unit/:semanticId',
func: require('../routes/semantics').unit,
}
];
22 changes: 21 additions & 1 deletion routes/semantics.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,25 @@ function keywords(req) {
});
};

function unit(req) {
const semanticId = req.params.semanticId;
debug("semantic unit query: %s", semanticId);
return Promise.all([
mongo.read(nconf.get('schema').semantics, { semanticId: semanticId }),
mongo.read(nconf.get('schema').summary, { semanticId: semanticId })
])
.then(function(e) {
debug("Found %d semantics and %d posts!",
_.size(e[0]), _.size(e[1]) );
return {
json: {
labels: _.map(e[0], function(semantic) { return _.omit(semantic, ['_id']); }),
posts: _.map(e[1], function(post) { return _.omit(post, ['_id']); })
}
};
})
}

module.exports = {
labels,
semantics,
Expand All @@ -300,5 +319,6 @@ module.exports = {
noogle,
langinfo,
languages,
keywords
keywords,
unit
};

0 comments on commit 05502bb

Please sign in to comment.