[DON'T MERGE] LITE-29320 LITE-29322 Draft for XVS extension enhanced filtering and … #138
+120
−23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…sort
Just an example of implementation filtering and sort using fastapi-filter library, combined with some custom cases to estimate, how to move further.
Custom filters and sort in this example were implemented for the DeploymentFilter.
Why do we have these special cases
Filtering.
There are some fields we want to filter by, but they are not stored in the model (e.g. hub), so we request them from the Connect on every call. And fastapi-filter supports filtering only by model fields. We may decide to store them, but in this case we will need to follow all the changes with such objects and process them (add more events).
Ordering.
fastapi-filter library doesn't support sort by related fields (https://github.com/arthurio/fastapi-filter/blob/main/fastapi_filter/base/filter.py#L35). So there is no way to sort by product__name, e.g.
The further possible ways are the following:
Implement only filtering and sort by fields, that fastapi-filter allows us to (marked green here https://confluence.int.zone/display/CONNECT/XVS+extension+filtering+and+pagination+enhancement#XVSextensionfilteringandpaginationenhancement-Listoffieldstofilterby). Also there is a possibility to use sort by id instead of sort by name, not so convenient, but still useful.
Combine fastapi-filter with custom filtering and sort (like done in the PR for Deployment model). Looks like mess.
Make all the filtering and sort custom (remove fastapi-filter lib). Probably it will be more convenient to write own reusable functions or classes for filtering, appropriate for our cases.
Enhance the way we process custom cases. Likely it means to create own Filter class and to override its methods.
Personally I prefer to go 1st way. And if it won't be sufficient, discuss the list of required fields and come up with how to deal with them (maybe, for few fields it might fine to process them in a custom way). If we for sure need comprehensive solution, probably 3rd or 4th way is for us, need to investigate more.