Skip to content

Commit

Permalink
Merge pull request #150 from monsieurtanuki/feature/#133
Browse files Browse the repository at this point in the history
feature/#133 - added country code parameter for keyword search
  • Loading branch information
monsieurtanuki authored Feb 5, 2021
2 parents 2b52f9a + 9291237 commit 3eed994
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
19 changes: 14 additions & 5 deletions packages/smooth_app/lib/database/keywords_product_query.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:smooth_app/database/product_query.dart';
import 'package:openfoodfacts/model/parameter/TagFilter.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:openfoodfacts/model/SearchResult.dart';
import 'package:openfoodfacts/utils/LanguageHelper.dart';
import 'package:smooth_app/data_models/product_list.dart';

class KeywordsProductQuery implements ProductQuery {
KeywordsProductQuery(this.keywords, this.languageCode);
KeywordsProductQuery({
@required this.keywords,
@required this.languageCode,
@required this.countryCode,
@required this.size,
});

final String keywords;
final String languageCode;
final String countryCode;
final int size;

@override
Future<SearchResult> getSearchResult() async =>
Expand All @@ -20,20 +27,22 @@ class KeywordsProductQuery implements ProductQuery {
ProductSearchQueryConfiguration(
fields: ProductQuery.fields,
parametersList: <Parameter>[
const PageSize(size: 500),
PageSize(size: size),
TagFilter(
tagType: 'categories',
contains: true,
tagName: keywords,
)
),
],
language: LanguageHelper.fromJson(languageCode),
lc: languageCode,
cc: countryCode,
),
);

@override
ProductList getProductList() => ProductList(
listType: ProductList.LIST_TYPE_HTTP_SEARCH_KEYWORDS,
// TODO(monsieurtanuki): parameters should include languageCode, countryCode and pageSize
parameters: keywords,
);
}
6 changes: 4 additions & 2 deletions packages/smooth_app/lib/pages/choose_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ class ChoosePage extends StatefulWidget {
name: value,
localDatabase: localDatabase,
productQuery: KeywordsProductQuery(
value,
Localizations.localeOf(context).languageCode,
keywords: value,
languageCode: Localizations.localeOf(context).languageCode,
countryCode: window.locale.countryCode,
size: 500,
),
context: context,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies:
basic_utils: ^2.6.3
modal_bottom_sheet: ^1.0.0+1
provider: ^4.3.2+3
openfoodfacts: ^0.3.14+1
openfoodfacts: ^0.3.15
flutter_qr_bar_scanner: ^1.0.2
qr_code_scanner: ^0.3.0
sqflite: ^1.3.2+1
Expand Down

0 comments on commit 3eed994

Please sign in to comment.