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:
32
client/lib/features/diary/food_product_service.dart
Normal file
32
client/lib/features/diary/food_product_service.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import '../../core/api/api_client.dart';
|
||||
import '../../shared/models/product.dart';
|
||||
|
||||
/// Service for looking up catalog products by barcode or search query.
|
||||
/// Used in the diary flow to log pre-packaged foods.
|
||||
class FoodProductService {
|
||||
const FoodProductService(this._client);
|
||||
|
||||
final ApiClient _client;
|
||||
|
||||
/// Fetches catalog product by barcode. Returns null when not found.
|
||||
Future<CatalogProduct?> getByBarcode(String barcode) async {
|
||||
try {
|
||||
final data = await _client.get('/products/barcode/$barcode');
|
||||
return CatalogProduct.fromJson(data);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Searches catalog products by name query.
|
||||
Future<List<CatalogProduct>> searchProducts(String query) async {
|
||||
if (query.isEmpty) return [];
|
||||
final list = await _client.getList(
|
||||
'/products/search',
|
||||
params: {'q': query, 'limit': '10'},
|
||||
);
|
||||
return list
|
||||
.map((e) => CatalogProduct.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user