diff --git a/functions/handlers/post.js b/functions/handlers/post.js index 79fcc4a..d15ea33 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -26,3 +26,20 @@ exports.putPost = (req, res) => { }); }; +exports.getallPostsforUser = (req, res) => { + + admin.firestore().collection('posts').where('userHandle', '==', 'user' ).get() + .then((data) => { + let posts = []; + data.forEach(function(doc) { + posts.push(doc.data()); + }); + return res.status(200).json(posts); + }) + .catch((err) => { + console.error(err); + return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'}) + }) + } + + diff --git a/functions/index.js b/functions/index.js index 15c9020..f93af4c 100644 --- a/functions/index.js +++ b/functions/index.js @@ -24,8 +24,9 @@ app.post('/updateProfileInfo', updateProfileInfo); /*------------------------------------------------------------------* * handlers/post.js * *------------------------------------------------------------------*/ -const {putPost} = require('./handlers/post'); +const {putPost, getallPostsforUser} = require('./handlers/post'); +app.get('/getallPostsforUser', getallPostsforUser); // Adds one post to the database app.post('/putPost', fbAuth, putPost); diff --git a/twistter-frontend/src/Userline.js b/twistter-frontend/src/Userline.js index af4ba7a..51d74f4 100644 --- a/twistter-frontend/src/Userline.js +++ b/twistter-frontend/src/Userline.js @@ -9,16 +9,29 @@ class Userline extends Component { { super(props); this.state = { - + microBlogs : [] } + } - render() { + componentDidMount() { + + axios.get('http://localhost:5001/twistter-e4649/us-central1/api/getallPostsforUser') + .then(res => { + const post = res.data; + this.setState({microBlogs : post}) + + }) + + + } + + render() { return ( -

Hi

+ ) - } - + } } - -export default Userline; \ No newline at end of file +export default Userline; diff --git a/twistter-frontend/src/Writing_Microblogs.js b/twistter-frontend/src/Writing_Microblogs.js index d9cbb1e..1858193 100644 --- a/twistter-frontend/src/Writing_Microblogs.js +++ b/twistter-frontend/src/Writing_Microblogs.js @@ -37,10 +37,11 @@ class Writing_Microblogs extends Component { }, { headers: { 'Content-Type': 'application/json'} } + ) console.log(response.data); - event.preventDefault(); + this.setState({value: '', title: '',characterCount: 10}) } handleChangeforPost(event) { @@ -51,6 +52,7 @@ class Writing_Microblogs extends Component { const charCount = event.target.value.length const charRemaining = 10 - charCount this.setState({characterCount: charRemaining }) + }