Skip to content

Conversation

@mikaeber
Copy link

@mikaeber mikaeber commented Dec 8, 2024

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.

Impressive work Mika! Keep up the good work 👍

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 +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);
});
Copy link
Contributor

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 👍

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