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

Feat offline support refactor #135

Open
wants to merge 1 commit into
base: feat-offline-support
Choose a base branch
from

Conversation

stnguyen90
Copy link
Contributor

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

Split out offline DB related operations into separate classes.
@stnguyen90 stnguyen90 changed the base branch from master to feat-offline-support March 22, 2023 18:22
@stnguyen90
Copy link
Contributor Author

@lohanidamodar, I tried to move a lot of logic out of ClientOfflineMixin. What do you think?

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;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abnegate, here's an attempt at client-side filters of offline data.

Copy link
Member

@lohanidamodar lohanidamodar left a comment

Choose a reason for hiding this comment

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

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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
String method;
List<dynamic> params;
final String method;
final List<dynamic> params;

I think these can be final

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants