-
Notifications
You must be signed in to change notification settings - Fork 496
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
Arnau's Happy thoughts API #488
base: master
Are you sure you want to change the base?
Conversation
…ly apears after changing to mongoUrl path save and run again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, but please consider adding a query of sorts if you want the user to be able to like 100 times at once, something like:
/thoughts/:id/like?amount=100
// increment by ${amount}
app.use((req, res, next) => { | ||
if (mongoose.connection.readyState === 1) { | ||
next(); | ||
} else { | ||
res.status(503).json({ error: "Service unavailable." }); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
app.get("/thoughts", async (req, res) => { | ||
try { | ||
const thoughts = await Thought.find().sort({ createdAt: -1 }).limit(20); | ||
res.status(200).json(thoughts); | ||
} catch (error) { | ||
res.status(400).json({ error: error.message }); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and clean endpoint 👍
const thought = await Thought.findByIdAndUpdate( | ||
thoughtId, | ||
{ $inc: { hearts: 1 } }, | ||
{ new: true } | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐
} | ||
}); | ||
|
||
app.post("/thoughts/:thoughtId/like", async (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha I love the idea with 1, 10, 100 likes, but consider dealing with that from the backend side so you don't need to call your API 100 times 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe you are right, it has to be done in the backend.
Netlify link
Backend: here
Frontend: here
Solo
[github-vidalhuix]