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

Nav bar #109

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
40f3538
Update README.md
Destinek Apr 3, 2023
58a30de
Merge pull request #1 from Destinek/patch-1
Destinek Apr 3, 2023
7edbec9
add new post from with bug
J-Neuwford Apr 8, 2023
5ed4a82
bug: displays posts from db but not not new posts
J-Neuwford Apr 8, 2023
c931f3a
added placeholder refresh to show new posts
J-Neuwford Apr 8, 2023
dc76593
displays newest post first
J-Neuwford Apr 8, 2023
998e412
added notation for readability
J-Neuwford Apr 9, 2023
787139b
refactored add post code
J-Neuwford Apr 10, 2023
e2119e0
Merge pull request #2 from Destinek/adding-posts-to-feed
francescoGuglielmi Apr 11, 2023
da8ca18
refactor
J-Neuwford Apr 11, 2023
3df0fe8
Merge pull request #3 from Destinek/adding-posts-to-feed
Destinek Apr 11, 2023
5d31e0f
commit for pull
kamafe Apr 11, 2023
e709056
Merge branch 'main' of https://github.com/Destinek/acebook-earth
kamafe Apr 11, 2023
9e9a56a
response type bug
J-Neuwford Apr 11, 2023
5c4bb66
can now like posts
J-Neuwford Apr 11, 2023
9b6ea30
fixed like bug
J-Neuwford Apr 12, 2023
33adf38
Merge pull request #4 from Destinek/post-likes
Destinek Apr 12, 2023
d6d071e
basic implementation of comments and basic style for a neater look
Apr 12, 2023
27056b7
Merge pull request #5 from Destinek/comments
J-Neuwford Apr 13, 2023
1a2d9c0
updated user schema and signup form
J-Neuwford Apr 13, 2023
b5bc66e
added usernames to posts
J-Neuwford Apr 13, 2023
31d9507
Merge pull request #6 from Destinek/adding-username-to-posts
francescoGuglielmi Apr 13, 2023
0707f0d
added default profile picture
J-Neuwford Apr 13, 2023
42a7986
NavBar
kamafe Apr 13, 2023
b5d69d8
Merge pull request #7 from Destinek/default_profile_pics
J-Neuwford Apr 13, 2023
766164f
navbar proper
kamafe Apr 13, 2023
ba8c315
Merge branch 'main' into nav-bar
kamafe Apr 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

In this project, you are tasked with working on an existing application. A significant part of the challenge will be to familiarise yourself with the codebase you've inherited, as you work to **improve and extend** it.

Link to Trello Board - https://trello.com/b/JFnRqonB/acebook-team-earth

## Videos

These videos complement the docs below.
Expand Down
41 changes: 40 additions & 1 deletion api/controllers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ const PostsController = {
}
const token = await TokenGenerator.jsonwebtoken(req.user_id)
res.status(200).json({ posts: posts, token: token });
console.log("hi")
});
},

Create: (req, res) => {
console.log(req.body)
const post = new Post(req.body);
post.save(async (err) => {
if (err) {
Expand All @@ -22,6 +25,42 @@ const PostsController = {
res.status(201).json({ message: 'OK', token: token });
});
},

Like: async (req, res) => {
const id = req.params.id
const post = await Post.findById(id);

if(!post) {
return res.status(404).send(`No post with ID ${id} found`)
}

const userId = req.body.userId;

// if (post.likes.includes(userId)) {
// return res.status(400).send("You have already liked this post");
// }

post.likes.push(userId);
await post.save();

res.json(post);
},

Comment: async (req, res) => {
const id = req.params.id
const post = await Post.findById(id)

if(!post) {
return res.status(404).send(`No post with ID ${id} found`)
}

const userId = req.body.userId;

post.comments.push(req.body.content);
await post.save();

res.json(post);
}
};

module.exports = PostsController;
module.exports = PostsController;
2 changes: 1 addition & 1 deletion api/controllers/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SessionsController = {
res.status(401).json({ message: "auth error" });
} else {
const token = await TokenGenerator.jsonwebtoken(user.id)
res.status(201).json({ token: token, message: "OK" });
res.status(201).json({ profilePicture: user.profilePicture, username: user.username, token: token, message: "OK" });
}
});
}
Expand Down
14 changes: 13 additions & 1 deletion api/models/post.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
const mongoose = require("mongoose");

const PostSchema = new mongoose.Schema({
message: String
author: {
type: String,
default: "User"
},
message: String,
likes: {
type: [String],
default: []
},
comments: {
type: Array,
default: []
}
});

const Post = mongoose.model("Post", PostSchema);
Expand Down
5 changes: 5 additions & 0 deletions api/models/user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const mongoose = require("mongoose");

const UserSchema = new mongoose.Schema({
username: {type: String, required: true},
email: { type: String, required: true },
password: { type: String, required: true },
profilePicture: {
type: String,
default: 'default.jpg'
}
});

const User = mongoose.model("User", UserSchema);
Expand Down
Loading