diff --git a/functions/handlers/post.js b/functions/handlers/post.js index e2d195b..79fcc4a 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -1,20 +1,21 @@ +const admin = require('firebase-admin'); /* eslint-disable promise/always-return */ exports.putPost = (req, res) => { - if (req.body.body.trim() === '') { - return res.status(400).json({ body: 'Body must not be empty!'}); - } + const newPost = { body: req.body.body, - userHandle: req.user.handle, - userImage: req.user.imageUrl, + userHandle: req.body.userHandle, + userImage: req.body.userImage, + microBlogTitle: req.body.microBlogTitle, createdAt: new Date().toISOString(), likeCount: 0, - commentCount: 0 + commentCount: 0, + }; - db.collection('post').add(newPost) - .then((doc) => { + admin.firestore().collection('posts').add(newPost) + .then((doc) => { const resPost = newPost; resPost.postId = doc.id; return res.status(200).json(resPost); diff --git a/functions/index.js b/functions/index.js index e764338..15c9020 100644 --- a/functions/index.js +++ b/functions/index.js @@ -26,6 +26,7 @@ app.post('/updateProfileInfo', updateProfileInfo); *------------------------------------------------------------------*/ const {putPost} = require('./handlers/post'); + // Adds one post to the database app.post('/putPost', fbAuth, putPost); diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index 3b0a077..1fea229 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -12,6 +12,7 @@ import register from './Register.js'; import login from './Login.js'; import user from './pages/user'; import writeMicroblog from './Writing_Microblogs.js'; +import userLine from './Userline.js'; class App extends Component { render() { @@ -25,6 +26,7 @@ class App extends Component { + diff --git a/twistter-frontend/src/Userline.js b/twistter-frontend/src/Userline.js new file mode 100644 index 0000000..af4ba7a --- /dev/null +++ b/twistter-frontend/src/Userline.js @@ -0,0 +1,24 @@ +import React, { Component } from "react"; +import { BrowserRouter as Router } from 'react-router-dom'; +import Route from 'react-router-dom/Route'; +import axios from 'axios'; + +class Userline extends Component { + + constructor(props) + { + super(props); + this.state = { + + } + } + + render() { + return ( +

Hi

+ ) + } + +} + +export default Userline; \ No newline at end of file diff --git a/twistter-frontend/src/Writing_Microblogs.js b/twistter-frontend/src/Writing_Microblogs.js index eca41d4..d9cbb1e 100644 --- a/twistter-frontend/src/Writing_Microblogs.js +++ b/twistter-frontend/src/Writing_Microblogs.js @@ -1,6 +1,7 @@ import React, { Component } from "react"; import { BrowserRouter as Router } from 'react-router-dom'; import Route from 'react-router-dom/Route'; +import axios from 'axios'; class Writing_Microblogs extends Component { @@ -25,7 +26,20 @@ class Writing_Microblogs extends Component { } handleSubmit(event) { - alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value); + // alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value); + + const response = axios.post( + 'http://localhost:5001/twistter-e4649/us-central1/api/putPost', + { body: this.state.value, + userHandle: "new user", + userImage: "bing-url", + microBlogTitle: this.state.title + + }, + { headers: { 'Content-Type': 'application/json'} } + ) + console.log(response.data); + event.preventDefault(); }