Skip to content

Conversation

jacquelinekellyhunt
Copy link

@jacquelinekellyhunt jacquelinekellyhunt commented Dec 15, 2024

server.js Outdated
Comment on lines 77 to 121
app.get("/avocado-sales/region/:region", async (req, res) => {
const { region } = req.params;
try {
const sales = await AvocadoSale.find({ region: new RegExp(region, "i") });
if (sales.length === 0) {
return res.status(404).send("No sales data found for this region");
}
res.json(sales);
} catch (error) {
console.error("Error retrieving sales by region:", error);
res.status(500).send("Server error");
}
});

// Route to get sales by date
app.get("/avocado-sales/date/:date", async (req, res) => {
const { date } = req.params;
try {
const sales = await AvocadoSale.find({ date });
if (sales.length === 0) {
return res.status(404).send("No sales data found for this date");
}
res.json(sales);
} catch (error) {
console.error("Error retrieving sales by date:", error);
res.status(500).send("Server error");
}
});

// Route to get sales by price range
app.get("/avocado-sales/price-range", async (req, res) => {
const { min, max } = req.query;
try {
const sales = await AvocadoSale.find({
averagePrice: { $gte: Number(min) || 0, $lte: Number(max) || Infinity },
});
if (sales.length === 0) {
return res.status(404).send("No sales data found in this price range");
}
res.json(sales);
} catch (error) {
console.error("Error retrieving sales by price range:", error);
res.status(500).send("Server error");
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

These should all be query params under your main endpoint to make it more RESTful.

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.

Sorry, I was a bit quick on the button there, I can't seem to get your deployed link working 👀 Can you please have a look?

@HIPPIEKICK HIPPIEKICK dismissed their stale review December 18, 2024 11:26

Render being slow

@HIPPIEKICK
Copy link
Contributor

Sorry that I'm going back and forth (and GitHub's UI doesn't let me remove my previous comments 😅). I cannot get your deployed link to work. I get "Server error". Can you get it to work?

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.

See comment

@HIPPIEKICK
Copy link
Contributor

No server error now, but:

"error": "No sales data found with the provided filters."

@jacquelinekellyhunt
Copy link
Author

@HIPPIEKICK now, it should be displayed 🥲

Copy link
Contributor

@JennieDalgren JennieDalgren left a comment

Choose a reason for hiding this comment

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

💪

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.

3 participants