mufidu / booku

0 stars 1 forks source link

Sweep: Create get books by author endpoint #60

Closed mufidu closed 5 months ago

mufidu commented 5 months ago

Details

So that client can create separate pages for authors, displaying their list of books. Don't create new file for the new router, add the new router to app.js. Create unit test for the newly created endpoint.

Checklist - [X] Modify `app.js` ✓ https://github.com/mufidu/booku/commit/cc192f07c3d49f035cecb5e1d39f6bb69df33035 [Edit](https://github.com/mufidu/booku/edit/sweep/create_get_books_by_author_endpoint/app.js) - [X] Running GitHub Actions for `app.js` ✓ [Edit](https://github.com/mufidu/booku/edit/sweep/create_get_books_by_author_endpoint/app.js) - [X] Create `test/booksByAuthor.test.js` ✓ https://github.com/mufidu/booku/commit/920e65dae336cba15218a0cd051abb793860fcd6 [Edit](https://github.com/mufidu/booku/edit/sweep/create_get_books_by_author_endpoint/test/booksByAuthor.test.js) - [X] Running GitHub Actions for `test/booksByAuthor.test.js` ✓ [Edit](https://github.com/mufidu/booku/edit/sweep/create_get_books_by_author_endpoint/test/booksByAuthor.test.js)
sweep-ai[bot] commented 5 months ago

🚀 Here's the PR! #62

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: a56e48304a)

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/mufidu/booku/blob/6c5a83fc7154c6f4e7a94907ea3a27f3b973dd9f/app.js#L1-L129 https://github.com/mufidu/booku/blob/6c5a83fc7154c6f4e7a94907ea3a27f3b973dd9f/package.json#L1-L41

Step 2: ⌨️ Coding

--- 
+++ 
@@ -113,6 +113,18 @@
     res.json(books);
 });

+// Get books by author
+app.get("/books/author/:authorName", async (req, res) => {
+    const { authorName } = req.params;
+    try {
+        const books = await Book.find({ author: new RegExp(authorName, 'i') });
+        res.json(books);
+    } catch (err) {
+        console.error(err);
+        res.status(500).send("Error fetching books by author");
+    }
+});
+
 // Delete a book by id
 app.delete("/books/:id", async (req, res) => {
     const book = await Book.findByIdAndDelete(req.params.id);

Ran GitHub Actions for cc192f07c3d49f035cecb5e1d39f6bb69df33035:

Ran GitHub Actions for 920e65dae336cba15218a0cd051abb793860fcd6:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/create_get_books_by_author_endpoint.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.

This is an automated message generated by Sweep AI.