-
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #2425 - added "all products to be completed" item (in user page) (
#2441) New files: * `paged_to_be_completed_product_query.dart`: Back-end paged query for all "to-be-completed" products. * `tmp_to_be_completed_query_configuration.dart`: Query Configuration for all to-be-completed products. Deleted files: * `contributor_product_query.dart` * `informer_product_query.dart` * `photographer_product_query.dart` * `to_be_completed_product_query.dart` Impacted files * `app_en.arb`: 1 label slightly modified, 1 added label. * `app_fr.arb`: 1 label slightly modified, 1 added label. * `paged_user_product_query.dart`: refactored around `UserProductSearchQueryConfiguration`. * `product_list.dart`: added a new list - all products to be completed (not just the user's). * `product_list_page.dart`: refactored. * `product_query_page_helper.dart`: refactored. * `user_preferences_account.dart`: added an item for "all to-be-completed"; refactored.
- Loading branch information
1 parent
e5aa231
commit 587e943
Showing
13 changed files
with
183 additions
and
149 deletions.
There are no files selected for viewing
This file contains 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
21 changes: 0 additions & 21 deletions
21
packages/smooth_app/lib/database/contributor_product_query.dart
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
packages/smooth_app/lib/database/informer_product_query.dart
This file was deleted.
Oops, something went wrong.
99 changes: 50 additions & 49 deletions
99
packages/smooth_app/lib/database/paged_user_product_query.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,65 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:http/http.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart'; | ||
import 'package:openfoodfacts/utils/QueryType.dart'; | ||
import 'package:openfoodfacts/utils/UriHelper.dart'; | ||
import 'package:openfoodfacts/utils/UserProductSearchQueryConfiguration.dart'; | ||
import 'package:smooth_app/data_models/product_list.dart'; | ||
import 'package:smooth_app/database/paged_product_query.dart'; | ||
import 'package:smooth_app/database/product_query.dart'; | ||
|
||
/// Back-end paged queries around User. | ||
abstract class PagedUserProductQuery extends PagedProductQuery { | ||
PagedUserProductQuery(this.userId); | ||
class PagedUserProductQuery extends PagedProductQuery { | ||
PagedUserProductQuery({ | ||
required this.userId, | ||
required this.type, | ||
}); | ||
|
||
final String userId; | ||
final UserProductSearchType type; | ||
|
||
@override | ||
Future<SearchResult> getSearchResult() async => _searchProducts( | ||
getPath(), | ||
Future<SearchResult> getSearchResult() async => OpenFoodAPIClient.getProducts( | ||
ProductQuery.getUser(), | ||
pageSize, | ||
pageNumber, | ||
OpenFoodAPIConfiguration.globalQueryType, | ||
UserProductSearchQueryConfiguration( | ||
type: type, | ||
userId: userId, | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
language: ProductQuery.getLanguage(), | ||
fields: ProductQuery.fields, | ||
), | ||
queryType: OpenFoodAPIConfiguration.globalQueryType, | ||
); | ||
|
||
String getPath(); | ||
|
||
static Future<SearchResult> _searchProducts( | ||
// TODO(monsieurtanuki): move to off-dart, but probably not as is | ||
final String path, | ||
final User user, | ||
final int pageSize, | ||
final int pageNumber, | ||
final QueryType? queryType, | ||
) async { | ||
final List<String> fields = convertFieldsToStrings( | ||
ProductQuery.fields, | ||
<OpenFoodFactsLanguage>[ProductQuery.getLanguage()!], | ||
); | ||
final Uri uri = UriHelper.getUri( | ||
path: path, | ||
queryType: queryType, | ||
queryParameters: <String, String>{ | ||
'page_size': '$pageSize', | ||
'page': '$pageNumber', | ||
'fields': fields.join(','), | ||
}, | ||
); | ||
final Response response = await HttpHelper().doGetRequest( | ||
uri, | ||
queryType: queryType, | ||
user: OpenFoodAPIConfiguration.globalUser, | ||
); | ||
final String jsonStr = response | ||
.body; // TODO(monsieurtanuki): what about _replaceQuotes(response.body); | ||
final SearchResult result = SearchResult.fromJson( | ||
json.decode(jsonStr) as Map<String, dynamic>, | ||
); | ||
|
||
// TODO(monsieurtanuki): what about _removeImages(result, configuration); | ||
|
||
return result; | ||
@override | ||
ProductList getProductList() { | ||
switch (type) { | ||
case UserProductSearchType.CONTRIBUTOR: | ||
return ProductList.contributor( | ||
userId, | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
); | ||
case UserProductSearchType.INFORMER: | ||
return ProductList.informer( | ||
userId, | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
); | ||
case UserProductSearchType.PHOTOGRAPHER: | ||
return ProductList.photographer( | ||
userId, | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
); | ||
case UserProductSearchType.TO_BE_COMPLETED: | ||
return ProductList.toBeCompleted( | ||
userId, | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
); | ||
} | ||
} | ||
|
||
@override | ||
String toString() => | ||
'PagedUserProductQuery($type, "$userId", $pageSize, $pageNumber)'; | ||
} |
21 changes: 0 additions & 21 deletions
21
packages/smooth_app/lib/database/photographer_product_query.dart
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
packages/smooth_app/lib/database/to_be_completed_product_query.dart
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
31 changes: 31 additions & 0 deletions
31
packages/smooth_app/lib/pages/preferences/paged_to_be_completed_product_query.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart'; | ||
import 'package:smooth_app/data_models/product_list.dart'; | ||
import 'package:smooth_app/database/paged_product_query.dart'; | ||
import 'package:smooth_app/database/product_query.dart'; | ||
import 'package:smooth_app/pages/preferences/tmp_to_be_completed_query_configuration.dart'; | ||
|
||
/// Back-end paged query for all "to-be-completed" products. | ||
class PagedToBeCompletedProductQuery extends PagedProductQuery { | ||
@override | ||
Future<SearchResult> getSearchResult() async => OpenFoodAPIClient.getProducts( | ||
ProductQuery.getUser(), | ||
ToBeCompletedQueryConfiguration( | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
language: ProductQuery.getLanguage(), | ||
country: ProductQuery.getCountry(), | ||
fields: ProductQuery.fields, | ||
), | ||
queryType: OpenFoodAPIConfiguration.globalQueryType, | ||
); | ||
|
||
@override | ||
ProductList getProductList() => ProductList.allToBeCompleted( | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
); | ||
|
||
@override | ||
String toString() => 'PagedToBeCompletedProductQuery($pageSize, $pageNumber)'; | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/smooth_app/lib/pages/preferences/tmp_to_be_completed_query_configuration.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:openfoodfacts/utils/AbstractQueryConfiguration.dart'; | ||
import 'package:openfoodfacts/utils/CountryHelper.dart'; | ||
|
||
// TODO(monsieurtanki): move to off-dart | ||
/// Query Configuration for all to-be-completed products. | ||
class ToBeCompletedQueryConfiguration extends AbstractQueryConfiguration { | ||
ToBeCompletedQueryConfiguration({ | ||
final OpenFoodFactsLanguage? language, | ||
final List<OpenFoodFactsLanguage> languages = | ||
const <OpenFoodFactsLanguage>[], | ||
final OpenFoodFactsCountry? country, | ||
final List<ProductField>? fields, | ||
final int? pageNumber, | ||
final int? pageSize, | ||
}) : super( | ||
language: language, | ||
languages: languages, | ||
country: country, | ||
fields: fields, | ||
additionalParameters: _convertToParametersList(pageNumber, pageSize), | ||
); | ||
|
||
static List<Parameter> _convertToParametersList( | ||
int? page, | ||
int? pageSize, | ||
) { | ||
final List<Parameter> result = <Parameter>[]; | ||
if (page != null) { | ||
result.add(PageNumber(page: page)); | ||
} | ||
if (pageSize != null) { | ||
result.add(PageSize(size: pageSize)); | ||
} | ||
return result; | ||
} | ||
|
||
@override | ||
String getUriPath() => '/state/to-be-completed.json'; | ||
} |
Oops, something went wrong.