Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tanya #457

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open

Tanya #457

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
702ec9c
Update README.md
CarolineGibson0307 Jan 3, 2023
63fc9b4
homepage
t4nn Jan 4, 2023
8a53079
Merge pull request #1 from CarolineGibson0307/Tanya
t4nn Jan 4, 2023
0fcd940
edits
t4nn Jan 5, 2023
6c57819
Merge pull request #2 from CarolineGibson0307/Tanya
t4nn Jan 5, 2023
a0db665
adds a like button
andr3wnguyen Jan 6, 2023
41f9db7
Merge pull request #3 from CarolineGibson0307/andy
andr3wnguyen Jan 6, 2023
c67a206
Add love button and redirects for sign-up
CarolineGibson0307 Jan 6, 2023
e6acd23
Merge pull request #4 from CarolineGibson0307/Caroline
CarolineGibson0307 Jan 6, 2023
d3ea393
updates to login/signup
andr3wnguyen Jan 9, 2023
8aebefa
Merge pull request #5 from CarolineGibson0307/andy
andr3wnguyen Jan 9, 2023
c277e95
Added usernames/ follow/ redirects for sign ins?
CarolineGibson0307 Jan 9, 2023
63cac43
test
CarolineGibson0307 Jan 9, 2023
d660463
test
CarolineGibson0307 Jan 9, 2023
6379290
test2
CarolineGibson0307 Jan 9, 2023
2533060
Merge pull request #6 from CarolineGibson0307/Caroline
CarolineGibson0307 Jan 9, 2023
9ab2ccc
adding friends
CarolineGibson0307 Jan 9, 2023
847cf48
Merge pull request #7 from CarolineGibson0307/Caroline
CarolineGibson0307 Jan 9, 2023
b9acb0a
friends page and adding friends
andr3wnguyen Jan 10, 2023
6403965
Merge pull request #8 from CarolineGibson0307/andrew
andr3wnguyen Jan 10, 2023
847f7fc
sessionChecker added so friends list can function properly
andr3wnguyen Jan 10, 2023
2591cc1
Merge pull request #9 from CarolineGibson0307/andydrew
andr3wnguyen Jan 10, 2023
baeec10
css stuff
t4nn Jan 10, 2023
b815659
Merge branch 'main' into Tanya
t4nn Jan 10, 2023
17768fe
Merge pull request #10 from CarolineGibson0307/Tanya
t4nn Jan 10, 2023
239cefe
Revert "css stuff"
andr3wnguyen Jan 10, 2023
d9b4280
Merge pull request #11 from CarolineGibson0307/revert-10-Tanya
andr3wnguyen Jan 10, 2023
ce81a86
implementations of unfollow button/changes to follow and an explore page
andr3wnguyen Jan 11, 2023
1879ff5
Merge pull request #12 from CarolineGibson0307/pandy
andr3wnguyen Jan 11, 2023
e517cb7
tanyas css/styling
andr3wnguyen Jan 11, 2023
8d6ef79
Merge pull request #13 from CarolineGibson0307/pandrew
andr3wnguyen Jan 11, 2023
e5c5ee8
buttons
t4nn Jan 11, 2023
ddf1a16
Merge pull request #14 from CarolineGibson0307/Tanya
t4nn Jan 11, 2023
03380cb
c
t4nn Jan 11, 2023
8355fbd
Merge pull request #15 from CarolineGibson0307/Tanya
t4nn Jan 11, 2023
364418d
comments and banner
andr3wnguyen Jan 12, 2023
f18c856
Merge pull request #16 from CarolineGibson0307/and
andr3wnguyen Jan 12, 2023
ad4e5a1
upload photos
t4nn Jan 12, 2023
2d2ba9e
layout
t4nn Jan 13, 2023
b1a9128
lay out
t4nn Jan 13, 2023
4fd91ed
pushed
t4nn Jan 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It uses:

## Card wall

REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL
(https://trello.com/b/9wjGVeJU/kittens)

## Quickstart

Expand Down
7 changes: 7 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const homeRouter = require("./routes/home");
const postsRouter = require("./routes/posts");
const sessionsRouter = require("./routes/sessions");
const usersRouter = require("./routes/users");
const friendsRouter = require("./routes/friends");

const app = express();

Expand Down Expand Up @@ -56,8 +57,14 @@ const sessionChecker = (req, res, next) => {
// route setup
app.use("/", homeRouter);
app.use("/posts", sessionChecker, postsRouter);
app.use("posts/explore", sessionChecker, postsRouter); //do we need this for it to work?
app.use("/sessions", sessionsRouter);
app.use("/users", usersRouter);
app.use("/friends", sessionChecker, friendsRouter) //added SC to check user is logged in

//posts router to listen to a post request to the id/act
app.use("/posts/:id/act", postsRouter)
//app.use("/users/:id/befriend", postsRouter)

// catch 404 and forward to error handler
app.use((req, res, next) => {
Expand Down
Empty file added car.txt
Empty file.
19 changes: 19 additions & 0 deletions controllers/friends.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const User = require("../models/user");


const FriendsController = {
Index: (req, res) => {
const user = req.session.user.username
User.find({username: user}, { friends: 1 }, (err, friendsArray) => {
if (err) {
throw err

}
//console.log(friendsArray[0].friends) - the find returns a list of objects which includes ids as well
//list of friends to be sent as an argument - this needs usercontroller and a method to list it
res.render("friends/index", { title: "Furrends", shownavbar:true, friendslist:friendsArray[0], user:user });
})
}
}

module.exports = FriendsController;
2 changes: 1 addition & 1 deletion controllers/home.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const HomeController = {
Index: (req, res) => {
res.render("home/index", { title: "Acebook" });
res.render("home/index", { title: "Acebook", shownavbar:false });
},
};

Expand Down
133 changes: 127 additions & 6 deletions controllers/posts.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,149 @@
const Post = require("../models/post");
const User = require("../models/user");

const PostsController = {
Index: (req, res) => {
//do we only see posts from users that are friends? yes
const postIds = req.params.id
console.log(postIds)
// const postauthor = Post.findOne({ _id: })
const user = req.session.user
const friendsList = user.friends
friendsList.push(user.username)
Post.find({author: {$in: friendsList}},(err, posts) => {

if (err) {
throw err;
}
posts = posts.sort((a,b) => b.date-a.date ) //sorts the posts by date order before rendering
res.render("posts/index", { posts: posts, shownavbar:true, user: user});
});
},
Explore: (req, res) => {
//page to see all posts make it happen
const user = req.session.user
Post.find((err, posts) => {
if (err) {
throw err;
}

res.render("posts/index", { posts: posts });
});
posts = posts.sort((a,b) => b.date-a.date ) //sorts the posts by date order before rendering
res.render("posts/explore", { posts: posts, shownavbar:true, user: user});
});
},

New: (req, res) => {
res.render("posts/new", {});
res.render("posts/new", {shownavbar:true});
},

Create: (req, res) => {
const post = new Post(req.body);
const post = new Post({message:req.body.message,author:req.session.user.username,image:req.body.photoURL.trim()});
post.save((err) => {
if (err) {
throw err;
}

res.status(201).redirect("/posts");
});
},
//added a like object that has an anonymous f(x) for the PostController 'class'
//this should send a post request to update the db using the postID retrieved from the
Like: (req, res) => {
const postId = req.params.id;
const action = req.body.action;
if (action === 'Like') {
Post.updateOne({ _id: postId }, { $inc: { likes: 1 } }, function (error) {
if (error) {
res.send(error);
console.log(error)
} else {
console.log('like updated')
res.send('Like added');
}
});
} else if (action === 'Unlike') {
Post.updateOne({ _id: postId }, { $inc: { likes: -1 } }, function (error) {
if (error) {
res.send(error);
} else {
res.send('Unlike added');
}
});
}
},

Love: (req, res) => {
const postId = req.params.id;
const action = req.body.action;
if (action === 'Love') {
Post.updateOne({ _id: postId }, { $inc: { loves: 1 } }, function (error) {
if (error) {
res.send(error);
console.log(error)
} else {
console.log('love updated')
res.send('Love added');
}
});
} else if (action === 'Hate') {
Post.updateOne({ _id: postId }, { $inc: { loves: -1 } }, function (error) {
if (error) {
res.send(error);
} else {
res.send('Hate added');
}
});
}
},
//added a follow object THIS IS ACTUALLY A MESS ATM
Follow: (req,res) => {
//const postId = req.params.id;
const usersname = req.body.main //gets the main user (user who's friend list is created)
// console.log(req.param.id)
// console.log(req.body.friend)
// console.log(req.body.action)
// console.log(req.body.main)
const friend = req.body.friend; //get friend to add from the post req body
const action = req.body.action; //get action
if (action === 'Follow') {
//use addToSet because want unique values to be added only
User.updateOne({ username: usersname }, {$addToSet:{ friends: friend}}, function (error) {
if (error) {
res.send(error);
console.log(error)
} else {
console.log('Followed');
}
});
} else if (action === 'Unfollow') {
User.updateOne({ username: usersname }, { $pull: { friends: friend } }, function (error) {
if (error) {
res.send(error);
} else {
console.log('Unfollowed');
}
});
}

},
Comment: (req, res) => {

// const usersname = req.body.main //gets the main user (user who's friend list is created)
// const friend = req.body.friend; //get friend to add from the post req body
// const action = req.body.action; //get action
const postId = req.params.id
const comment = req.body.comment
const commenter = req.session.user.username
const commentObject = {comment:comment, user:commenter}
Post.updateOne({ _id: postId }, {$push: {comments:commentObject}}, {new:true}, function
(error) {
if (error) {
res.send(error);
console.log(error)
}

});
res.status(201).redirect("/posts");
}
};


module.exports = PostsController;
10 changes: 7 additions & 3 deletions controllers/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const User = require("../models/user");

const SessionsController = {
New: (req, res) => {
res.render("sessions/new", {});
res.render("sessions/new", {shownavbar:false});
},

Create: (req, res) => {
Expand All @@ -11,10 +11,14 @@ const SessionsController = {
const password = req.body.password;

User.findOne({ email: email }).then((user) => {
//if user doesn't exist in the db, redirects to /new which creates a new account
if (!user) {
res.redirect("/sessions/new");
var wronguser = true;
res.render("home/index", {wronguser});
//if the userpassword doesn't match it redirects
} else if (user.password != password) {
res.redirect("/sessions/new");
var wrongpass = true;
res.render("home/index",{wrongpass});
} else {
req.session.user = user;
res.redirect("/posts");
Expand Down
41 changes: 32 additions & 9 deletions controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,41 @@ const User = require("../models/user");

const UsersController = {
New: (req, res) => {
res.render("users/new", {});
res.render("users/new", {shownavbar:true});
},

Create: (req, res) => {
const user = new User(req.body);
user.save((err) => {
const newuser = new User(req.body);
const email = req.body.email
const username = req.body.username
User.findOne({ email: email }).then((user) => {
//if user doesn't exist in the db, redirects to /new which creates a new account
if (!user) {
User.findOne({ username: username }).then((name) => {
if (!name) {
newuser.save((err) => {
if (err) {
throw err;
}
res.status(201).redirect("/posts");
});
},
};
var accountCreated = true;
res.render("home/index", {accountCreated})
})}
else
{
console.log('User already exists!')
var usernameExists = true;
res.render("home/index", {usernameExists})
}
})}
//if user email and name doesn't exist, save it
else
{
console.log('User already exists!')
var emailExists = true;
res.render("home/index", {emailExists})
}
})
}
}


module.exports = UsersController;
module.exports = UsersController;
16 changes: 14 additions & 2 deletions models/post.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
const mongoose = require("mongoose");


const PostSchema = new mongoose.Schema({
message: String,
likes: { type: Number, default: 0 }
message: {type:String, required:true},
author: {type:String, required:true}, //required true means it is needed when a post is created, we can then pass an objecrt including user info to the new post initialisation.
likes: { type: Number, default: 0 },
loves: { type: Number, default: 0 },
date: { type: Date, default:Date.now },
image: {type:String},
comments: [{
date: { type: Date, default: Date.now },
comment: {type: String},
user: {type:String}
}]

});


const Post = mongoose.model("Post", PostSchema);

module.exports = Post;
16 changes: 14 additions & 2 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
const mongoose = require("mongoose");

const UserSchema = new mongoose.Schema({
email: String,
username: {type: String, unique: true},
email: {type: String, unique: true},
password: String,
profilepic: {type:String},
friends: {type: [String], default: []}
});

const User = mongoose.model("User", UserSchema);
//const friend = new User({username: "Kitten", email: "kitten@kitten.com", password: "password "})
//friend.friends.push("Steve")

module.exports = User;
//friend.save()
// User.findOneAndUpdate(
// { _id: "63bc4bc14dbd82782c7cc65c" },
// { $push: {
// friends : "Steve"
// }
// })
module.exports = User;
Binary file added public/.DS_Store
Binary file not shown.
Binary file added public/images/.DS_Store
Binary file not shown.
Binary file added public/images/Catbook.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/favicon.ico
Binary file not shown.
Binary file added public/images/paw.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading