Compare commits

...

3 Commits

Author SHA1 Message Date
shobhitm23
f08db94f0d before npm rebuild 2019-11-12 14:48:58 -05:00
shobhitm23
5ad28dc254 Basic logic 2019-11-12 14:12:18 -05:00
shobhitm23
4958723a42 Filtering just with topics 2019-11-08 18:08:28 -05:00
2 changed files with 35 additions and 1 deletions

View File

@@ -69,3 +69,35 @@ exports.getallPosts = (req, res) => {
exports.getFilteredPosts = (req, res) => {
admin.firestore().collection('posts').where('userHandle', '==', 'new user').where('microBlogTopics', '==')
};
exports.getFilteredPostsOnTopics = (req, res) => {
// get topics that user follows
// make a set storing all topics
// for each post, make a set of topics and if A and B != 0, you can display post
var queryTopics = admin.firestore().collection('users').where('userHandle', '==', req.userHandle)
var topics = new Set();
topics.add(queryTopics.get().microBlogTopics)
//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);
});
}

View File

@@ -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);