Open
Conversation
HIPPIEKICK
approved these changes
Dec 10, 2024
Contributor
HIPPIEKICK
left a comment
There was a problem hiding this comment.
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.
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); | ||
| }); |
Contributor
There was a problem hiding this comment.
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"; | |||
Contributor
There was a problem hiding this comment.
I don't understand how your API can function when I can't see any data folder in your repo 😅
Author
There was a problem hiding this comment.
@HIPPIEKICK what do you mean exactly by not seeing a data folder? :'))

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://golden-globes-api.onrender.com