Conversation
HIPPIEKICK
approved these changes
Dec 18, 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" }); | ||
| } | ||
| }); |
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://project-mongo-api-jg3l.onrender.com/