mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 18:28:47 +00:00
connected backend to frontend for writing microblogs
This commit is contained in:
parent
b1faacd312
commit
55dc62e57e
@ -1,15 +1,13 @@
|
|||||||
const admin = require('firebase-admin');
|
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.body.userHandle,
|
userHandle: req.body.userHandle,
|
||||||
userImage: req.body.userImage,
|
userImage: req.body.userImage,
|
||||||
title: req.body.title,
|
microBlogTitle: req.body.microBlogTitle,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
likeCount: 0,
|
likeCount: 0,
|
||||||
commentCount: 0,
|
commentCount: 0,
|
||||||
|
|||||||
@ -19,7 +19,8 @@ const {
|
|||||||
|
|
||||||
|
|
||||||
// post routes
|
// post routes
|
||||||
app.post('/putPost', FBauth, putPost);
|
//app.post('/putPost', FBauth, putPost);
|
||||||
|
app.post('/putPost', putPost);
|
||||||
|
|
||||||
// users routes
|
// users routes
|
||||||
app.get('/getUser/:handle', getUserDetails);
|
app.get('/getUser/:handle', getUserDetails);
|
||||||
|
|||||||
@ -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;
|
||||||
@ -27,12 +27,19 @@ 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 = await axios.post(
|
|
||||||
|
const response = axios.post(
|
||||||
'http://localhost:5001/twistter-e4649/us-central1/api/putPost',
|
'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'} }
|
{ headers: { 'Content-Type': 'application/json'} }
|
||||||
)
|
)
|
||||||
console.log(response.data);
|
console.log(response.data);
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user