forked from openfoodfacts/smooth-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: openfoodfacts#2315 - added 4 user-related searches in the profi…
…le screen New files: * `contributor_product_query.dart`: User Product Search, in "contributor" mode. * `informer_product_query.dart`: User Product Search, in "informer" mode. * `paged_search_product_query.dart`: Back-end paged queries around search. * `paged_user_product_query.dart`: Back-end paged queries around User. * `photographer_product_query.dart`: User Product Search, in "photographer" mode. * `to_be_completed_product_query.dart`: User Product Search, in "to be completed" mode. Impacted files: * `category_product_query.dart`: refactored with new class `PagedSearchProductQuery` * `keywords_product_query.dart`: refactored with new class `PagedSearchProductQuery` * `paged_product_query.dart`: now limited to page management * `product_list.dart`: added `enum`s and constructors around user queries * `product_list_page.dart`: added cases for the new 4 product list types * `product_query_page_helper.dart`: added cases for the new 4 product list types * `user_preferences_account.dart`
- Loading branch information
1 parent
3ae4791
commit 54166e5
Showing
13 changed files
with
314 additions
and
23 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
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: 21 additions & 0 deletions
21
packages/smooth_app/lib/database/contributor_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,21 @@ | ||
import 'package:smooth_app/data_models/product_list.dart'; | ||
import 'package:smooth_app/database/paged_user_product_query.dart'; | ||
|
||
/// User Product Search, in "contributor" mode. | ||
class ContributorProductQuery extends PagedUserProductQuery { | ||
ContributorProductQuery(final String userId) : super(userId); | ||
|
||
@override | ||
ProductList getProductList() => ProductList.contributor( | ||
userId, | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
); | ||
|
||
@override | ||
String getPath() => 'contributor/$userId.json'; | ||
|
||
@override | ||
String toString() => | ||
'ContributorProductQuery("$userId", $pageSize, $pageNumber)'; | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/smooth_app/lib/database/informer_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,21 @@ | ||
import 'package:smooth_app/data_models/product_list.dart'; | ||
import 'package:smooth_app/database/paged_user_product_query.dart'; | ||
|
||
/// User Product Search, in "informer" mode. | ||
class InformerProductQuery extends PagedUserProductQuery { | ||
InformerProductQuery(final String userId) : super(userId); | ||
|
||
@override | ||
ProductList getProductList() => ProductList.informer( | ||
userId, | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
); | ||
|
||
@override | ||
String getPath() => 'informer/$userId.json'; | ||
|
||
@override | ||
String toString() => | ||
'InformerProductQuery("$userId", $pageSize, $pageNumber)'; | ||
} |
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
24 changes: 24 additions & 0 deletions
24
packages/smooth_app/lib/database/paged_search_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,24 @@ | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:smooth_app/database/paged_product_query.dart'; | ||
import 'package:smooth_app/database/product_query.dart'; | ||
|
||
/// Back-end paged queries around search. | ||
abstract class PagedSearchProductQuery extends PagedProductQuery { | ||
Parameter getParameter(); | ||
|
||
@override | ||
Future<SearchResult> getSearchResult() async => | ||
OpenFoodAPIClient.searchProducts( | ||
ProductQuery.getUser(), | ||
ProductSearchQueryConfiguration( | ||
fields: ProductQuery.fields, | ||
parametersList: <Parameter>[ | ||
PageSize(size: pageSize), | ||
PageNumber(page: pageNumber), | ||
getParameter(), | ||
], | ||
language: ProductQuery.getLanguage(), | ||
country: ProductQuery.getCountry(), | ||
), | ||
); | ||
} |
59 changes: 59 additions & 0 deletions
59
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
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: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); | ||
|
||
final String userId; | ||
|
||
@override | ||
Future<SearchResult> getSearchResult() async => _searchProducts( | ||
getPath(), | ||
ProductQuery.getUser(), | ||
pageSize, | ||
pageNumber, | ||
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 Uri uri = UriHelper.getUri( | ||
path: path, | ||
queryType: queryType, | ||
queryParameters: <String, String>{ | ||
'page_size': '$pageSize', | ||
'page': '$pageNumber', | ||
}, | ||
); | ||
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; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/smooth_app/lib/database/photographer_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,21 @@ | ||
import 'package:smooth_app/data_models/product_list.dart'; | ||
import 'package:smooth_app/database/paged_user_product_query.dart'; | ||
|
||
/// User Product Search, in "photographer" mode. | ||
class PhotographerProductQuery extends PagedUserProductQuery { | ||
PhotographerProductQuery(final String userId) : super(userId); | ||
|
||
@override | ||
ProductList getProductList() => ProductList.photographer( | ||
userId, | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
); | ||
|
||
@override | ||
String getPath() => 'photographer/$userId.json'; | ||
|
||
@override | ||
String toString() => | ||
'PhotographerProductQuery("$userId", $pageSize, $pageNumber)'; | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/smooth_app/lib/database/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,21 @@ | ||
import 'package:smooth_app/data_models/product_list.dart'; | ||
import 'package:smooth_app/database/paged_user_product_query.dart'; | ||
|
||
/// User Product Search, in "to be completed" mode. | ||
class ToBeCompletedProductQuery extends PagedUserProductQuery { | ||
ToBeCompletedProductQuery(final String userId) : super(userId); | ||
|
||
@override | ||
ProductList getProductList() => ProductList.toBeCompleted( | ||
userId, | ||
pageSize: pageSize, | ||
pageNumber: pageNumber, | ||
); | ||
|
||
@override | ||
String getPath() => 'informer/$userId/state/to-be-completed.json'; | ||
|
||
@override | ||
String toString() => | ||
'ToBeCompletedProductQuery("$userId", $pageSize, $pageNumber)'; | ||
} |
Oops, something went wrong.