feat: rename ingredients→products, products→user_products; add barcode/OFF import
- Rename catalog: ingredient/* → product/* (canonical_name, barcode, nutrition per 100g)
- Rename pantry: product/* → userproduct/* (user-owned items with expiry)
- Squash migrations into single 001_initial_schema.sql (clean-db baseline)
- product_categories: add English canonical name column; fix COALESCE in queries
- Remove product_translations: product names are stored in their original language
- Add default_unit_name to product API responses via unit_translations JOIN
- Add cmd/importoff: bulk import from OpenFoodFacts JSONL dump (COPY + ON CONFLICT)
- Diary: support product_id entries alongside dish_id (CHECK num_nonnulls = 1)
- Home: getLoggedCalories joins both recipes and catalog products
- Flutter: rename models/providers/services to match backend rename
- Flutter: add barcode scan flow for diary (mobile_scanner, product_portion_sheet)
- Flutter: localise 6 new keys across 12 languages (barcode scan, portion weight)
- Routes: GET /products/search, GET /products/barcode/{barcode}, /user-products
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'ingredient_mapping.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class IngredientMapping {
|
||||
final String id;
|
||||
@JsonKey(name: 'canonical_name')
|
||||
final String canonicalName;
|
||||
@JsonKey(name: 'category_name')
|
||||
final String? categoryName;
|
||||
final String? category;
|
||||
@JsonKey(name: 'default_unit')
|
||||
final String? defaultUnit;
|
||||
@JsonKey(name: 'storage_days')
|
||||
final int? storageDays;
|
||||
|
||||
const IngredientMapping({
|
||||
required this.id,
|
||||
required this.canonicalName,
|
||||
this.categoryName,
|
||||
this.category,
|
||||
this.defaultUnit,
|
||||
this.storageDays,
|
||||
});
|
||||
|
||||
/// Display name is the server-resolved canonical name (language-aware from backend).
|
||||
String get displayName => canonicalName;
|
||||
|
||||
factory IngredientMapping.fromJson(Map<String, dynamic> json) =>
|
||||
_$IngredientMappingFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$IngredientMappingToJson(this);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'ingredient_mapping.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
IngredientMapping _$IngredientMappingFromJson(Map<String, dynamic> json) =>
|
||||
IngredientMapping(
|
||||
id: json['id'] as String,
|
||||
canonicalName: json['canonical_name'] as String,
|
||||
categoryName: json['category_name'] as String?,
|
||||
category: json['category'] as String?,
|
||||
defaultUnit: json['default_unit'] as String?,
|
||||
storageDays: (json['storage_days'] as num?)?.toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$IngredientMappingToJson(IngredientMapping instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'canonical_name': instance.canonicalName,
|
||||
'category_name': instance.categoryName,
|
||||
'category': instance.category,
|
||||
'default_unit': instance.defaultUnit,
|
||||
'storage_days': instance.storageDays,
|
||||
};
|
||||
@@ -2,45 +2,48 @@ import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'product.g.dart';
|
||||
|
||||
/// Catalog product (shared nutrition database entry).
|
||||
@JsonSerializable()
|
||||
class Product {
|
||||
class CatalogProduct {
|
||||
final String id;
|
||||
@JsonKey(name: 'user_id')
|
||||
final String userId;
|
||||
@JsonKey(name: 'mapping_id')
|
||||
final String? mappingId;
|
||||
final String name;
|
||||
final double quantity;
|
||||
final String unit;
|
||||
@JsonKey(name: 'canonical_name')
|
||||
final String canonicalName;
|
||||
@JsonKey(name: 'category_name')
|
||||
final String? categoryName;
|
||||
final String? category;
|
||||
@JsonKey(name: 'default_unit')
|
||||
final String? defaultUnit;
|
||||
@JsonKey(name: 'storage_days')
|
||||
final int storageDays;
|
||||
@JsonKey(name: 'added_at')
|
||||
final DateTime addedAt;
|
||||
@JsonKey(name: 'expires_at')
|
||||
final DateTime expiresAt;
|
||||
@JsonKey(name: 'days_left')
|
||||
final int daysLeft;
|
||||
@JsonKey(name: 'expiring_soon')
|
||||
final bool expiringSoon;
|
||||
final int? storageDays;
|
||||
final String? barcode;
|
||||
@JsonKey(name: 'calories_per_100g')
|
||||
final double? caloriesPer100g;
|
||||
@JsonKey(name: 'protein_per_100g')
|
||||
final double? proteinPer100g;
|
||||
@JsonKey(name: 'fat_per_100g')
|
||||
final double? fatPer100g;
|
||||
@JsonKey(name: 'carbs_per_100g')
|
||||
final double? carbsPer100g;
|
||||
|
||||
const Product({
|
||||
const CatalogProduct({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
this.mappingId,
|
||||
required this.name,
|
||||
required this.quantity,
|
||||
required this.unit,
|
||||
required this.canonicalName,
|
||||
this.categoryName,
|
||||
this.category,
|
||||
required this.storageDays,
|
||||
required this.addedAt,
|
||||
required this.expiresAt,
|
||||
required this.daysLeft,
|
||||
required this.expiringSoon,
|
||||
this.defaultUnit,
|
||||
this.storageDays,
|
||||
this.barcode,
|
||||
this.caloriesPer100g,
|
||||
this.proteinPer100g,
|
||||
this.fatPer100g,
|
||||
this.carbsPer100g,
|
||||
});
|
||||
|
||||
factory Product.fromJson(Map<String, dynamic> json) =>
|
||||
_$ProductFromJson(json);
|
||||
/// Display name is the server-resolved canonical name (language-aware from backend).
|
||||
String get displayName => canonicalName;
|
||||
|
||||
Map<String, dynamic> toJson() => _$ProductToJson(this);
|
||||
factory CatalogProduct.fromJson(Map<String, dynamic> json) =>
|
||||
_$CatalogProductFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$CatalogProductToJson(this);
|
||||
}
|
||||
|
||||
@@ -6,32 +6,32 @@ part of 'product.dart';
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Product _$ProductFromJson(Map<String, dynamic> json) => Product(
|
||||
id: json['id'] as String,
|
||||
userId: json['user_id'] as String,
|
||||
mappingId: json['mapping_id'] as String?,
|
||||
name: json['name'] as String,
|
||||
quantity: (json['quantity'] as num).toDouble(),
|
||||
unit: json['unit'] as String,
|
||||
category: json['category'] as String?,
|
||||
storageDays: (json['storage_days'] as num).toInt(),
|
||||
addedAt: DateTime.parse(json['added_at'] as String),
|
||||
expiresAt: DateTime.parse(json['expires_at'] as String),
|
||||
daysLeft: (json['days_left'] as num).toInt(),
|
||||
expiringSoon: json['expiring_soon'] as bool,
|
||||
);
|
||||
CatalogProduct _$CatalogProductFromJson(Map<String, dynamic> json) =>
|
||||
CatalogProduct(
|
||||
id: json['id'] as String,
|
||||
canonicalName: json['canonical_name'] as String,
|
||||
categoryName: json['category_name'] as String?,
|
||||
category: json['category'] as String?,
|
||||
defaultUnit: json['default_unit'] as String?,
|
||||
storageDays: (json['storage_days'] as num?)?.toInt(),
|
||||
barcode: json['barcode'] as String?,
|
||||
caloriesPer100g: (json['calories_per_100g'] as num?)?.toDouble(),
|
||||
proteinPer100g: (json['protein_per_100g'] as num?)?.toDouble(),
|
||||
fatPer100g: (json['fat_per_100g'] as num?)?.toDouble(),
|
||||
carbsPer100g: (json['carbs_per_100g'] as num?)?.toDouble(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ProductToJson(Product instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'user_id': instance.userId,
|
||||
'mapping_id': instance.mappingId,
|
||||
'name': instance.name,
|
||||
'quantity': instance.quantity,
|
||||
'unit': instance.unit,
|
||||
'category': instance.category,
|
||||
'storage_days': instance.storageDays,
|
||||
'added_at': instance.addedAt.toIso8601String(),
|
||||
'expires_at': instance.expiresAt.toIso8601String(),
|
||||
'days_left': instance.daysLeft,
|
||||
'expiring_soon': instance.expiringSoon,
|
||||
};
|
||||
Map<String, dynamic> _$CatalogProductToJson(CatalogProduct instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'canonical_name': instance.canonicalName,
|
||||
'category_name': instance.categoryName,
|
||||
'category': instance.category,
|
||||
'default_unit': instance.defaultUnit,
|
||||
'storage_days': instance.storageDays,
|
||||
'barcode': instance.barcode,
|
||||
'calories_per_100g': instance.caloriesPer100g,
|
||||
'protein_per_100g': instance.proteinPer100g,
|
||||
'fat_per_100g': instance.fatPer100g,
|
||||
'carbs_per_100g': instance.carbsPer100g,
|
||||
};
|
||||
|
||||
46
client/lib/shared/models/user_product.dart
Normal file
46
client/lib/shared/models/user_product.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'user_product.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class UserProduct {
|
||||
final String id;
|
||||
@JsonKey(name: 'user_id')
|
||||
final String userId;
|
||||
@JsonKey(name: 'primary_product_id')
|
||||
final String? primaryProductId;
|
||||
final String name;
|
||||
final double quantity;
|
||||
final String unit;
|
||||
final String? category;
|
||||
@JsonKey(name: 'storage_days')
|
||||
final int storageDays;
|
||||
@JsonKey(name: 'added_at')
|
||||
final DateTime addedAt;
|
||||
@JsonKey(name: 'expires_at')
|
||||
final DateTime expiresAt;
|
||||
@JsonKey(name: 'days_left')
|
||||
final int daysLeft;
|
||||
@JsonKey(name: 'expiring_soon')
|
||||
final bool expiringSoon;
|
||||
|
||||
const UserProduct({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
this.primaryProductId,
|
||||
required this.name,
|
||||
required this.quantity,
|
||||
required this.unit,
|
||||
this.category,
|
||||
required this.storageDays,
|
||||
required this.addedAt,
|
||||
required this.expiresAt,
|
||||
required this.daysLeft,
|
||||
required this.expiringSoon,
|
||||
});
|
||||
|
||||
factory UserProduct.fromJson(Map<String, dynamic> json) =>
|
||||
_$UserProductFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$UserProductToJson(this);
|
||||
}
|
||||
38
client/lib/shared/models/user_product.g.dart
Normal file
38
client/lib/shared/models/user_product.g.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'user_product.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
UserProduct _$UserProductFromJson(Map<String, dynamic> json) => UserProduct(
|
||||
id: json['id'] as String,
|
||||
userId: json['user_id'] as String,
|
||||
primaryProductId: json['primary_product_id'] as String?,
|
||||
name: json['name'] as String,
|
||||
quantity: (json['quantity'] as num).toDouble(),
|
||||
unit: json['unit'] as String,
|
||||
category: json['category'] as String?,
|
||||
storageDays: (json['storage_days'] as num).toInt(),
|
||||
addedAt: DateTime.parse(json['added_at'] as String),
|
||||
expiresAt: DateTime.parse(json['expires_at'] as String),
|
||||
daysLeft: (json['days_left'] as num).toInt(),
|
||||
expiringSoon: json['expiring_soon'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$UserProductToJson(UserProduct instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'user_id': instance.userId,
|
||||
'primary_product_id': instance.primaryProductId,
|
||||
'name': instance.name,
|
||||
'quantity': instance.quantity,
|
||||
'unit': instance.unit,
|
||||
'category': instance.category,
|
||||
'storage_days': instance.storageDays,
|
||||
'added_at': instance.addedAt.toIso8601String(),
|
||||
'expires_at': instance.expiresAt.toIso8601String(),
|
||||
'days_left': instance.daysLeft,
|
||||
'expiring_soon': instance.expiringSoon,
|
||||
};
|
||||
Reference in New Issue
Block a user