Replaces the flat JSONB-based recipe schema with a normalized relational model:
Schema (migrations consolidated to 001_initial_schema + 002_seed_data):
- New: dishes, dish_translations, dish_tags — canonical dish catalog
- New: cuisines, tags, dish_categories with _translations tables + full seed data
- New: recipe_ingredients, recipe_steps with _translations (replaces JSONB blobs)
- New: user_saved_recipes thin bookmark (drops saved_recipes + saved_recipe_translations)
- New: product_ingredients M2M table
- recipes: now a cooking variant of a dish (dish_id FK, no title/JSONB columns)
- recipe_translations: repurposed to per-language notes only
- products: mapping_id → primary_ingredient_id
- menu_items: recipe_id FK → recipes; adds dish_id
- meal_diary: adds dish_id, recipe_id → recipes, portion_g
Backend (Go):
- New packages: internal/cuisine, internal/tag, internal/dish (registry + handler + repo)
- New GET /cuisines, GET /tags (public), GET /dishes, GET /dishes/{id}, GET /recipes/{id}
- recipe, savedrecipe, menu, diary, product, ingredient packages updated for new schema
Flutter:
- New models: Cuisine, Tag; new providers: cuisineNamesProvider, tagNamesProvider
- recipe.dart: RecipeIngredient gains unit_code + effectiveUnit getter
- saved_recipe.dart: thin model, manual fromJson, computed nutrition getter
- diary_entry.dart: adds dishId, recipeId, portionG
- recipe_detail_screen.dart: localized cuisine/tag names via providers
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
133 lines
3.0 KiB
Dart
133 lines
3.0 KiB
Dart
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
part 'recipe.g.dart';
|
|
|
|
@JsonSerializable(explicitToJson: true)
|
|
class Recipe {
|
|
final String title;
|
|
final String description;
|
|
final String cuisine;
|
|
final String difficulty;
|
|
|
|
@JsonKey(name: 'prep_time_min')
|
|
final int prepTimeMin;
|
|
|
|
@JsonKey(name: 'cook_time_min')
|
|
final int cookTimeMin;
|
|
|
|
final int servings;
|
|
|
|
@JsonKey(name: 'image_url', defaultValue: '')
|
|
final String imageUrl;
|
|
|
|
@JsonKey(name: 'image_query', defaultValue: '')
|
|
final String imageQuery;
|
|
|
|
@JsonKey(defaultValue: [])
|
|
final List<RecipeIngredient> ingredients;
|
|
|
|
@JsonKey(defaultValue: [])
|
|
final List<RecipeStep> steps;
|
|
|
|
@JsonKey(defaultValue: [])
|
|
final List<String> tags;
|
|
|
|
@JsonKey(name: 'nutrition_per_serving')
|
|
final NutritionInfo? nutrition;
|
|
|
|
const Recipe({
|
|
required this.title,
|
|
required this.description,
|
|
required this.cuisine,
|
|
required this.difficulty,
|
|
required this.prepTimeMin,
|
|
required this.cookTimeMin,
|
|
required this.servings,
|
|
this.imageUrl = '',
|
|
this.imageQuery = '',
|
|
this.ingredients = const [],
|
|
this.steps = const [],
|
|
this.tags = const [],
|
|
this.nutrition,
|
|
});
|
|
|
|
factory Recipe.fromJson(Map<String, dynamic> json) => _$RecipeFromJson(json);
|
|
Map<String, dynamic> toJson() => _$RecipeToJson(this);
|
|
}
|
|
|
|
@JsonSerializable()
|
|
class RecipeIngredient {
|
|
final String name;
|
|
final double amount;
|
|
|
|
/// Unit from Gemini recommendations (free-form string).
|
|
@JsonKey(defaultValue: '')
|
|
final String unit;
|
|
|
|
/// Unit code from the DB-backed saved recipes endpoint.
|
|
@JsonKey(name: 'unit_code')
|
|
final String? unitCode;
|
|
|
|
const RecipeIngredient({
|
|
required this.name,
|
|
required this.amount,
|
|
this.unit = '',
|
|
this.unitCode,
|
|
});
|
|
|
|
/// Returns the best available unit identifier for display / lookup.
|
|
String get effectiveUnit => unitCode ?? unit;
|
|
|
|
factory RecipeIngredient.fromJson(Map<String, dynamic> json) =>
|
|
_$RecipeIngredientFromJson(json);
|
|
Map<String, dynamic> toJson() => _$RecipeIngredientToJson(this);
|
|
}
|
|
|
|
@JsonSerializable()
|
|
class RecipeStep {
|
|
final int number;
|
|
final String description;
|
|
|
|
@JsonKey(name: 'timer_seconds')
|
|
final int? timerSeconds;
|
|
|
|
const RecipeStep({
|
|
required this.number,
|
|
required this.description,
|
|
this.timerSeconds,
|
|
});
|
|
|
|
factory RecipeStep.fromJson(Map<String, dynamic> json) =>
|
|
_$RecipeStepFromJson(json);
|
|
Map<String, dynamic> toJson() => _$RecipeStepToJson(this);
|
|
}
|
|
|
|
@JsonSerializable()
|
|
class NutritionInfo {
|
|
final double calories;
|
|
|
|
@JsonKey(name: 'protein_g')
|
|
final double proteinG;
|
|
|
|
@JsonKey(name: 'fat_g')
|
|
final double fatG;
|
|
|
|
@JsonKey(name: 'carbs_g')
|
|
final double carbsG;
|
|
|
|
@JsonKey(defaultValue: true)
|
|
final bool approximate;
|
|
|
|
const NutritionInfo({
|
|
required this.calories,
|
|
required this.proteinG,
|
|
required this.fatG,
|
|
required this.carbsG,
|
|
this.approximate = true,
|
|
});
|
|
|
|
factory NutritionInfo.fromJson(Map<String, dynamic> json) =>
|
|
_$NutritionInfoFromJson(json);
|
|
Map<String, dynamic> toJson() => _$NutritionInfoToJson(this);
|
|
}
|