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: #2425 - added "all products to be completed" item (in user page) #2441

Merged
merged 2 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/smooth_app/lib/data_models/product_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ enum ProductListType {

/// End-user for products to be completed
HTTP_USER_TO_BE_COMPLETED,

/// For products to be completed, all of them.
HTTP_ALL_TO_BE_COMPLETED,
}

extension ProductListTypeExtension on ProductListType {
Expand All @@ -46,6 +49,8 @@ extension ProductListTypeExtension on ProductListType {
return 'http/user/photographer';
case ProductListType.HTTP_USER_TO_BE_COMPLETED:
return 'http/user/to_be_completed';
case ProductListType.HTTP_ALL_TO_BE_COMPLETED:
return 'http/all/to_be_completed';
case ProductListType.HISTORY:
return 'history';
case ProductListType.USER:
Expand Down Expand Up @@ -128,6 +133,15 @@ class ProductList {
pageNumber: pageNumber,
);

ProductList.allToBeCompleted({
required int pageSize,
required int pageNumber,
}) : this._(
listType: ProductListType.HTTP_ALL_TO_BE_COMPLETED,
pageSize: pageSize,
pageNumber: pageNumber,
);

ProductList.history() : this._(listType: ProductListType.HISTORY);

ProductList.scanSession() : this._(listType: ProductListType.SCAN_SESSION);
Expand Down Expand Up @@ -224,6 +238,7 @@ class ProductList {
case ProductListType.HTTP_USER_INFORMER:
case ProductListType.HTTP_USER_PHOTOGRAPHER:
case ProductListType.HTTP_USER_TO_BE_COMPLETED:
case ProductListType.HTTP_ALL_TO_BE_COMPLETED:
case ProductListType.USER:
return false;
case ProductListType.SCAN_SESSION:
Expand All @@ -244,6 +259,7 @@ class ProductList {
case ProductListType.HTTP_USER_INFORMER:
case ProductListType.HTTP_USER_PHOTOGRAPHER:
case ProductListType.HTTP_USER_TO_BE_COMPLETED:
case ProductListType.HTTP_ALL_TO_BE_COMPLETED:
return '$parameters,$pageSize,$pageNumber';
}
}
Expand Down
21 changes: 0 additions & 21 deletions packages/smooth_app/lib/database/contributor_product_query.dart

This file was deleted.

21 changes: 0 additions & 21 deletions packages/smooth_app/lib/database/informer_product_query.dart

This file was deleted.

99 changes: 50 additions & 49 deletions packages/smooth_app/lib/database/paged_user_product_query.dart
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 packages/smooth_app/lib/database/photographer_product_query.dart

This file was deleted.

This file was deleted.

6 changes: 5 additions & 1 deletion packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1350,10 +1350,14 @@
"@user_search_photographer_title": {
"description": "User search (photographer): list tile title"
},
"user_search_to_be_completed_title": "Products that need to be completed",
"user_search_to_be_completed_title": "My to-be-completed products",
"@user_search_to_be_completed_title": {
"description": "User search (to be completed): list tile title"
},
"all_search_to_be_completed_title": "All to-be-completed products",
"@all_search_to_be_completed_title": {
"description": "All products to be completed: list tile title"
},
"edit_product_action_retake_picture": "Retake photo",
"@edit_product_action_retake_picture": {
"description": "Product edition - FAB actions - retake a picture"
Expand Down
6 changes: 5 additions & 1 deletion packages/smooth_app/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1350,10 +1350,14 @@
"@user_search_photographer_title": {
"description": "User search (photographer): list tile title"
},
"user_search_to_be_completed_title": "Produits à compléter",
"user_search_to_be_completed_title": "Mes produits à compléter",
"@user_search_to_be_completed_title": {
"description": "User search (to be completed): list tile title"
},
"all_search_to_be_completed_title": "Tous les produits à compléter",
"@all_search_to_be_completed_title": {
"description": "All products to be completed: list tile title"
},
"edit_product_action_retake_picture": "Reprendre une photo",
"@edit_product_action_retake_picture": {
"description": "Product edition - FAB actions - retake a picture"
Expand Down
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)';
}
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';
}
Loading