Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"@babel/core": "^7.17.9",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.16.11",
"@babel/core": "^7.26.0",
"@babel/node": "^7.26.0",
"@babel/preset-env": "^7.26.0",
"cors": "^2.8.5",
"express": "^4.17.3",
"nodemon": "^3.0.1"
"express": "^4.21.2",
"express-list-endpoints": "^7.1.1",
"nodemon": "^3.1.7"
}
}
6 changes: 0 additions & 6 deletions pull_request_template.md

This file was deleted.

40 changes: 40 additions & 0 deletions routes/awards.js
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? 👀

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import express from 'express';
import awards from '../data/golden-globes.json';

const router = express.Router();

router.get('/', (req, res) => {
const { year, category, winner } = req.query;
let filteredAwards = awards;

if (year) {
filteredAwards = filteredAwards.filter((award) => award.year_award == year);
}
if (category) {
filteredAwards = filteredAwards.filter((award) =>
award.category.toLowerCase().includes(category.toLowerCase())
);
}
if (winner) {
filteredAwards = filteredAwards.filter(
(award) => award.win.toString() === winner
);
}

res.json(filteredAwards);
});

router.get('/:id', (req, res) => {
const id = parseInt(req.params.id, 10);
if (id >= 0 && id < awards.length) {
res.json(awards[id]);
} else {
res.status(404).json({ error: 'Award not found' });
}
});

router.post('/dummy-endpoint', (req, res) => {
res.status(501).json({ message: 'This endpoint is under construction.' });
});

export default router;
69 changes: 53 additions & 16 deletions server.js
Original file line number Diff line number Diff line change
@@ -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

import listEndpoints from "express-list-endpoints";

// If you're using one of our datasets, uncomment the appropriate import below
// to get started!
// import avocadoSalesData from "./data/avocado-sales.json";
// import booksData from "./data/books.json";
// import goldenGlobesData from "./data/golden-globes.json";
// import netflixData from "./data/netflix-titles.json";
// import topMusicData from "./data/top-music.json";

// Defines the port the app will run on. Defaults to 8080, but can be overridden
// when starting the server. Example command to overwrite PORT env variable value:
// PORT=9000 npm start
const port = process.env.PORT || 8080;
const port = process.env.PORT || 3000;
const app = express();

// Add middlewares to enable cors and json body parsing
app.use(cors());
app.use(express.json());

// Start defining your routes here
app.get("/", (req, res) => {
res.send("Hello Technigo!");
const endpoints = listEndpoints(app).map((endpoint) => ({
path: endpoint.path,
methods: endpoint.methods,
middlewares: endpoint.middlewares || ["anonymous"],
}));

res.json({
message: "Welcome to the Golden Globes API!",
endpoints: endpoints,
});
});

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


app.get("/awards/:id", (req, res) => {
const id = parseInt(req.params.id, 10);
const award = awardsData[id];

if (award) {
res.status(200).json(award);
} else {
res.status(404).json({ error: "Award not found" });
}
});

// Start the server
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});