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: 618 - added 6 contribution fields #636

Merged
merged 1 commit into from
Dec 5, 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
33 changes: 33 additions & 0 deletions lib/model/Product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,46 @@ class Product extends JsonObject {
toJson: JsonHelper.attributeGroupsToJson)
List<AttributeGroup>? attributeGroups;

/// Latest modification timestamp. Read-only.
@JsonKey(
name: 'last_modified_t',
includeIfNull: false,
fromJson: JsonHelper.timestampToDate,
toJson: JsonHelper.dateToTimestamp)
DateTime? lastModified;

/// Latest modification user id. Read-only.
@JsonKey(name: 'last_modified_by', includeIfNull: false)
String? lastModifiedBy;

/// Last check timestamp. Read-only.
@JsonKey(
name: 'last_checked_t',
includeIfNull: false,
fromJson: JsonHelper.timestampToDate,
toJson: JsonHelper.dateToTimestamp)
DateTime? lastChecked;

/// Last check user id. Read-only.
@JsonKey(name: 'last_checker', includeIfNull: false)
String? lastChecker;

/// Creation timestamp. Read-only.
@JsonKey(
name: 'created_t',
includeIfNull: false,
fromJson: JsonHelper.timestampToDate,
toJson: JsonHelper.dateToTimestamp)
DateTime? created;

/// Creation user id. Read-only.
@JsonKey(includeIfNull: false)
String? creator;

/// Editors. Read-only.
@JsonKey(name: 'editors_tags', includeIfNull: false)
List<String>? editors;

@JsonKey(name: 'ecoscore_grade', includeIfNull: false)
String? ecoscoreGrade;
@JsonKey(
Expand Down
15 changes: 15 additions & 0 deletions lib/model/Product.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/utils/ProductFields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ enum ProductField implements OffTagged {
ENVIRONMENT_IMPACT_LEVELS(offTag: 'environment_impact_level_tags'),
ATTRIBUTE_GROUPS(offTag: 'attribute_groups'),
LAST_MODIFIED(offTag: 'last_modified_t'),
LAST_MODIFIER(offTag: 'last_modified_by'),
LAST_CHECKED(offTag: 'last_checked_t'),
LAST_CHECKER(offTag: 'last_checker'),
CREATED(offTag: 'created_t'),
CREATOR(offTag: 'creator'),
EDITORS(offTag: 'editors_tags'),
ECOSCORE_GRADE(offTag: 'ecoscore_grade'),
ECOSCORE_SCORE(offTag: 'ecoscore_score'),
ECOSCORE_DATA(offTag: 'ecoscore_data'),
Expand Down
46 changes: 46 additions & 0 deletions test/api_getProduct_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,52 @@ void main() {
expect(result.product, isNotNull);
expect(result.product!.website, isNotNull);
expect(result.product!.website, isNotEmpty);

configuration = ProductQueryConfiguration(
'3033710065066',
fields: [
ProductField.LAST_CHECKED,
ProductField.LAST_CHECKER,
ProductField.LAST_MODIFIED,
ProductField.LAST_MODIFIER,
ProductField.CREATED,
ProductField.CREATOR,
ProductField.EDITORS,
],
version: ProductQueryVersion.v3,
);
result = await OpenFoodAPIClient.getProductV3(
configuration,
queryType: QueryType.PROD,
);
expect(result.status, ProductResultV3.statusSuccess);
expect(result.product, isNotNull);
expect(result.product!.lastModified, isNotNull);
expect(
JsonHelper.dateToTimestamp(result.product!.lastModified),
greaterThanOrEqualTo(1667683782),
); // value on 2022-12-05
expect(result.product!.lastModifiedBy, isNotNull);
expect(result.product!.lastModifiedBy, isNotEmpty);
expect(result.product!.lastChecked, isNotNull);
expect(
JsonHelper.dateToTimestamp(result.product!.lastChecked),
greaterThanOrEqualTo(1541687984),
); // value on 2022-12-05
expect(result.product!.lastChecker, isNotNull);
expect(result.product!.lastChecker, isNotEmpty);
expect(result.product!.created, isNotNull);
expect(
JsonHelper.dateToTimestamp(result.product!.created),
greaterThanOrEqualTo(1340658486),
); // value on 2022-12-05
expect(result.product!.creator, isNotNull);
expect(result.product!.creator, isNotEmpty);
expect(result.product!.editors, isNotNull);
expect(
result.product!.editors!.length,
greaterThanOrEqualTo(59),
); // value on 2022-12-05
});

group('no nutrition data', () {
Expand Down