mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
work
This commit is contained in:
parent
6dbca16ace
commit
cc20e30990
@ -50,7 +50,7 @@ exports.getPost = (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.likePost = (req, res) => {
|
exports.likePost = (req, res) => {
|
||||||
let postData;
|
|
||||||
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.userData.handle)
|
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.userData.handle)
|
||||||
.where('postId', '==', req.params.postId).limit(1);
|
.where('postId', '==', req.params.postId).limit(1);
|
||||||
|
|
||||||
@ -59,16 +59,15 @@ exports.likePost = (req, res) => {
|
|||||||
likeDoc.get()
|
likeDoc.get()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.empty) {
|
if (data.empty) {
|
||||||
return admin.firestore().collection('likes').add({
|
admin.firestore().collection('likes').add({
|
||||||
postId : req.params.postId,
|
postId : req.params.postId,
|
||||||
userHandle: req.userData.handle
|
userHandle: req.userData.handle
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
postData.likeCount++;
|
return postDoc.update({likeCount : firebase.firestore.FieldValue.increment(1) })
|
||||||
return postDoc.update({likeCount : postData.likeCount})
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return res.status(200).json(postData);
|
return res.status(200).json(postDoc);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -114,6 +113,30 @@ exports.unlikePost = (re, res) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.quotePost = (req, res) => {
|
||||||
|
|
||||||
|
const likeDoc = admin.firestore().collection('posts').where('postId', '==', req.params.postId).limit(1);
|
||||||
|
|
||||||
|
const quotedPost = {
|
||||||
|
quotingUser : req.userData.handle,
|
||||||
|
quotedAt: new Date().toISOString(),
|
||||||
|
body: req.body.body,
|
||||||
|
|
||||||
|
}
|
||||||
|
admin.firestore().collection('posts').add(quotedPost)
|
||||||
|
.then((doc) => {
|
||||||
|
const resPost = quotedPost;
|
||||||
|
resPost.postId = doc.id;
|
||||||
|
return res.status(200).json(resPost);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({error: 'Something is wrong'});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.getallPostsforFeed = (req, res) => {
|
exports.getallPostsforFeed = (req, res) => {
|
||||||
admin.firestore().collection('posts').get()
|
admin.firestore().collection('posts').get()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
|||||||
@ -44,7 +44,7 @@ app.get("/user", fbAuth, getAuthenticatedUser);
|
|||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const { getallPostsforUser, putPost, getPost, getallPostsforFeed, likePost, unlikePost
|
const { getallPostsforUser, putPost, getPost, getallPostsforFeed, likePost, unlikePost, quotePost
|
||||||
} = require("./handlers/post");
|
} = require("./handlers/post");
|
||||||
|
|
||||||
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||||
@ -54,6 +54,8 @@ app.get("/getallPostsforFeed", fbAuth, getallPostsforFeed);
|
|||||||
app.get("/putPost/:postId", fbAuth, getPost);
|
app.get("/putPost/:postId", fbAuth, getPost);
|
||||||
app.get("/putPost/:postId/like", fbAuth, likePost);
|
app.get("/putPost/:postId/like", fbAuth, likePost);
|
||||||
app.get("/putPost/:postId/unlike", fbAuth, unlikePost);
|
app.get("/putPost/:postId/unlike", fbAuth, unlikePost);
|
||||||
|
app.post("/putPost/:postId/quote", fbAuth, quotePost);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Adds one post to the database
|
// Adds one post to the database
|
||||||
|
|||||||
16
twistter-frontend/package-lock.json
generated
16
twistter-frontend/package-lock.json
generated
@ -3121,6 +3121,11 @@
|
|||||||
"merge": "^1.2.0"
|
"merge": "^1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"exenv": {
|
||||||
|
"version": "1.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/exenv/-/exenv-1.2.2.tgz",
|
||||||
|
"integrity": "sha1-KueOhdmJQVhnCwPUe+wfA72Ru50="
|
||||||
|
},
|
||||||
"exit-hook": {
|
"exit-hook": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-1.1.1.tgz",
|
||||||
@ -7270,6 +7275,17 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz",
|
||||||
"integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA=="
|
"integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA=="
|
||||||
},
|
},
|
||||||
|
"react-modal": {
|
||||||
|
"version": "3.11.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-modal/-/react-modal-3.11.1.tgz",
|
||||||
|
"integrity": "sha512-8uN744Yq0X2lbfSLxsEEc2UV3RjSRb4yDVxRQ1aGzPo86QjNOwhQSukDb8U8kR+636TRTvfMren10fgOjAy9eA==",
|
||||||
|
"requires": {
|
||||||
|
"exenv": "^1.2.0",
|
||||||
|
"prop-types": "^15.5.10",
|
||||||
|
"react-lifecycles-compat": "^3.0.0",
|
||||||
|
"warning": "^4.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"react-overlays": {
|
"react-overlays": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-overlays/-/react-overlays-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-overlays/-/react-overlays-1.2.0.tgz",
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
"react-bootstrap": "^1.0.0-beta.14",
|
"react-bootstrap": "^1.0.0-beta.14",
|
||||||
"react-dom": "^16.9.0",
|
"react-dom": "^16.9.0",
|
||||||
"react-dropdown": "^1.6.4",
|
"react-dropdown": "^1.6.4",
|
||||||
|
"react-modal": "^3.11.1",
|
||||||
"react-redux": "^7.1.1",
|
"react-redux": "^7.1.1",
|
||||||
"react-router-dom": "^5.1.0",
|
"react-router-dom": "^5.1.0",
|
||||||
"react-scripts": "0.9.5",
|
"react-scripts": "0.9.5",
|
||||||
|
|||||||
@ -9,38 +9,33 @@ class Like extends Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
like : false,
|
like : false,
|
||||||
Id : null
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit = post => {
|
handleSubmit(){
|
||||||
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
like: !this.state.like
|
like: !this.state.like
|
||||||
});
|
});
|
||||||
|
|
||||||
axios.get("https://us-central1-twistter-e4649.cloudfunctions.net/api/getallPostsforFeed")
|
|
||||||
.then((res) => {
|
const postId = "AJdhYAE4diocF8UcrHDq"
|
||||||
const postData = res.data;
|
|
||||||
this.setState({Id: postData.id})
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
if(this.state.like == false)
|
if(this.state.like == false)
|
||||||
{
|
{
|
||||||
|
axios.get(`/putPost/${postId}/like`)
|
||||||
axios.get(`/putPost/${this.state.Id}/like`)
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res.data);
|
console.log(res.data);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
axios.get(`/putPost/${this.state.Id}/unlike`)
|
axios.get(`/putPost/${postId}/unlike`)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res.data);
|
console.log(res.data);
|
||||||
})
|
})
|
||||||
|
|||||||
@ -2,6 +2,8 @@ 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';
|
import axios from 'axios';
|
||||||
|
import Modal from "react-modal";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -11,7 +13,7 @@ class Quote extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
value : ''
|
post: null
|
||||||
};
|
};
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
this.handleSubmit2 = this.handleSubmit2.bind(this);
|
this.handleSubmit2 = this.handleSubmit2.bind(this);
|
||||||
@ -19,11 +21,48 @@ class Quote extends Component {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit() {
|
handleSubmit2() {
|
||||||
|
const postId = "AJdhYAE4diocF8UcrHDq";
|
||||||
|
const postNoComment = {
|
||||||
|
body : ""
|
||||||
|
}
|
||||||
|
const headers = {
|
||||||
|
headers: { 'Content-Type': 'application/json'}
|
||||||
|
}
|
||||||
|
|
||||||
|
axios.post(`/putPost/${postId}/quote`, postNoComment, headers)
|
||||||
|
.then((res) =>{
|
||||||
|
alert('Quoting was successful!')
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
alert('An error occured.');
|
||||||
|
console.error(err);
|
||||||
|
})
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit2() {
|
handleSubmit() {
|
||||||
|
const postId = "AJdhYAE4diocF8UcrHDq";
|
||||||
|
const postComment = {
|
||||||
|
body : ""
|
||||||
|
}
|
||||||
|
const headers = {
|
||||||
|
headers: { 'Content-Type': 'application/json'}
|
||||||
|
}
|
||||||
|
|
||||||
|
axios
|
||||||
|
.post(`/putPost/${postId}/quote`, postComment, headers)
|
||||||
|
.then((res) =>{
|
||||||
|
alert('Quoting was successful!')
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
alert('An error occured.');
|
||||||
|
console.error(err);
|
||||||
|
})
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user