Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Mongo API #510

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open

Project Mongo API #510

wants to merge 41 commits into from

Conversation

joheri1
Copy link

@joheri1 joheri1 commented Dec 14, 2024

… This endpoint returns the complete list of elves from the elves database
… on title, find unique id, and testing the server. Mongoose has not been implemented on those endpoints yet.
… for this project. Change package.json to copy all files from folder Data to dist
…_code or languages. Update the Mongoode model.
…int using query params. Limit to get the top twelve, and filter to find the title.
…gic. REmove the old dist folder and create a new one.
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.

Solid work, Johanna, keep it up 👍

Comment on lines +87 to +109
app.get("/elves", async (request, response) => {
try {
const { title, top_twelves } = request.query;
const query = {};

// Filter based on query params
if (title) {
// Case insensitive by using Regular Expression
query.title = new RegExp(title, "i");
}

// Limit to get the top 12 elves, the "TwElves", if "top_twelves=true"
const limit = top_twelves === "true" ? 12 : 0;
const elves = await Elf.find(query)
.sort({ elfID: 1 }) // Sort elfID in ascending order (1 for ascending, -1 for descending)
.limit(limit);

response.json(elves);

} catch (error) {
response.status(500).json({ error: "Failed to fetch elves" });
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Well done using query params, RESTful 💯

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