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

Nella: project-mongo-api #512

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

Nella: project-mongo-api #512

wants to merge 2 commits into from

Conversation

nella-x
Copy link

@nella-x nella-x commented Dec 15, 2024

Comment on lines +81 to 119
app.get("/golden-globes/winners", async (req, res) => {
try {
const winners = await GoldenGlobe.find({ win: true });
res.json(winners);
} catch (error) {
console.error("Error fetching winners:", error);
res.status(500).json({ error: "Internal server error" });
}
});

app.get("/golden-globes/category/:category", async (req, res) => {
const { category } = req.params;
try {
const nominees = await GoldenGlobe.find({ category });
if (nominees.length > 0) {
res.json(nominees);
} else {
res.status(404).json({ error: "No nominations found for this category" });
}
} catch (error) {
console.error(`Error fetching nominations for category: ${category}`, error);
res.status(500).json({ error: "Internal server error" });
}
});

app.get("/golden-globes/nominee/:nominee", async (req, res) => {
const { nominee } = req.params;
try {
const result = await GoldenGlobe.findOne({ nominee });
if (result) {
res.json(result);
} else {
res.status(404).json({ error: "Nominee not found" });
}
} catch (error) {
console.error(`Error fetching nominee: ${nominee}`, error);
res.status(500).json({ error: "Internal server error" });
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to use query params for filters to make it more RESTful. Endpoints should be named after what they return, and you're not returning categories for example, you're returning nominations or golden-globes filtered on a category

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