feat: slim meal_diary — derive name and nutrition from dish/recipe
Remove denormalized columns (name, calories, protein_g, fat_g, carbs_g) from meal_diary. Name is now resolved via JOIN with dishes/dish_translations; macros are computed as recipe.*_per_serving * portions at query time. - Add dish.Repository.FindOrCreateRecipe: finds or creates a minimal recipe stub seeded with AI-estimated macros - recognition/handler: resolve recipe_id synchronously per candidate; simplify enrichDishInBackground to translations-only - diary/handler: accept dish_id OR name; always resolve recipe_id via FindOrCreateRecipe before INSERT - diary/entity: DishID is now non-nullable string; CreateRequest drops macros - diary/repository: ListByDate and Create use JOIN to return computed macros - ai/types: add RecipeID field to DishCandidate - Update tests and wire_gen accordingly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,6 @@ import '../../features/products/add_product_screen.dart';
|
||||
import '../../features/scan/scan_screen.dart';
|
||||
import '../../features/scan/recognition_confirm_screen.dart';
|
||||
import '../../features/scan/recognition_service.dart';
|
||||
import '../../features/menu/diary_screen.dart';
|
||||
import '../../features/menu/menu_screen.dart';
|
||||
import '../../features/menu/shopping_list_screen.dart';
|
||||
import '../../features/recipes/recipe_detail_screen.dart';
|
||||
@@ -129,14 +128,6 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
return ShoppingListScreen(week: week);
|
||||
},
|
||||
),
|
||||
// Diary — full-screen, no bottom nav.
|
||||
GoRoute(
|
||||
path: '/menu/diary',
|
||||
builder: (context, state) {
|
||||
final date = state.extra as String? ?? '';
|
||||
return DiaryScreen(date: date);
|
||||
},
|
||||
),
|
||||
// Scan / recognition flow — all without bottom nav.
|
||||
GoRoute(
|
||||
path: '/scan',
|
||||
|
||||
@@ -89,7 +89,7 @@ class HomeScreen extends ConsumerWidget {
|
||||
_ExpiringBanner(items: expiringSoon),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
_QuickActionsRow(date: dateString),
|
||||
_QuickActionsRow(),
|
||||
if (recommendations.isNotEmpty) ...[
|
||||
const SizedBox(height: 20),
|
||||
_SectionTitle('Рекомендуем приготовить'),
|
||||
@@ -988,8 +988,7 @@ class _ExpiringBanner extends StatelessWidget {
|
||||
// ── Quick actions ─────────────────────────────────────────────
|
||||
|
||||
class _QuickActionsRow extends StatelessWidget {
|
||||
final String date;
|
||||
const _QuickActionsRow({required this.date});
|
||||
const _QuickActionsRow();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -1010,14 +1009,6 @@ class _QuickActionsRow extends StatelessWidget {
|
||||
onTap: () => context.push('/menu'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _ActionButton(
|
||||
icon: Icons.book_outlined,
|
||||
label: 'Дневник',
|
||||
onTap: () => context.push('/menu/diary', extra: date),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -150,20 +150,6 @@ class _MenuContent extends StatelessWidget {
|
||||
label: const Text('Список покупок'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
final today = DateTime.now();
|
||||
final dateStr =
|
||||
'${today.year}-${today.month.toString().padLeft(2, '0')}-${today.day.toString().padLeft(2, '0')}';
|
||||
context.push('/menu/diary', extra: dateStr);
|
||||
},
|
||||
icon: const Icon(Icons.book_outlined),
|
||||
label: const Text('Дневник питания'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ class _DishResultSheetState extends ConsumerState<DishResultSheet> {
|
||||
'carbs_g': scaledCarbs,
|
||||
'portion_g': _portionGrams,
|
||||
'source': 'recognition',
|
||||
if (_selected.dishId != null) 'dish_id': _selected.dishId,
|
||||
});
|
||||
if (mounted) widget.onAdded();
|
||||
} catch (addError) {
|
||||
|
||||
@@ -65,6 +65,7 @@ class ReceiptResult {
|
||||
|
||||
/// A single dish recognition candidate with estimated nutrition for the portion in the photo.
|
||||
class DishCandidate {
|
||||
final String? dishId;
|
||||
final String dishName;
|
||||
final int weightGrams;
|
||||
final double calories;
|
||||
@@ -74,6 +75,7 @@ class DishCandidate {
|
||||
final double confidence;
|
||||
|
||||
const DishCandidate({
|
||||
this.dishId,
|
||||
required this.dishName,
|
||||
required this.weightGrams,
|
||||
required this.calories,
|
||||
@@ -85,6 +87,7 @@ class DishCandidate {
|
||||
|
||||
factory DishCandidate.fromJson(Map<String, dynamic> json) {
|
||||
return DishCandidate(
|
||||
dishId: json['dish_id'] as String?,
|
||||
dishName: json['dish_name'] as String? ?? '',
|
||||
weightGrams: json['weight_grams'] as int? ?? 0,
|
||||
calories: (json['calories'] as num?)?.toDouble() ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user