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

Project express api - deployed on Render - Emelie Nyberg #521

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

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