Feat offline support refactor#135
Open
stnguyen90 wants to merge 1 commit intofeat-offline-supportfrom
Open
Conversation
Split out offline DB related operations into separate classes.
Contributor
Author
|
@lohanidamodar, I tried to move a lot of logic out of ClientOfflineMixin. What do you think? |
stnguyen90
commented
Mar 22, 2023
Comment on lines
+40
to
+114
| if (params.containsKey('queries')) { | ||
| final queries = params['queries'] as List<dynamic>; | ||
| queries.forEach((query) { | ||
| final q = Query.parse(query as String); | ||
|
|
||
| switch (q.method) { | ||
| case 'equal': | ||
| final value = q.params[1]; | ||
| if (value is List) { | ||
| value.forEach((v) { | ||
| final List<Filter> equalFilters = []; | ||
| value.forEach((v) { | ||
| equalFilters.add(Filter.equals(q.params[0], v)); | ||
| }); | ||
| filters.add(Filter.or(equalFilters)); | ||
| }); | ||
| } else { | ||
| filters.add(Filter.equals(q.params[0], q.params[1])); | ||
| } | ||
| break; | ||
|
|
||
| case 'notEqual': | ||
| filters.add(Filter.notEquals(q.params[0], q.params[1])); | ||
| break; | ||
|
|
||
| case 'lessThan': | ||
| filters.add(Filter.lessThan(q.params[0], q.params[1])); | ||
| break; | ||
|
|
||
| case 'lessThanEqual': | ||
| filters.add(Filter.lessThanOrEquals(q.params[0], q.params[1])); | ||
| break; | ||
|
|
||
| case 'greaterThan': | ||
| filters.add(Filter.greaterThan(q.params[0], q.params[1])); | ||
| break; | ||
|
|
||
| case 'greaterThanEqual': | ||
| filters.add(Filter.greaterThanOrEquals(q.params[0], q.params[1])); | ||
| break; | ||
|
|
||
| case 'search': | ||
| filters.add(Filter.matches(q.params[0], r'${q.params[1]}+')); | ||
| break; | ||
|
|
||
| case 'orderAsc': | ||
| sortOrders.add(SortOrder(q.params[0] as String)); | ||
| break; | ||
|
|
||
| case 'orderDesc': | ||
| sortOrders.add(SortOrder(q.params[0] as String, false)); | ||
| break; | ||
|
|
||
| case 'cursorBefore': | ||
| // TODO: Handle this case. | ||
| break; | ||
|
|
||
| case 'cursorAfter': | ||
| // TODO: Handle this case. | ||
| break; | ||
|
|
||
| case 'limit': | ||
| finder.limit = q.params[0] as int; | ||
| break; | ||
| case 'offset': | ||
| finder.offset = q.params[0] as int; | ||
| break; | ||
| } | ||
| }); | ||
|
|
||
| if (filters.isNotEmpty) { | ||
| filter = Filter.and(filters); | ||
| finder.filter = filter; | ||
| } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
@abnegate, here's an attempt at client-side filters of offline data.
Member
lohanidamodar
left a comment
There was a problem hiding this comment.
Looks good. However I still suggest refactoring it in a middleware approach for final release. LMK WYT.
Comment on lines
+50
to
+51
| String method; | ||
| List<dynamic> params; |
Member
There was a problem hiding this comment.
Suggested change
| String method; | |
| List<dynamic> params; | |
| final String method; | |
| final List<dynamic> params; |
I think these can be final
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Refactor ClientOfflineMixin and add offline filters
Test Plan
Manual
Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
Have you read the Contributing Guidelines on issues?
Yes