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

Erika's Happy Thoughts API #483

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Erika's Happy Thoughts API #483

wants to merge 5 commits into from

Conversation

Tejpex
Copy link

@Tejpex Tejpex commented May 18, 2024

Netlify link

https://tejpex-happy-thoughts-api.onrender.com/

Collaborators

Add your collaborators here. Write their GitHub usernames in square brackets. If there's more than one, separate them with a comma, like this:
[github-username-1, github-username-2]

Copy link
Contributor

@HIPPIEKICK HIPPIEKICK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job and nice to see that you made it your own with the dislike endpoint. What do you think about having it as one endpoint and then using a query to specify exactly what the user wants to do? Something like:
/thoughts/mongoID?like=true
and
/thoughts/mongoID?like=false

or something, maybe with better naming. Just a thought.

Good work!

Comment on lines +16 to +22
app.use((req, res, next) => {
if (mongoose.connection.readyState === 1) {
next()
} else {
res.status(503).json({ error: "Service unavailable." })
}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

try {
const thoughts = await Thought.find().sort({ createdAt: -1 }).limit(20).exec()
if (thoughts.length > 0) {
res.json(thoughts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A status code would be nice here

}
})

app.patch("/thoughts/:id/like", async (req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice with patch 🪡

Comment on lines +89 to +91
const thought = await Thought.findByIdAndUpdate(
req.params.id,
{ $inc: { hearts: 1 } }, { new: true, runValidators: true })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +101 to +116
app.patch("/thoughts/:id/dislike", async (req, res) => {
try {
const thought = await Thought.findByIdAndUpdate(
req.params.id,
{ $inc: { hearts: -1 } },
{ new: true, runValidators: true }
)
res.status(200).json(thought)
} catch (error) {
res.status(400).json({
success: false,
response: error,
message: "Could not dislike thought.",
})
}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, love this! ⭐ ⭐ ⭐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants