Open
Conversation
HIPPIEKICK
approved these changes
Dec 10, 2024
Contributor
HIPPIEKICK
left a comment
There was a problem hiding this comment.
Impressive work Mika! Keep up the good work 👍
Comment on lines
+18
to
+66
| app.get("/nominations", (req, res) => { | ||
| const { win, year_award, category } = req.query; | ||
|
|
||
| let filteredNominations = goldenGlobesData; | ||
|
|
||
| if (win) { | ||
| if (win !== "true" && win !== "false") { | ||
| return res | ||
| .status(400) | ||
| .json({ error: "win parameter must be 'true' or 'false'" }); | ||
| } | ||
| filteredNominations = filteredNominations.filter( | ||
| (nomination) => nomination.win === (win === "true") | ||
| ); | ||
| } | ||
|
|
||
| if (year_award) { | ||
| if (+year_award < 2015 || +year_award > 2020) { | ||
| return res.status(400).json({ | ||
| error: "Invalid year. Please enter a year between 2015 and 2020.", | ||
| }); | ||
| } | ||
| filteredNominations = filteredNominations.filter( | ||
| (nomination) => nomination.year_award === parseInt(year_award) | ||
| ); | ||
| } | ||
|
|
||
| if (category) { | ||
| const searchTerms = category.toLowerCase().split(" "); | ||
| filteredNominations = filteredNominations.filter((nomination) => | ||
| searchTerms.every((term) => | ||
| nomination.category.toLowerCase().includes(term) | ||
| ) | ||
| ); | ||
|
|
||
| if (filteredNominations.length === 0) { | ||
| return res.status(404).json({ | ||
| error: "No nominations found. Please enter a valid category.", | ||
| }); | ||
| } | ||
| } | ||
| if (filteredNominations.length === 0) { | ||
| return res | ||
| .status(404) | ||
| .json({ error: "No nominations found with chosen filters" }); | ||
| } | ||
|
|
||
| res.json(filteredNominations); | ||
| }); |
Contributor
There was a problem hiding this comment.
Nice job making use of query params to be able to chain filters like this ⭐ RESTful 👍
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.
Render link
https://mika-project-express-api.onrender.com