-
Notifications
You must be signed in to change notification settings - Fork 517
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
Happy thoughts API #498
base: master
Are you sure you want to change the base?
Happy thoughts API #498
Conversation
Please share a link to your frontend as well so we can test it live 😊 |
Hi Matilda! sure! I think is this one? I think that I accidentally posted the link to the PR and not the frontend, I hopw its correct now! :) |
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.
Great job! The project is approved
// Validate the message length | ||
if (!message || message.length < 5 || message.length > 140) { | ||
return res.status(400).json({ error: "Message must be between 5 and 140 characters" }); |
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.
⭐
// GET /thoughts - Retrieve 20 most recent thoughts | ||
app.get("/thoughts", async (req, res) => { | ||
try { | ||
const thoughts = await Thought.find().sort({ createdAt: -1 }).limit(20); |
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.
createdAt: "desc"
would be another way to sort the thoughts.
try { | ||
const updatedThought = await Thought.findByIdAndUpdate( | ||
thoughtId, | ||
{ $inc: { hearts: 1 } }, // Increment hearts count | ||
{ new: true } // Return updated document | ||
); |
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.
⭐
https://project-happy-thoughts-api-estefanny.onrender.com