mufidu / booku

0 stars 1 forks source link

Sweep: Implement search #58

Closed mufidu closed 7 months ago

mufidu commented 7 months ago

Details

Add a search feature in the /books endpoint to allow users to search for books by title, author, or category.

Checklist - [X] Modify `app.js` ✓ https://github.com/mufidu/booku/commit/7d188944ba1ab8c9e0f6c2bb3ecded7e03359fed [Edit](https://github.com/mufidu/booku/edit/sweep/implement_search/app.js) - [X] Running GitHub Actions for `app.js` ✓ [Edit](https://github.com/mufidu/booku/edit/sweep/implement_search/app.js)
sweep-ai[bot] commented 7 months ago

🚀 Here's the PR! #59

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

[!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/e54e094cb30babf73b9fd9beb1c16fcf66f9c6bd/models/book.js#L1-L26 https://github.com/mufidu/booku/blob/e54e094cb30babf73b9fd9beb1c16fcf66f9c6bd/db.js#L1-L15 https://github.com/mufidu/booku/blob/e54e094cb30babf73b9fd9beb1c16fcf66f9c6bd/package.json#L1-L41

Step 2: ⌨️ Coding

--- 
+++ 
@@ -30,10 +30,24 @@
     });
 });

-// Get all books
+// Get all books with optional search
 app.get("/books", async (req, res) => {
-    const books = await Book.find({});
-    res.json(books);
+    let query = {};
+    if (req.query.title) {
+        query.title = new RegExp(req.query.title, 'i');
+    }
+    if (req.query.author) {
+        query.author = new RegExp(req.query.author, 'i');
+    }
+    if (req.query.category) {
+        query.category = req.query.category;
+    }
+    Book.find(query).then(books => {
+        res.json(books);
+    }).catch(err => {
+        console.error(err);
+        res.status(500).send("Error fetching books");
+    });
 });

 // Create a new book

Ran GitHub Actions for 7d188944ba1ab8c9e0f6c2bb3ecded7e03359fed:


Step 3: 🔁 Code Review

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


🎉 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.