feat: core schema redesign — dishes, structured recipes, cuisines, tags (iteration 7)
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>
This commit is contained in:
@@ -1,28 +1,18 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
import "time"
|
||||
|
||||
// Recipe is a recipe record in the database.
|
||||
// Title, Description, Ingredients, and Steps hold the content for the language
|
||||
// resolved at query time (English by default, or from recipe_translations when
|
||||
// a matching row exists for the requested language).
|
||||
// Recipe is a cooking variant of a Dish in the catalog.
|
||||
// It links to a Dish for all presentational data (name, image, cuisine, tags).
|
||||
type Recipe struct {
|
||||
ID string `json:"id"`
|
||||
Source string `json:"source"` // spoonacular | ai | user
|
||||
SpoonacularID *int `json:"spoonacular_id"`
|
||||
ID string `json:"id"`
|
||||
DishID string `json:"dish_id"`
|
||||
Source string `json:"source"` // ai | user | spoonacular
|
||||
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
|
||||
Cuisine *string `json:"cuisine"`
|
||||
Difficulty *string `json:"difficulty"` // easy | medium | hard
|
||||
PrepTimeMin *int `json:"prep_time_min"`
|
||||
CookTimeMin *int `json:"cook_time_min"`
|
||||
Servings *int `json:"servings"`
|
||||
ImageURL *string `json:"image_url"`
|
||||
Difficulty *string `json:"difficulty"`
|
||||
PrepTimeMin *int `json:"prep_time_min"`
|
||||
CookTimeMin *int `json:"cook_time_min"`
|
||||
Servings *int `json:"servings"`
|
||||
|
||||
CaloriesPerServing *float64 `json:"calories_per_serving"`
|
||||
ProteinPerServing *float64 `json:"protein_per_serving"`
|
||||
@@ -30,29 +20,29 @@ type Recipe struct {
|
||||
CarbsPerServing *float64 `json:"carbs_per_serving"`
|
||||
FiberPerServing *float64 `json:"fiber_per_serving"`
|
||||
|
||||
Ingredients json.RawMessage `json:"ingredients"` // []RecipeIngredient
|
||||
Steps json.RawMessage `json:"steps"` // []RecipeStep
|
||||
Tags json.RawMessage `json:"tags"` // []string
|
||||
Ingredients []RecipeIngredient `json:"ingredients"`
|
||||
Steps []RecipeStep `json:"steps"`
|
||||
Notes *string `json:"notes,omitempty"`
|
||||
|
||||
AvgRating float64 `json:"avg_rating"`
|
||||
ReviewCount int `json:"review_count"`
|
||||
CreatedBy *string `json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// RecipeIngredient is a single ingredient in a recipe's JSONB array.
|
||||
// RecipeIngredient is a single ingredient row from recipe_ingredients.
|
||||
type RecipeIngredient struct {
|
||||
MappingID *string `json:"mapping_id"`
|
||||
Name string `json:"name"`
|
||||
Amount float64 `json:"amount"`
|
||||
Unit string `json:"unit"`
|
||||
Optional bool `json:"optional"`
|
||||
ID string `json:"id"`
|
||||
IngredientID *string `json:"ingredient_id"`
|
||||
Name string `json:"name"`
|
||||
Amount float64 `json:"amount"`
|
||||
UnitCode *string `json:"unit_code"`
|
||||
IsOptional bool `json:"is_optional"`
|
||||
SortOrder int `json:"sort_order"`
|
||||
}
|
||||
|
||||
// RecipeStep is a single step in a recipe's JSONB array.
|
||||
// RecipeStep is a single step row from recipe_steps.
|
||||
type RecipeStep struct {
|
||||
Number int `json:"number"`
|
||||
ID string `json:"id"`
|
||||
StepNumber int `json:"step_number"`
|
||||
Description string `json:"description"`
|
||||
TimerSeconds *int `json:"timer_seconds"`
|
||||
ImageURL *string `json:"image_url"`
|
||||
|
||||
Reference in New Issue
Block a user