diff --git a/functions/handlers/post.js b/functions/handlers/post.js index 47af9c0..d52fbe3 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -79,6 +79,25 @@ exports.getFilteredPostsOnTopics = (req, res) => { var topics = new Set(); topics.add(queryTopics.get().microBlogTopics) - var queryPosts = admin.firestore().collection('posts'); - + //console.log(topics); + + var queryPosts = admin.firestore().collection('posts').where('microBlogTopics','==', topics); + + console.log(queryPosts); + + queryPosts.get() + .then(function(Posts) { + let posts = []; + Posts.forEach(function(doc){ + posts.push(doc.data()); + }); + return res.status(200).json(posts); + }) + .then(function() { + res.status(200).send("Successfully retrieved filtered posts from database."); + return; + }) + .catch(function(err) { + res.status(500).send("Failed to retrieve posts from database.", err); + }); } \ No newline at end of file diff --git a/functions/index.js b/functions/index.js index f05c7b8..d977745 100644 --- a/functions/index.js +++ b/functions/index.js @@ -58,12 +58,14 @@ app.get("/getUserHandles", fbAuth, getUserHandles); /*------------------------------------------------------------------* * handlers/post.js * *------------------------------------------------------------------*/ -const { getallPostsforUser, getallPosts, putPost } = require("./handlers/post"); +const { getallPostsforUser, getallPosts, putPost, getFilteredPostsOnTopics } = require("./handlers/post"); app.get("/getallPostsforUser", fbAuth, getallPostsforUser); app.get("/getallPosts", getallPosts); +app.get("/getFilteredPostsOnTopics", getFilteredPostsOnTopics); + // Adds one post to the database app.post("/putPost", fbAuth, putPost);