Skip to content

Commit

Permalink
feat: #2339 - added language and country to query product list keys (#…
Browse files Browse the repository at this point in the history
…2465)

What:
* added language and country to query product list keys
* that means that if I run a query for "pizza", not only the results will be different depending on the language and country (that was already the case), but the results will be cached accordingly - if I change language or country, I will see the cached results for those new language/country, not the results of the same query but with different language/country
* we needed that improvement in order to display correctly the "world" results; that was the first step
* also moved all the "query" classes to a specific folder
* fun fact: there are more "pizza"s in France than in Italy

Impacted files:
* `abstract_onboarding_data.dart`: minor refactoring
* `barcode_product_query.dart`: moved; minor refactoring
* `category_product_query.dart`: moved; added language and country to product list key
* `continuous_scan_model.dart`: minor refactoring
* `country_selector.dart`: minor refactoring
* `database_product_list_supplier.dart`: minor refactoring
* `keywords_product_query.dart`: moved; added language and country to product list key
* `main.dart`: minor refactoring
* `new_product_page.dart`: minor refactoring
* `nutrition_page_loaded.dart`: minor refactoring
* `ocr_helper.dart`: minor refactoring
* `onboarding_data_product.dart`: minor refactoring
* `ordered_nutrients_cache.dart`: minor refactoring
* `paged_product_query.dart`: moved; added language and country to product list key; refactored around `getProducts`
* `paged_search_product_query.dart`: moved; refactored
* `paged_to_be_completed_product_query.dart`: moved; added language and country to product list key; refactored
* `paged_user_product_query.dart`: moved; added language to product list key; refactored
* `picture_capture_helper.dart`: minor refactoring
* `product_dialog_helper.dart`: minor refactoring
* `product_list.dart`: added optional language and country to constructor parameters
* `product_list_import_export.dart`: minor refactoring
* `product_list_page.dart`: minor refactoring
* `product_list_supplier.dart`: minor refactoring
* `product_query.dart`: moved; not an interface anymore
* `product_query_model.dart`: minor refactoring
* `product_query_page_helper.dart`: minor refactoring
* `product_refresher.dart`: minor refactoring
* `query_product_list_supplier.dart`: minor refactoring
* `robotoff_insight_helper.dart`: minor refactoring
* `robotoff_questions_query.dart`: moved; minor refactoring
* `search_page.dart`: minor refactoring
* `simple_input_page_helpers.dart`: minor refactoring
* `summary_card.dart`: minor refactoring
* `user_preferences_account.dart`: minor refactoring
* `user_preferences_dev_mode.dart`: minor refactoring
  • Loading branch information
monsieurtanuki authored Jul 2, 2022
1 parent 3d46da9 commit 9e253a7
Show file tree
Hide file tree
Showing 38 changed files with 201 additions and 134 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:smooth_app/database/dao_string.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:smooth_app/query/product_query.dart';

/// Abstraction of data we download, store and reuse at onboarding.
abstract class AbstractOnboardingData<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import 'package:flutter/widgets.dart';
import 'package:openfoodfacts/model/Product.dart';
import 'package:smooth_app/data_models/fetched_product.dart';
import 'package:smooth_app/data_models/product_list.dart';
import 'package:smooth_app/database/barcode_product_query.dart';
import 'package:smooth_app/database/dao_product.dart';
import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/query/barcode_product_query.dart';
import 'package:smooth_app/services/smooth_services.dart';

enum ScannedProductState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:smooth_app/data_models/product_list_supplier.dart';
import 'package:smooth_app/data_models/query_product_list_supplier.dart';
import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/paged_product_query.dart';
import 'package:smooth_app/query/paged_product_query.dart';

/// Supplier of previous back-end results now stored in the local database.
class DatabaseProductListSupplier extends ProductListSupplier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:convert';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/data_models/abstract_onboarding_data.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:smooth_app/query/product_query.dart';

