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

Harry Potter express API #536

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

Conversation

Fannyhenriques
Copy link

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.

Good job with your first API Fanny! You've met the requirements, but I'd like to challenge you to think of a way to chain your filters 👀

Comment on lines +25 to +55
app.get("/harryPotterCharacters", (req, res) => {
const house = req.query.house; // Query parameter for house
const year = req.query.yearIntroduced; // Query parameter for yearIntroduced
const role = req.query.role; // Query parameter for role

// Filter by house
if (house) {
const filteredCharacters = harryPotterCharactersData.filter(character =>
character.house.toLowerCase() === house.toLowerCase()
);
res.json(filteredCharacters);
}
// Filter by role
else if (role) {
const characterRole = harryPotterCharactersData.filter(character =>
character.role.toLowerCase() === role.toLowerCase()
);
res.json(characterRole);
}
// Filter by yearIntroduced
else if (year) {
const charactersIntroducedInYear = harryPotterCharactersData.filter(character =>
character.yearIntroduced === +year
);
res.json(charactersIntroducedInYear);
}
else {
res.json(harryPotterCharactersData); // No filters = return all characters

}
});
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 filter ⭐ Could you think of a way to improve this code so that the user can filter on two things at once? E.g. /characters?role=student&year=1997

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