mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 18:28:47 +00:00
commit
7969d3b10b
@ -1,20 +1,21 @@
|
|||||||
|
const admin = require('firebase-admin');
|
||||||
/* eslint-disable promise/always-return */
|
/* eslint-disable promise/always-return */
|
||||||
exports.putPost = (req, res) => {
|
exports.putPost = (req, res) => {
|
||||||
if (req.body.body.trim() === '') {
|
|
||||||
return res.status(400).json({ body: 'Body must not be empty!'});
|
|
||||||
}
|
|
||||||
|
|
||||||
const newPost = {
|
const newPost = {
|
||||||
body: req.body.body,
|
body: req.body.body,
|
||||||
userHandle: req.user.handle,
|
userHandle: req.body.userHandle,
|
||||||
userImage: req.user.imageUrl,
|
userImage: req.body.userImage,
|
||||||
|
microBlogTitle: req.body.microBlogTitle,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
likeCount: 0,
|
likeCount: 0,
|
||||||
commentCount: 0
|
commentCount: 0,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
db.collection('post').add(newPost)
|
admin.firestore().collection('posts').add(newPost)
|
||||||
.then((doc) => {
|
.then((doc) => {
|
||||||
const resPost = newPost;
|
const resPost = newPost;
|
||||||
resPost.postId = doc.id;
|
resPost.postId = doc.id;
|
||||||
return res.status(200).json(resPost);
|
return res.status(200).json(resPost);
|
||||||
|
|||||||
@ -26,6 +26,7 @@ app.post('/updateProfileInfo', updateProfileInfo);
|
|||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const {putPost} = require('./handlers/post');
|
const {putPost} = require('./handlers/post');
|
||||||
|
|
||||||
|
|
||||||
// Adds one post to the database
|
// Adds one post to the database
|
||||||
app.post('/putPost', fbAuth, putPost);
|
app.post('/putPost', fbAuth, putPost);
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import register from './Register.js';
|
|||||||
import login from './Login.js';
|
import login from './Login.js';
|
||||||
import user from './pages/user';
|
import user from './pages/user';
|
||||||
import writeMicroblog from './Writing_Microblogs.js';
|
import writeMicroblog from './Writing_Microblogs.js';
|
||||||
|
import userLine from './Userline.js';
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
render() {
|
render() {
|
||||||
@ -25,6 +26,7 @@ class App extends Component {
|
|||||||
<Route exact path="/login" component={login}/>
|
<Route exact path="/login" component={login}/>
|
||||||
<Route exact path="/user" component={user}/>
|
<Route exact path="/user" component={user}/>
|
||||||
<Route exact path="/home" component={writeMicroblog}/>
|
<Route exact path="/home" component={writeMicroblog}/>
|
||||||
|
<Route exact path="/userline" component={userLine}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</Router>
|
</Router>
|
||||||
|
|||||||
24
twistter-frontend/src/Userline.js
Normal file
24
twistter-frontend/src/Userline.js
Normal file
@ -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 (
|
||||||
|
<p>Hi</p>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Userline;
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { BrowserRouter as Router } from 'react-router-dom';
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
import Route from 'react-router-dom/Route';
|
import Route from 'react-router-dom/Route';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
|
||||||
class Writing_Microblogs extends Component {
|
class Writing_Microblogs extends Component {
|
||||||
@ -25,7 +26,20 @@ class Writing_Microblogs extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit(event) {
|
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();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user