mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
Filtered timeline posts to only followers
This commit is contained in:
parent
6184a22607
commit
1a2f269466
@ -63,3 +63,43 @@ exports.getallPosts = (req, res) => {
|
||||
res.status(500).send("Failed to retrieve posts from database.", err);
|
||||
});
|
||||
};
|
||||
|
||||
exports.getFollowedPosts = (req, res) => {
|
||||
var post_query = admin.firestore().collection("posts");
|
||||
var followers_list = admin.firestore().collection("users").doc(req.user.handle).collection("followedUsers");
|
||||
let followers_str = [];
|
||||
followers_str.push(req.user.handle);
|
||||
|
||||
followers_list.get()
|
||||
.then(function(allFollowers) {
|
||||
allFollowers.forEach(function(followers) {
|
||||
followers_str.push(followers.data().handle);
|
||||
});
|
||||
|
||||
post_query.get()
|
||||
.then(function(allPosts) {
|
||||
let posts = [];
|
||||
allPosts.forEach(function(doc) {
|
||||
if(followers_str.includes(doc.data().userHandle)) {
|
||||
posts.push(doc.data());
|
||||
}
|
||||
});
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
/*.then(function() {
|
||||
res.status(200).send("Successfully retrieved all posts from followed users.");
|
||||
return;
|
||||
})*/
|
||||
.catch(function(err) {
|
||||
res.status(500).send("Failed to retrieve posts.", err);
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
//res.status(200).send("Successfully added all follower handles to array.");
|
||||
//res.status(200).send("Successfully retrieved all posts from followed users.");
|
||||
return;
|
||||
})
|
||||
.catch(function(err) {
|
||||
res.status(500).send("Failed to retrieve follower handles.", err);
|
||||
});
|
||||
};
|
||||
|
||||
@ -44,12 +44,14 @@ app.get("/user", fbAuth, getAuthenticatedUser);
|
||||
/*------------------------------------------------------------------*
|
||||
* handlers/post.js *
|
||||
*------------------------------------------------------------------*/
|
||||
const { getallPostsforUser, getallPosts, putPost } = require("./handlers/post");
|
||||
const { getallPostsforUser, getallPosts, getFollowedPosts, putPost } = require("./handlers/post");
|
||||
|
||||
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||
|
||||
app.get("/getallPosts", getallPosts);
|
||||
|
||||
app.get("/getFollowedPosts", fbAuth, getFollowedPosts);
|
||||
|
||||
// Adds one post to the database
|
||||
app.post("/putPost", fbAuth, putPost);
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ class Home extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
axios
|
||||
.get("/getallPosts")
|
||||
.get("/getFollowedPosts")
|
||||
.then(res => {
|
||||
console.log(res.data);
|
||||
this.setState({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user