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

Happy thoughts API #498

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

Happy thoughts API #498

wants to merge 6 commits into from

Conversation

FannyEste
Copy link

@HIPPIEKICK
Copy link
Contributor

Please share a link to your frontend as well so we can test it live 😊

@FannyEste
Copy link
Author

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! :)

https://happy-thoughts-typescript-estefanny.netlify.app/

Copy link

@JennieDalgren JennieDalgren left a 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

Comment on lines +38 to +40
// 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" });

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);

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.

Comment on lines +56 to +61
try {
const updatedThought = await Thought.findByIdAndUpdate(
thoughtId,
{ $inc: { hearts: 1 } }, // Increment hearts count
{ new: true } // Return updated document
);

Choose a reason for hiding this comment

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

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.

None yet

3 participants