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: 972 - new "product_type" field for Product #973

Merged
merged 1 commit into from
Sep 14, 2024
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
1 change: 1 addition & 0 deletions lib/openfoodfacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export 'src/model/parameter/without_additives.dart';
export 'src/model/per_size.dart';
export 'src/model/product.dart';
export 'src/model/product_freshness.dart';
export 'src/model/product_type.dart';
export 'src/model/product_image.dart';
export 'src/model/product_packaging.dart';
export 'src/model/product_result_field_answer.dart';
Expand Down
5 changes: 5 additions & 0 deletions lib/src/model/product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'nutriments.dart';
import 'owner_field.dart';
import 'product_image.dart';
import 'product_packaging.dart';
import 'product_type.dart';
import '../interface/json_object.dart';
import '../utils/json_helper.dart';
import '../utils/language_helper.dart';
Expand Down Expand Up @@ -90,6 +91,10 @@ class Product extends JsonObject {
@JsonKey(name: 'code')
String? barcode;

/// Type of the product (e.g. "pet food").
@JsonKey(name: 'product_type')
ProductType? productType;

/// Product name, either set directly or taken from one of the localizations.
///
/// Rather use [productNameInLanguages] instead.
Expand Down
10 changes: 10 additions & 0 deletions lib/src/model/product.g.dart

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

32 changes: 32 additions & 0 deletions lib/src/model/product_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:json_annotation/json_annotation.dart';
import 'off_tagged.dart';
import '../prices/flavor.dart';
import '../utils/server_type.dart';

/// Type used at the [Product] level (e.g. "this is a pet food product").
///
/// Somehow redundant with [ServerType] and [Flavor].
enum ProductType implements OffTagged {
@JsonValue('food')
food(offTag: 'food'),

@JsonValue('beauty')
beauty(offTag: 'beauty'),

@JsonValue('petfood')
petFood(offTag: 'petfood'),

@JsonValue('product')
product(offTag: 'product');

const ProductType({
required this.offTag,
});

@override
final String offTag;

/// Returns the first [ProductType] that matches the [offTag].
static ProductType? fromOffTag(final String? offTag) =>
OffTagged.fromOffTag(offTag, ProductType.values) as ProductType?;
}
Loading