-
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
Week 17: API #531
base: master
Are you sure you want to change the base?
Week 17: API #531
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.
I might be stupid but I'm so confused about the non-existing data file 😅
Remember to make use of query params going forward, instead of creating different endpoints to filter.
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.
Is this file used? 👀
app.get("/awards/winners", (req, res) => { | ||
const winners = awardsData.filter((award) => award.win === true); | ||
res.status(200).json(winners); | ||
}); | ||
|
||
app.get("/awards", (req, res) => { | ||
const { year, category } = req.query; | ||
|
||
let filteredAwards = awardsData; | ||
|
||
if (year) { | ||
filteredAwards = filteredAwards.filter( | ||
(award) => award.year_award === parseInt(year, 10) | ||
); | ||
} | ||
|
||
if (category) { | ||
filteredAwards = filteredAwards.filter((award) => | ||
award.category.toLowerCase().includes(category.toLowerCase()) | ||
); | ||
} | ||
|
||
if (filteredAwards.length === 0) { | ||
return res.status(404).json({ error: "No awards found matching the criteria" }); | ||
} | ||
|
||
res.status(200).json(filteredAwards); | ||
}); |
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.
These endpoints could be one if you make use of another query param, such as /awards?winner=true
@@ -1,30 +1,67 @@ | |||
import express from "express"; | |||
import cors from "cors"; | |||
import awardsData from "./data/golden-globes.json"; |
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.
I don't understand how your API can function when I can't see any data folder in your repo 😅
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.
@HIPPIEKICK what do you mean exactly by not seeing a data folder? :'))
https://golden-globes-api.onrender.com