Skip to content

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.

3 participants