Open
Conversation
HIPPIEKICK
approved these changes
Dec 18, 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"); | ||
| } | ||
| }); |
Contributor
There was a problem hiding this comment.
These should all be query params under your main endpoint to make it more RESTful.
HIPPIEKICK
previously requested changes
Dec 18, 2024
Contributor
HIPPIEKICK
left a comment
There was a problem hiding this comment.
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?
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? |
Contributor
|
No server error now, but: |
Author
|
@HIPPIEKICK now, it should be displayed 🥲 |
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://project-mongo-api-uref.onrender.com