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

API Search profiles: adding parameter to search (only) by username #3235

Merged

Conversation

milaaraujo
Copy link
Collaborator

Hey everybody!

We are opening this request to fix the issue #3228.

We added a new parameter to the profile endpoint so now we can search only by username. We will use this new functionality on the autocomplete feature.

We would like some feedback, thanks! :)

fixes #3228
@publiclab/reviewers @publiclab/soc @jywarren

@milaaraujo milaaraujo added summer-of-code rgsoc Rails Girls Summer of Code labels Aug 16, 2018
@ghost ghost added the in progress label Aug 16, 2018
@milaaraujo milaaraujo added the API label Aug 16, 2018
@plotsbot
Copy link
Collaborator

plotsbot commented Aug 16, 2018

1 Message
📖 @milaaraujo Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.

Generated by 🚫 Danger

search_type = endpoint
search_criteria = SearchCriteria.new(search_query, tag: tag_query, sort_by: sort_query, order_direction: order_query)
search_criteria = SearchCriteria.new(search_query, tag: tag_query, sort_by: sort_query, order_direction: order_query, field: field_query)
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we could break this up over multiple lines? It could be indented so they line up. And is there an advantage to making variables to store these values in the above lines versus directly using params[] in the .new call?

user_scope = SrchScope.find_users(search_criteria.query, limit = 10)
user_scope =
if search_criteria.field == "username"
SrchScope.find_by_username(search_criteria.query, limit = 10)
Copy link
Member

Choose a reason for hiding this comment

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

Here we might think of setting an optional limit parameter in profiles(search_criteria, limit = 10) and then we could override it if needed?

end
end

def self.find_by_username(query, limit)
Copy link
Member

Choose a reason for hiding this comment

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

Great!

@@ -148,6 +148,34 @@ def app
assert matcher =~ json
end

# search by username and bio, returns users by id when order_by is not provided and sorted direction default DESC
test 'search profiles by username and bio without order_by and default sort_direction' do
get '/api/srch/profiles?srchString=steff'
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, looking on my phone... is there also a text for only bio content? Something that has no username matches?

Choose a reason for hiding this comment

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

we did like this: the previous tests (that we first had in mind to search only by username) have the field=username and therefore, returns only the users searched by username. So we added another one that would search only by username, but yeah, good point, we added a new one to search only by bio!

Choose a reason for hiding this comment

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

@jywarren we pushed some changes, thanks for the feedback!

@milaaraujo
Copy link
Collaborator Author

Hey @jywarren,

We've just realized that code in the master branch contains an error. In line 9 of plots2/app/services/srch_scope.rb we forgot to replace input for query.
desenho sem titulo 1
This error only occurs in development/test environment, when using sqlite. That's why Travis did not complain about it. We are fixing this problem here in this PR!

@stefannibrasil
Copy link

@publiclab/reviewers anyone to review this PR? :)

@@ -129,7 +129,7 @@ test_user:
password_salt: <%= salt = Authlogic::Random.hex_token %>
crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("secretive" + salt) %>
persistence_token: <%= Authlogic::Random.hex_token %>
bio: ''
bio: 'I love ruby'
Copy link
Member

Choose a reason for hiding this comment

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

😄 💎

crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("secretive" + salt) %>
persistence_token: <%= Authlogic::Random.hex_token %>
last_request_at: <%= Time.now %>
bio: 'data is a nice cat and he loves steff!'
Copy link
Member

Choose a reason for hiding this comment

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

😹

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

This looks fantastic!

@jywarren
Copy link
Member

Hi, this looks great, and I'm going to merge it. Just for future reference, if you can also say something like "ready to merge if you approve" then I can do so straight away... here it looks fine but sometimes folks want feedback but not actually to have it merged. Maybe that'll help me speed things up on my end a bit -- many thanks!

@jywarren jywarren merged commit ea2b5ba into publiclab:master Aug 21, 2018
@ghost ghost removed the review-me label Aug 21, 2018
@stefannibrasil
Copy link

thank you, @jywarren ! Ok, from now on we are gonna add this "ready to merge if you approve" tag xD

@milaaraujo milaaraujo deleted the api/add-username-to-profiles-endpoint branch October 31, 2018 04:19
SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this pull request May 5, 2019
…ubliclab#3235)

* Add field username to profiles endpoint to be used on the autocomplete call

* Version 1

* Added missing json

* Change the params to create a new SearchCriteria instance

* Adding limit parameter

* Refactor find_users and add bio search test

* fix codeclimate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rgsoc Rails Girls Summer of Code summer-of-code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Search profiles by username endpoint
4 participants