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

Arnau's Happy thoughts API #488

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

Conversation

vidalhuix
Copy link

@vidalhuix vidalhuix commented May 19, 2024

Netlify link

Backend: here
Frontend: here

Solo

[github-vidalhuix]

Your Name added 27 commits May 18, 2024 11:57
…ly apears after changing to mongoUrl path save and run again
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, 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}

Comment on lines +21 to +27
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.

👍

Comment on lines +61 to +68
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 });
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice and clean endpoint 👍

Comment on lines +91 to +95
const thought = await Thought.findByIdAndUpdate(
thoughtId,
{ $inc: { hearts: 1 } },
{ new: true }
);
Copy link
Contributor

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) => {
Copy link
Contributor

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 🙈

Copy link
Author

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.

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