mentorship-backend icon indicating copy to clipboard operation
mentorship-backend copied to clipboard

feat: Add to List Users API the ability to filter users by location

Open ashokrayal opened this issue 5 years ago • 12 comments

Description

Fixes #760 Add to List Users API the ability to filter users by location

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 updated location for few users then I tried to search from /users and /users/verified endpoints and It was giving expected results.

Checklist:

  • [x] My PR follows the style guidelines of this project
  • [x] I have performed a self-review of my own code or materials
  • [x] I have commented my code or provided relevant documentation, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation

Code/Quality Assurance Only

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

ashokrayal avatar Sep 08 '20 16:09 ashokrayal

Codecov Report

Merging #848 (62d68cc) into develop (1643e7e) will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #848   +/-   ##
========================================
  Coverage    95.99%   96.00%           
========================================
  Files           96       96           
  Lines         5293     5306   +13     
========================================
+ Hits          5081     5094   +13     
  Misses         212      212           
Impacted Files Coverage Δ
app/api/dao/user.py 85.08% <100.00%> (ø)
app/api/resources/user.py 89.04% <100.00%> (+0.10%) :arrow_up:
tests/test_data.py 100.00% <100.00%> (ø)
tests/users/test_api_list_users.py 99.30% <100.00%> (+0.05%) :arrow_up:

codecov[bot] avatar Sep 08 '20 16:09 codecov[bot]

Hi @paritoshsinghrahar,

Can you please review my PR?

Thanks

ashokrayal avatar Sep 13 '20 10:09 ashokrayal

Hi @paritoshsinghrahar,

Can you please review my PR?

Thanks

Sure. I'll get back to you.

paritoshsinghrahar avatar Sep 15 '20 23:09 paritoshsinghrahar

@Ashokrayal On an initial review looks good. Great Effort, though.

paritoshsinghrahar avatar Sep 16 '20 00:09 paritoshsinghrahar

Hi @paritoshsinghrahar @isabelcosta, @vj-codes, Can someone review this PR?

ashokrayal avatar Sep 26 '20 05:09 ashokrayal

@isabelcosta This looks good,

But before merging any of the filter PRs, I'd be willing to have a discussion on what the best approach is to implement this or refactor this later. Currently, the function and the parameters suffers from all kinds of code smell, so I am open to all kinds of ideas on how to implement filtering in a clean way.

SanketDG avatar Sep 29 '20 04:09 SanketDG

@isabelcosta @SanketDG does this PR need further discussion before being tested and merged?

rpattath avatar Oct 26 '20 15:10 rpattath

@SanketDG I agree with you. Will wait for the test and then merge. But as part of this, can you create an issue for creating a cleaner way for filtering data? If not, I can, just let me know :) Thank you so much for bringing this up!

isabelcosta avatar Oct 27 '20 18:10 isabelcosta

I will surely do it today

ashokrayal avatar Nov 16 '20 02:11 ashokrayal

Here are some basic ideas to abstract away filtering into a common piece of code (so that it doesn't end up having 20 arguments in the function signature)

  • Use **kwargs as a container for all filter operations.
  • Loop through kwargs and check which "keys" are fields of UserModel.
  • Do the standard filter query using these key value pairs from **kwargs

SanketDG avatar Nov 16 '20 11:11 SanketDG

Putting on hold as the best approach is not decided yet

vj-codes avatar Feb 21 '21 11:02 vj-codes

@vj-codes could you create, in case it does not exist yet, an issue to implement filtering in a generic way.

isabelcosta avatar Feb 21 '21 20:02 isabelcosta