/// Helper around a product we download, store and reuse at onboarding.
class OnboardingDataProduct extends AbstractOnboardingData<Product> {
Expand Down
37 changes: 35 additions & 2 deletions packages/smooth_app/lib/data_models/product_list.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:openfoodfacts/model/Product.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:openfoodfacts/utils/CountryHelper.dart';

enum ProductListType {
/// API search by [SearchTerms] keywords
Expand Down Expand Up @@ -65,81 +66,103 @@ class ProductList {
this.parameters = '',
this.pageSize = 0,
this.pageNumber = 0,
this.language,
this.country,
});

ProductList.keywordSearch(
final String keywords, {
required int pageSize,
required int pageNumber,
required OpenFoodFactsLanguage? language,
required OpenFoodFactsCountry? country,
}) : this._(
listType: ProductListType.HTTP_SEARCH_KEYWORDS,
parameters: keywords,
pageSize: pageSize,
pageNumber: pageNumber,
language: language,
country: country,
);

ProductList.categorySearch(
final String category, {
required int pageSize,
required int pageNumber,
required OpenFoodFactsLanguage? language,
required OpenFoodFactsCountry? country,
}) : this._(
listType: ProductListType.HTTP_SEARCH_CATEGORY,
parameters: category,
pageSize: pageSize,
pageNumber: pageNumber,
language: language,
country: country,
);

ProductList.contributor(
final String userId, {
required int pageSize,
required int pageNumber,
required OpenFoodFactsLanguage? language,
}) : this._(
listType: ProductListType.HTTP_USER_CONTRIBUTOR,
parameters: userId,
pageSize: pageSize,
pageNumber: pageNumber,
language: language,
);

ProductList.informer(
final String userId, {
required int pageSize,
required int pageNumber,
required OpenFoodFactsLanguage? language,
}) : this._(
listType: ProductListType.HTTP_USER_INFORMER,
parameters: userId,
pageSize: pageSize,
pageNumber: pageNumber,
language: language,
);

ProductList.photographer(
final String userId, {
required int pageSize,
required int pageNumber,
required OpenFoodFactsLanguage? language,
}) : this._(
listType: ProductListType.HTTP_USER_PHOTOGRAPHER,
parameters: userId,
pageSize: pageSize,
pageNumber: pageNumber,
language: language,
);

ProductList.toBeCompleted(
final String userId, {
required int pageSize,
required int pageNumber,
required OpenFoodFactsLanguage? language,
}) : this._(
listType: ProductListType.HTTP_USER_TO_BE_COMPLETED,
parameters: userId,
pageSize: pageSize,
pageNumber: pageNumber,
language: language,
);

ProductList.allToBeCompleted({
required int pageSize,
required int pageNumber,
required OpenFoodFactsLanguage? language,
required OpenFoodFactsCountry? country,
}) : this._(
listType: ProductListType.HTTP_ALL_TO_BE_COMPLETED,
pageSize: pageSize,
pageNumber: pageNumber,
language: language,
country: country,
);

ProductList.history() : this._(listType: ProductListType.HISTORY);
Expand All @@ -161,6 +184,12 @@ class ProductList {
/// Page number at query time.
final int? pageNumber;

/// Language at query time.
final OpenFoodFactsLanguage? language;

/// Country at query time.
final OpenFoodFactsCountry? country;

/// "Total size" returned by the query.
int totalSize = 0;

Expand Down Expand Up @@ -260,7 +289,11 @@ class ProductList {
case ProductListType.HTTP_USER_PHOTOGRAPHER:
case ProductListType.HTTP_USER_TO_BE_COMPLETED:
case ProductListType.HTTP_ALL_TO_BE_COMPLETED:
return '$parameters,$pageSize,$pageNumber';
return '$parameters'
',$pageSize'
',$pageNumber'
',${language?.code ?? ''}'
',${country?.iso2Code ?? ''}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:smooth_app/data_models/product_list.dart';
import 'package:smooth_app/data_models/query_product_list_supplier.dart';
import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/paged_product_query.dart';
import 'package:smooth_app/query/paged_product_query.dart';

/// Asynchronously loads a [ProductList] with products
abstract class ProductListSupplier {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/data_models/product_list_supplier.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:smooth_app/query/product_query.dart';

enum LoadingStatus {
LOADING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:smooth_app/data_models/product_list_supplier.dart';
import 'package:smooth_app/database/dao_product.dart';
import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/paged_product_query.dart';
import 'package:smooth_app/query/paged_product_query.dart';

/// [ProductListSupplier] with a server query flavor
class QueryProductListSupplier extends ProductListSupplier {
Expand Down
18 changes: 0 additions & 18 deletions packages/smooth_app/lib/database/paged_product_query.dart

This file was deleted.

24 changes: 0 additions & 24 deletions packages/smooth_app/lib/database/paged_search_product_query.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:smooth_app/data_models/product_list.dart';
import 'package:smooth_app/database/dao_product.dart';
import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:smooth_app/helpers/collections_helper.dart';
import 'package:smooth_app/query/product_query.dart';

/// Import / Export of product lists (with or without JSON).
/// All lists are composed of barcodes, where we support history and user lists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/continuous_scan_model.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:smooth_app/generic_lib/loading_dialog.dart';
import 'package:smooth_app/query/product_query.dart';

Future<bool> uploadCapturedPicture(
BuildContext context, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:openfoodfacts/model/RobotoffQuestion.dart';
import 'package:smooth_app/database/dao_string_list_map.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/robotoff_questions_query.dart';
import 'package:smooth_app/query/robotoff_questions_query.dart';

class RobotoffInsightHelper {
const RobotoffInsightHelper(this._localDatabase);
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import 'package:smooth_app/data_models/user_management_provider.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/database/dao_string.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/helpers/camera_helper.dart';
import 'package:smooth_app/helpers/data_importer/smooth_app_data_importer.dart';
import 'package:smooth_app/helpers/network_config.dart';
import 'package:smooth_app/helpers/permission_helper.dart';
import 'package:smooth_app/pages/onboarding/onboarding_flow_navigator.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/services/smooth_services.dart';
import 'package:smooth_app/themes/smooth_theme.dart';
import 'package:smooth_app/themes/theme_provider.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:iso_countries/iso_countries.dart';
import 'package:openfoodfacts/utils/CountryHelper.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_text_form_field.dart';
import 'package:smooth_app/query/product_query.dart';

/// A selector for selecting user's country.
class CountrySelector extends StatefulWidget {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/user_management_provider.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/paged_product_query.dart';
import 'package:smooth_app/database/paged_user_product_query.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/helpers/launch_url_helper.dart';
import 'package:smooth_app/helpers/user_management_helper.dart';
import 'package:smooth_app/pages/preferences/abstract_user_preferences.dart';
import 'package:smooth_app/pages/preferences/paged_to_be_completed_product_query.dart';
import 'package:smooth_app/pages/preferences/user_preferences_page.dart';
import 'package:smooth_app/pages/preferences/user_preferences_widgets.dart';
import 'package:smooth_app/pages/product/common/product_query_page_helper.dart';
import 'package:smooth_app/pages/user_management/login_page.dart';
import 'package:smooth_app/query/paged_product_query.dart';
import 'package:smooth_app/query/paged_to_be_completed_product_query.dart';
import 'package:smooth_app/query/paged_user_product_query.dart';

class UserPreferencesAccount extends AbstractUserPreferences {
UserPreferencesAccount({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:smooth_app/data_models/product_list.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/helpers/data_importer/product_list_import_export.dart';
import 'package:smooth_app/helpers/data_importer/smooth_app_data_importer.dart';
Expand All @@ -17,6 +16,7 @@ import 'package:smooth_app/pages/preferences/abstract_user_preferences.dart';
import 'package:smooth_app/pages/preferences/user_preferences_dialog_editor.dart';
import 'package:smooth_app/pages/preferences/user_preferences_page.dart';
import 'package:smooth_app/pages/scan/ml_kit_scan_page.dart';
import 'package:smooth_app/query/product_query.dart';

/// Collapsed/expanded display of "dev mode" for the preferences page.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/data_models/fetched_product.dart';
import 'package:smooth_app/database/barcode_product_query.dart';
import 'package:smooth_app/database/dao_product.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/loading_dialog.dart';
import 'package:smooth_app/pages/product/add_new_product_page.dart';
import 'package:smooth_app/query/barcode_product_query.dart';

/// Dialog helper for product barcode search
class ProductDialogHelper {
Expand Down
Loading

0 comments on commit 9e253a7

Please sign in to comment.