Skip to content

Conversation

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

Great job on creating your first RESTful API! You've done some nice filtering, just remember that sorting can be included as a query param as well (to keep it more RESTful).

Keep up the good work!

Comment on lines +60 to 63
app.get("/videogames/sorted/ratings", (req, res) => {
const sortedGames = videogames.sort((a, b) => b.rating - a.rating);
res.json(sortedGames);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be another query param: ?sortOnRate=descending or something

Comment on lines +22 to +43
app.get("/videogames", (req, res) => {
const category = req.query.category;
const year = req.query.year;

// Filter on category if category is sent
// For example http://localhost:3000/videogames?category=racing
if (category) {
const filterCategory = videogames.filter(game => game.category.toLowerCase() === category);
res.json(filterCategory);

// Endpoint that returns a specific year
// For example http://localhost:3000/videogames?year=2020
} if (year) {
const videogameByYear = videogames.filter(game => game.release_year === +year);
res.json(videogameByYear);

// If no categori is sent, return all videogames
// For example http://localhost:3000/videogames
} else {
res.json(videogames);
};
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent filtering!

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