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-18-mongo-api #516

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

Conversation

erikamolsson
Copy link

Render

https://project-18-mongo-api.onrender.com/ (not working yet..)

Collaborators

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.

Code looks good, just need to see a working deploy! Let us know if you need help debugging



// Ge books based on number of pages (needs to be befor bookID otherwise that route will override this)
app.get("/books/pages", async (req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be named just /books, because that's what this endpoint is returning

Comment on lines +116 to +133
app.get("/books/authors/:author", async (req, res) => {
const author = req.params.author;

try {
// $regex = to match name and not case sensitive
const booksByAuthor = await Book.find({
authors: { $regex: author, $options: "i" }, // "i" case-insensitive
});

if (booksByAuthor.length > 0) {
res.json(booksByAuthor); // Returnera böckerna om de finns
} else {
res.status(404).json({ error: "No books found for this author" });
}
} catch (error) {
res.status(500).json({ error: "An error occurred while fetching books" });
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

And this should also be a query under your /books endpoint to make it more RESTful. Even though you're filtering on author, you still return books

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