Skip to content

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

@HIPPIEKICK
Copy link
Contributor

Reach out to us if you need help with the deploy, otherwise, I'll wait for new changes 😊

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.

Yes! deployad och funkar. Snyggt jobbat. 💪

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