Open
Conversation
added 5 commits
December 11, 2024 18:42
HIPPIEKICK
approved these changes
Dec 18, 2024
Contributor
HIPPIEKICK
left a comment
There was a problem hiding this comment.
Since the filters was a stretch goal, I'll allow that you've used separate endpoints for them instead of query params, but please think about it going forward :)
| // PORT=9000 npm start | ||
| const port = process.env.PORT || 8080; | ||
| const app = express(); | ||
| const listEndpoints = require("express-list-endpoints") |
Contributor
There was a problem hiding this comment.
Can this not be imported like your other packages? 👀
Comment on lines
+41
to
+49
| if (process.env.RESET_DB) { | ||
| const seedDatabase = async () => { | ||
| await Book.deleteMany({}); | ||
| booksData.forEach(book => { | ||
| new Book(book).save() | ||
| }) | ||
| } | ||
| seedDatabase() | ||
| } |
Contributor
There was a problem hiding this comment.
OK to remove once you've seeded your DB
| }); | ||
|
|
||
| // Route to get books by author | ||
| app.get('/books/author/:author', async (req, res) => { |
Contributor
There was a problem hiding this comment.
You're still returning books and not authors, so it would be more RESTful to put this as a query param under the /books endpoint
Comment on lines
+91
to
134
| app.get('/books/title/:title', async (req, res) => { | ||
| const { title } = req.params; // Get the title from the URL parameter | ||
| try { | ||
| const books = await Book.find({ | ||
| title: {$regex: title, $options: 'i' }}) | ||
| if (books.length === 0) { | ||
| return res.status(404).send('No books found for this author'); | ||
| } | ||
| res.json(books); | ||
| } catch (error) { | ||
| console.error('Error retrieving book', error); | ||
| res.status(500).send('Server error'); | ||
| } | ||
| }); | ||
|
|
||
| // Route to get books by isbn | ||
| app.get('/books/isbn/:isbn', async (req, res) => { | ||
| const { isbn } = req.params; | ||
| try { | ||
| const book = await Book.findOne({ isbn: isbn }); | ||
| if (!book) { | ||
| return res.status(404).send('Book not found'); | ||
| } | ||
| res.json(book); | ||
| } catch (error) { | ||
| console.error('Error retrieving book by ISBN', error); | ||
| res.status(500).send('Server error'); | ||
| } | ||
| }); | ||
|
|
||
| // Route to get books by language | ||
| app.get('/books/language/:language', async (req, res) => { | ||
| const { language } = req.params; | ||
| try { | ||
| const books = await Book.find({ language_code: language }); | ||
| if (books.length === 0) { | ||
| return res.status(404).send('No books found for this language'); | ||
| } | ||
| res.json(books); | ||
| } catch (error) { | ||
| console.error('Error retrieving books by language', error); | ||
| res.status(500).send('Server error'); | ||
| } | ||
| }); |
Contributor
There was a problem hiding this comment.
Same with these filters
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-7ch7.onrender.com/