Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#162948923 custom search #29

Merged
merged 1 commit into from
Feb 19, 2019
Merged

Conversation

danuluma
Copy link
Contributor

What does this PR do?

Add a search functionality with custom filters

Description of Task(s) to be completed?

  • Users would be able to filter articles by author, article title and tag/keywords

How should this be manually tested?

  • Pull the branch git fetch origin ft-custom-search-162948923:ft-custom-search-162948923
  • Checkout to the branch git checkout ft-custom-search-162948923
  • Install requirements pip3 install -r requirements.txt
  • Run the server python3 manage.py runserver
  • Launch postman and create a user by sending a POST request to http://127.0.0.1:8000/api/v1/users/ with a body of:
{
   "user":{
        "username": "dann",
        "email": "danuluma@gmail.com",
        "password": "Passw0rd"
    }
}
  • Login by sending a POST request to http://127.0.0.1:8000/api/v1/users/login/ with your registered email and password
{
   "user":{
        "email": "danuluma@gmail.com",
        "password": "Passw0rd"
    }
}
  • Copy the returned JWT token and store it somewhere
  • Use postman to create an article by sending a POST request to http://127.0.0.1:8000/api/v1/articles
  • The body should have the format of
{ 
  "article":{
       "image_path":"....",
            "title":"rick",
            "description":"It hits hard, Morty, then it slowly fades, leaving you stranded in a failing marriage. I did it.",
            "body":"morty"
    }
}
  • Select Bearer Token under Authorization and paste in the token gotten previously.
  • The response should be similar to
{
    "id": 14,
    "author": {
        "email": "danuluma@gmail.com",
        "username": "dann"
    },
    "image_path": "dan",
    "slug": "rick-5",
    "title": "rick",
    "body": "It hits hard, Morty, then it slowly fades, leaving you stranded in a failing marriage. I did it.",
    "created_at": "2019-01-31T14:51:16.512539Z",
    "updated_at": "2019-01-31T14:51:16.512733Z",
    "favourites": false
}
  • Please go ahead and create several other articles in a similar fashion, with different titles and body content

  • Now we can filter articles authored by dann by sending a GET request to http://127.0.0.1:8000/api/v1/articles?author=dann

  • We can also filter with the title or body like http://127.0.0.1:8000/api/v1/articles?title=rick , http://127.0.0.1:8000/api/v1/articles?body=slowly+fades. Multiple words should be concatenated with a + or %20

  • We can also provide multiple params to filter against http://127.0.0.1:8000/api/v1/articles?title=rick&author=dann

Any background context you want to provide?

  • This project uses the latest version of python3. Please download it from here
  • You may as well use pip instead of pip3 if you have either only python3 installed on your computer or you have it set as the default version of python

What are the relevant pivotal tracker stories?

#162948923

@coveralls
Copy link

coveralls commented Jan 31, 2019

Coverage Status

Coverage decreased (-0.5%) to 93.708% when pulling 23d1fff on ft-custom-search-162948923 into c287e80 on develop.

@boltonotieno
Copy link
Contributor

You have 4 commits. Kindly squash them to one

search_fields = ('title', 'body',
'author__username', 'tags__tag')

def get_queryset(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a docstring

@danuluma danuluma force-pushed the ft-custom-search-162948923 branch 3 times, most recently from b0eb96b to 68dbe24 Compare February 1, 2019 18:32
@Ruiru11 Ruiru11 temporarily deployed to ah-alpha-pr-29 February 1, 2019 18:32 Inactive
@Ruiru11 Ruiru11 temporarily deployed to ah-alpha-pr-29 February 1, 2019 18:43 Inactive
@Ruiru11 Ruiru11 temporarily deployed to ah-alpha-pr-29 February 1, 2019 19:43 Inactive
@Ruiru11 Ruiru11 temporarily deployed to ah-alpha-pr-29 February 1, 2019 19:50 Inactive
@Ruiru11 Ruiru11 temporarily deployed to ah-alpha-pr-29 February 1, 2019 19:52 Inactive
@Ruiru11 Ruiru11 temporarily deployed to ah-alpha-pr-29 February 1, 2019 19:54 Inactive
@Ruiru11 Ruiru11 temporarily deployed to ah-alpha-pr-29 February 4, 2019 07:25 Inactive
@Ruiru11 Ruiru11 temporarily deployed to ah-alpha-pr-29 February 4, 2019 09:12 Inactive
@Ruiru11 Ruiru11 temporarily deployed to ah-alpha-pr-29 February 4, 2019 09:27 Inactive
@danuluma danuluma force-pushed the ft-custom-search-162948923 branch 2 times, most recently from 7dc17fb to 02bd8f8 Compare February 12, 2019 14:03
@danuluma danuluma force-pushed the ft-custom-search-162948923 branch 3 times, most recently from 9084fd8 to c7f8326 Compare February 12, 2019 14:21
format="json"
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 10)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danuluma good job on this test but you can make it even better by checking the response and if there was an article that matched the author

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

format="json"
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 10)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here, test for the actual response data returned

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done this

format="json"
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 10)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the same for here as well

@danuluma danuluma force-pushed the ft-custom-search-162948923 branch 4 times, most recently from e54f101 to b07072b Compare February 15, 2019 00:28
- Users can be able to search for articles by title, author or tags

[Delivers #162948923]
Copy link
Contributor

@Ruiru11 Ruiru11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work

Copy link
Contributor

@tesh254 tesh254 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work with solving the CORSB issue we are getting on the frontend. The Pull request is good to go

@Betty-Kebenei Betty-Kebenei merged commit 45d7952 into develop Feb 19, 2019
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.

None yet

8 participants