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

Feature/post feed #57

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0b00fdf
adding comments
alexHoggett Feb 7, 2023
6b74edc
added navbar folder
alexHoggett Feb 8, 2023
1dccb08
added navbar.js
alexHoggett Feb 8, 2023
bda298d
implemented add post ticket with post form component
Feb 8, 2023
e74409c
navbar login logout function
josh-p-git Feb 8, 2023
c66a459
Test passed for new user fields in model
amh4 Feb 8, 2023
868f5bf
added comments to the postForm component
Feb 9, 2023
df8ce63
more coments added to the code
Feb 9, 2023
e47b4fb
completed navbar component
alexHoggett Feb 9, 2023
561b9ba
Test passed for new user schema
amh4 Feb 9, 2023
4dee02c
cypress tests add
Feb 9, 2023
043dd69
added some basic tests for the navbar component
alexHoggett Feb 9, 2023
389baa6
Seeded users to the user collection
rachelnewby Feb 9, 2023
55313b6
finished mvp navbar
alexHoggett Feb 9, 2023
eff760e
Updated tests based on new schema
amh4 Feb 9, 2023
290497d
change button class name
Feb 9, 2023
90c4574
Merge pull request #2 from alexHoggett/feature/add-navbar
amh4 Feb 9, 2023
543f431
Merge branch 'main' into add-post
amh4 Feb 9, 2023
401d310
Merge pull request #1 from alexHoggett/add-post
amh4 Feb 9, 2023
2130be8
Pull request for Seed Setup
amh4 Feb 9, 2023
37f8fff
Rename navbar.js to Navbar.js
alexHoggett Feb 9, 2023
59ef14d
added a comment ad navbar file
santosluizfelipe Feb 9, 2023
8996201
Merge branch 'main' into feature/add-other-users-to-friends-list
alexHoggett Feb 9, 2023
1ccde4d
fixed package-lock
alexHoggett Feb 9, 2023
2387f92
Merge branch 'main' into feature/add-other-users-to-friends-list
alexHoggett Feb 9, 2023
f7f768c
Merge pull request #3 from alexHoggett/feature/add-other-users-to-fri…
alexHoggett Feb 9, 2023
2b7c73d
first attempt to implement the delete method
santosluizfelipe Feb 9, 2023
08afacc
delete post working
santosluizfelipe Feb 9, 2023
f24d3b4
updating tests for updated post models
alexHoggett Feb 10, 2023
aeabef1
post controller tests
josh-p-git Feb 10, 2023
e2fc9b4
added the delete feature for the posts
santosluizfelipe Feb 10, 2023
4c16a53
addded 1 comment on the post.js file
santosluizfelipe Feb 10, 2023
01cfbb3
add tests
Feb 10, 2023
5b384e5
Merge pull request #4 from alexHoggett/post-delete
santosluizfelipe Feb 10, 2023
2831a89
Merge branch 'main' into feature/post-feed
alexHoggett Feb 10, 2023
8654101
removed logout
alexHoggett Feb 10, 2023
69bb87e
tetsing
alexHoggett Feb 10, 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 modified .DS_Store
Binary file not shown.
15 changes: 14 additions & 1 deletion api/controllers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ const PostsController = {
res.status(201).json({ message: 'OK', token: token });
});
},
};

Delete: async (req, res) => {
const postId = req.params.id;
try {
await Post.deleteOne({ _id: postId });
const token = await TokenGenerator.jsonwebtoken(req.user_id);
res
.status(200)
.json({ message: 'Post deleted successfully', token: token });
} catch (err) {
res.status(500).json({ error: err.message });
}
},
};

module.exports = PostsController;
3 changes: 3 additions & 0 deletions api/controllers/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ const SessionsController = {

User.findOne({ email: email }).then(async (user) => {
if (!user) {
// if the user doesn't exist in the db
console.log("auth error: user not found")
res.status(401).json({ message: "auth error" });
} else if (user.password !== password) {
// if the passwords don't match
console.log("auth error: passwords do not match")
res.status(401).json({ message: "auth error" });
} else {
// successful login, generate a new token and assign it to that user_id
const token = await TokenGenerator.jsonwebtoken(user.id)
res.status(201).json({ token: token, message: "OK" });
}
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const UsersController = {
const user = new User(req.body);
user.save((err) => {
if (err) {
// if account already exists
res.status(400).json({message: 'Bad request'})
} else {
// account does not already exist
res.status(201).json({ message: 'OK' });
}
});
Expand Down
7 changes: 5 additions & 2 deletions api/models/post.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const mongoose = require("mongoose");

const PostSchema = new mongoose.Schema({
message: String
content: { type: String, required: true },
date_created: { type: Date, required: true },
user_id: { type: Number, required: true },
likes: { type: Number, required: true }
});

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

module.exports = Post;
module.exports = Post;
3 changes: 3 additions & 0 deletions api/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const mongoose = require("mongoose");
const UserSchema = new mongoose.Schema({
email: { type: String, required: true },
password: { type: String, required: true },
firstName: { type: String, required: true },
surname: { type: String, required: true },
friendsList: [{type: Number}]
});

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