Skip to content

Instantly share code, notes, and snippets.

@amrvitale
Last active July 21, 2020 17:50
Show Gist options
  • Save amrvitale/3a610f2a975623532491520a0fbc21ec to your computer and use it in GitHub Desktop.
Save amrvitale/3a610f2a975623532491520a0fbc21ec to your computer and use it in GitHub Desktop.
Issues with Search component
ISSUE: I'm only seeing results when I click "search" but without any terms searched on.
If I enter a search term that should return results, I get "No results found, search again" message
CLIENT CODE: https://github.com/amrvitale/reciplease-capstone/blob/master/src/components/search/Search.js (search component)
SERVER CODE: https://github.com/amrvitale/reciplease-capstone-api/tree/master/src/searchRecipes
POSTMAN: I've tried get request in Postman, but only get the empty {"recipes": []} array object when I search http://localhost:8000/api/search?recipename=chocolate
WHAT I'VE TRIED: I have lots of "sanity testing" console logs throughout my server code, and these are now appearing in the vs code terminal.
VS CODE SERVER TERMINAL -WHEN I SEARCH WITH QUERY "PASTA" IN RECIPENMAME FIELD
] Angela was here
::1 - - [21/Jul/2020:17:39:44 +0000] "GET /api/search? HTTP/1.1" 304 -
::1 - - [21/Jul/2020:17:39:51 +0000] "OPTIONS /api/search?recipename=pasta HTTP/1.1" 204 0
hi, inside get for search router
{ recipename: 'pasta' } my req.query
parts: pasta undefined
recipename pasta
ingredients null
[] Angela was here <---- should have logged recipes array, but is empty
::1 - - [21/Jul/2020:17:39:51 +0000] "GET /api/search?recipename=pasta HTTP/1.1" 304 -
VS CODE SERVER TERMINAL WHEN I SEARCH WITH NO QUERIES ENTERED
::1 - - [21/Jul/2020:17:45:00 +0000] "GET /api/myrecipes HTTP/1.1" 304 -
::1 - - [21/Jul/2020:17:45:08 +0000] "OPTIONS /api/search? HTTP/1.1" 204 0
hi, inside get for search router
{} my req.query
parts: undefined undefined
recipename null
ingredients null
[
{
id: 2,
recipename: 'Chocolate',
experience: 'easy',
preptime: '30 minutes',
cooktime: '2 hours',
servings: '7',
ingredients: 'test\ntest\ntest',
directions: '1. test\n2. test\n3. test',
status: 'published'
},
{
id: 3,
recipename: 'pasta alla norma super long title here seeing what happens.',
experience: 'This is a recipe for vegetable and pasta lovers. \n' +
"It's fun to make, easy and can be easily doubled. \n" +
'Highly recommend this recipe.',
preptime: '2',
cooktime: '2',
servings: '2',
ingredients: '160 ml extra-virgin olive oil, plus extra to serve\n' +
'4 garlic cloves, thinly sliced\n' +
'800 gm canned whole peeled tomatoes\n' +
'1 tsp dried oregano\n' +
'1 large eggplant (about 500gm), cut into 2cm cubes\n' +
'600 gm dried fusilli\n' +
'1 cup (loosely packed) basil, coarsely torn, plus extra to garnish\n' +
'2 buffalo mozzarella balls (125gm each), coarsely torn',
directions: '1) Heat 50ml oil in a large saucepan over high heat, then reduce heat to medium, add garlic and cook until golden (1-2 minutes). Add tomatoes and oregano, season to taste and cook, breaking down tomatoes with a spoon, until sauce thickens (5-10 minutes).\n' +
'\n' +
'2) Heat half the remaining oil in a large, deep frying pan over medium-high heat and fry half the eggplant until golden and tender (5-7 minutes). Drain on absorbent paper or in a colander and repeat with remaining oil and eggplant. Add to tomato sauce and keep warm.\n' +
'\n' +
'3) Cook fusilli in a large saucepan of boiling salted water until al dente (10-15 minutes), then drain, reserving a little pasta water.\n' +
'\n' +
'4)Add basil, mozzarella and fusilli to tomato sauce and stir to combine. If the sauce is a bit dry, loosen it with a little reserved
pasta water. Serve drizzled with extra-virgin olive oil and scattered with basil.',
status: 'published'
}
] Angela was here
::1 - - [21/Jul/2020:17:45:08 +0000] "GET /api/search? HTTP/1.1" 304 -
Please note: I tried using code from my other capstone for the search component (which worked): https://github.com/amrvitale/draftling-capstone/blob/master/src/search/Search.js
So if you see differences that I do not, please point out!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment