-
Notifications
You must be signed in to change notification settings - Fork 529
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
Mikas Project Express Api #534
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Impressive work Mika! Keep up the good work 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈 👏
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); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job making use of query params to be able to chain filters like this ⭐ RESTful 👍
Render link
https://mika-project-express-api.onrender.com