Skip to content

Conversation

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this file used? 👀

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

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";
Copy link
Contributor

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 😅

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? :'))
Screenshot 2024-12-11 at 11 47 34

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