From bf0c4c78ee27803605e2b78c5f6a7f1abd38f585 Mon Sep 17 00:00:00 2001 From: shobhitm23 Date: Wed, 2 Oct 2019 21:11:11 -0400 Subject: [PATCH] Added basic backend implementation to get posts based on topics --- functions/handlers/post.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index 5f361fe..a42b2c4 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -41,3 +41,20 @@ exports.getallPostsforUser = (req, res) => { return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'}) }) } + + exports.getallPostsrelatedtoTopics = (req, res) => { + admin.firestore().collection('posts').where('microBlogTopics', '==', 'Joker').get() + .then((data) => { + let posts = []; + data.forEach(function(doc) { + posts.push(doc.data()); + }); + return res.status(200).json(posts); + }) + .catch((err) => { + console.err(err); + return res.status(500).json({error: 'Failed to fetch all posts with a specific Topic.'}) + } + + ) + } \ No newline at end of file