Skip to content

feat: add feature to the List Users API to filter users by skill#1097

Open
battuAshita wants to merge 18 commits intoanitab-org:developfrom
battuAshita:issue#759
Open

feat: add feature to the List Users API to filter users by skill#1097
battuAshita wants to merge 18 commits intoanitab-org:developfrom
battuAshita:issue#759

Conversation

@battuAshita
Copy link
Copy Markdown
Contributor

@battuAshita battuAshita commented May 10, 2021

Description

Added a new feature to filter both users and verified users based on their skill.
The 'app/api/dao/user.py' and the 'app/api/resources/user.py' files have been updated.

Fixes #759

Type of Change:

  • Code

Code/Quality Assurance Only

  • New feature (non-breaking change which adds functionality pre-approved by mentors)

How Has This Been Tested?

I have included a test_dao_filter_by_skill.py file to 'tests/users'.
Both the test cases that I have written have been passed successfully.
c

Checklist:

  • My PR follows the style guidelines of this project
  • I have performed a self-review of my own code or materials
  • Updated the Swagger UI documentation for the List Users API

Code/Quality Assurance Only

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member

@vj-codes vj-codes left a comment

Choose a reason for hiding this comment

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

@battuAshita the lint check is failing, please run black locally and push the changes
Unless lint passes the build action won't be triggered

@vj-codes vj-codes added the Status: Changes Requested Changes are required to be done by the PR author. label May 10, 2021
@vj-codes
Copy link
Copy Markdown
Member

@battuAshita one last file and it will pass

@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2021

Codecov Report

Merging #1097 (7f158f9) into develop (8924616) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1097   +/-   ##
========================================
  Coverage    94.94%   94.95%           
========================================
  Files           38       38           
  Lines         2058     2061    +3     
========================================
+ Hits          1954     1957    +3     
  Misses         104      104           
Impacted Files Coverage Δ
app/api/dao/user.py 100.00% <100.00%> (ø)
app/api/resources/user.py 90.36% <100.00%> (ø)
app/database/models/user.py 98.57% <100.00%> (ø)

Comment thread app/api/dao/user.py
)
if skill != "":
users_list_query = users_list_query.filter(
func.lower(UserModel.skills) == func.lower(skill)
Copy link
Copy Markdown
Member

@epicadk epicadk May 10, 2021

Choose a reason for hiding this comment

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

This will only work when the skill exactly matches. Enable FTS and use proter tokenizer (or the postgres equivalent).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will make the necessary changes and get back :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @epicadk Please correct me if I'm wrong. Adding FTS would require changes to made in the underlying table right? We need to have a ts_vector column which helps us compare with the given query.

Also, I have a row with skill as "critical thinking"
select * from users where to_tsvector('english', skills) @@ to_tsquery('Criti');
This query did not give me the result whereas
select * from users where skills ilike '%criti%';
This query gave me the result

I feel using something like "ILIKE" would be sufficient here.
Thoughts?

Copy link
Copy Markdown
Member

@epicadk epicadk May 11, 2021

Choose a reason for hiding this comment

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

Like with a wildcard at the beginning will not use indexes.
Also porter will match Frustrate to Frustration which would be nice to have since skills isn't an enum.

A good practice is to use Explain Analyze on SQL queries. ( Only for your understanding not in production of course.)

Comment thread app/api/resources/user.py Outdated
Comment thread app/api/resources/user.py
@devkapilbansal devkapilbansal added Status: Needs Review PR needs an additional review or a maintainer's review. and removed Status: Changes Requested Changes are required to be done by the PR author. labels May 11, 2021
Copy link
Copy Markdown
Member

@devkapilbansal devkapilbansal left a comment

Choose a reason for hiding this comment

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

Hi @battuAshita please make necessary changes requested below 👇

Comment thread tests/users/test_dao_filter_by_skill.py Outdated
Comment thread tests/users/test_dao_filter_by_skill.py Outdated
Comment thread tests/users/test_dao_filter_by_skill.py Outdated
Comment thread tests/users/test_dao_filter_by_skill.py Outdated
@devkapilbansal devkapilbansal added Status: Changes Requested Changes are required to be done by the PR author. and removed Status: Needs Review PR needs an additional review or a maintainer's review. labels May 11, 2021
Comment thread app/api/dao/user.py Outdated
@battuAshita
Copy link
Copy Markdown
Contributor Author

I have made changes to the code such that we will be able to filter based on the skill even when they are not exactly matched. Like if we search for "Creative", we will be able to get the users with skill "Creativity". Please review this change :)

Comment thread tests/users/test_dao_filter_by_skill.py Outdated
Comment thread tests/users/test_dao_filter_by_skill.py Outdated
Comment thread tests/users/test_dao_filter_by_skill.py Outdated
@battuAshita battuAshita requested a review from isabelcosta as a code owner May 18, 2021 19:06
Comment thread tests/users/test_dao_filter_by_skill.py Outdated
@battuAshita
Copy link
Copy Markdown
Contributor Author

Done :)

@devkapilbansal devkapilbansal added Status: Needs Review PR needs an additional review or a maintainer's review. and removed Status: Changes Requested Changes are required to be done by the PR author. labels Jun 9, 2021
@devkapilbansal
Copy link
Copy Markdown
Member

There are some conflicts @battuAshita .
Please solve them

@devkapilbansal devkapilbansal added Status: Changes Requested Changes are required to be done by the PR author. and removed Status: Needs Review PR needs an additional review or a maintainer's review. labels Sep 9, 2021
@battuAshita
Copy link
Copy Markdown
Contributor Author

There are some conflicts @battuAshita .
Please solve them

Okay, sure. Will get back :)

@battuAshita
Copy link
Copy Markdown
Contributor Author

There are some conflicts @battuAshita .
Please solve them

Done.

Copy link
Copy Markdown
Member

@devkapilbansal devkapilbansal left a comment

Choose a reason for hiding this comment

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

Will test it soon

Some minor changes here 👇

Comment thread requirements.txt
Comment thread tests/users/test_dao_filter_by_skill.py Outdated
Comment thread tests/users/test_dao_filter_by_skill.py Outdated
Comment thread tests/users/test_dao_filter_by_skill.py Outdated
@battuAshita
Copy link
Copy Markdown
Contributor Author

battuAshita commented Sep 10, 2021

Made the necessary changes. Please review them.

@devkapilbansal devkapilbansal added Status: Needs Review PR needs an additional review or a maintainer's review. and removed Status: Changes Requested Changes are required to be done by the PR author. labels Sep 11, 2021
Copy link
Copy Markdown
Member

@isabelcosta isabelcosta 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 good, I just wonder about the "None" keyword added to the documentation.
Other than that, once that is addressed I am happy to approve :)

Thank you for contributing @battuAshita 🤗

Comment thread app/api/resources/user.py Outdated
Comment on lines +90 to +91
self.need_mentoring = need_mentoring
self.available_to_mentor = available_to_mentor
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wow so this was just making these values set to false 😱 nice catch!

@battuAshita
Copy link
Copy Markdown
Contributor Author

Done :)

Copy link
Copy Markdown
Member

@isabelcosta isabelcosta left a comment

Choose a reason for hiding this comment

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

Great work! Thank you for addressing my comments @battuAshita 🙌🏾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Needs Review PR needs an additional review or a maintainer's review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add to List Users API the ability to filter users by skills

5 participants