Skip to content

Conversation

@jempa182
Copy link

@jempa182 jempa182 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.

Good job creating a RESTful API Jenny. Looks super! Impressive work with chaining the filters as well as implementing error handling. Just remember to clean up the code when you're done (remove console.logs)


This is not part of the review, but what the hell kind of category is this 😂 😭
Skärmavbild 2024-12-10 kl  14 48 28

Comment on lines +34 to +62
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);
});
Copy link
Contributor

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 ⭐

Copy link
Author

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 😂😂

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