-
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
Express API - Dog breeds - Jenny A #529
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.
app.get("/dogs", (req, res) => { | ||
const { category, size, origin, familyFriendly } = req.query; // Get all filters from query parameters | ||
console.log("Query parameters:", req.query); | ||
|
||
let filteredDogs = [...dogs]; | ||
|
||
// Start defining your routes here | ||
if (category) { | ||
filteredDogs = filteredDogs.filter(dog => | ||
dog.category.toLowerCase() === category.toLowerCase() | ||
); | ||
} | ||
if (size) { | ||
filteredDogs = filteredDogs.filter(dog => | ||
dog.size.toLowerCase() === size.toLowerCase() | ||
); | ||
} | ||
if (origin) { | ||
filteredDogs = filteredDogs.filter(dog => | ||
dog.origin.toLowerCase() === origin.toLowerCase() | ||
); | ||
} | ||
if (familyFriendly) { | ||
filteredDogs = filteredDogs.filter(dog => | ||
dog.familyFriendly.toLowerCase() === familyFriendly.toLowerCase() | ||
); | ||
} | ||
|
||
res.json(filteredDogs); | ||
}); |
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.
Excellent work making use of query params and chaining the filters like this, works like a charm ⭐
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.
Thank you for the feedback @HIPPIEKICK! Hahaha I was also really confused by the "Toy" category so I asked ChatGPT and apparently it's "the official classification for small breeds that were specifically developed to be companion pets rather than working dogs". So small lap dogs! You live and you learn 😂😂
Netlify link
https://project-express-api-y1pr.onrender.com/