- migration 012: create ingredient_categories + ingredient_category_translations tables (7 slugs, Russian names); add ingredient_aliases (ingredient_id, lang, alias) with GIN trigram index; migrate aliases JSONB from ingredient_mappings and ingredient_translations; drop aliases columns and spoonacular_id; add UNIQUE (canonical_name) as conflict key - ingredient/model: remove SpoonacularID, add CategoryName for localized display - ingredient/repository: conflict on canonical_name; GetByID/Search join category translations and aliases lateral; new UpsertAliases (pgx batch), UpsertCategoryTranslation; remove GetBySpoonacularID; split scan helpers into scanMappingWrite / scanMappingRead - gemini/recognition: add IngredientTranslation type; IngredientClassification now carries Translations []IngredientTranslation instead of CanonicalNameRu; update ClassifyIngredient prompt to English with structured translations array - recognition/handler: update ingredientRepo interface; saveClassification uses UpsertAliases and iterates Translations - recipe/model: remove SpoonacularID from RecipeIngredient - integration tests: remove SpoonacularID fixtures, replace GetBySpoonacularID tests with GetByID, add UpsertAliases and UpsertCategoryTranslation tests - Flutter: remove canonicalNameRu from IngredientMapping, add categoryName; displayName returns server-resolved canonicalName; regenerate .g.dart Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package recipe
|
|
|
|
import (
|
|
"encoding/json"
|
|
"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).
|
|
type Recipe struct {
|
|
ID string `json:"id"`
|
|
Source string `json:"source"` // spoonacular | ai | user
|
|
SpoonacularID *int `json:"spoonacular_id"`
|
|
|
|
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"`
|
|
|
|
CaloriesPerServing *float64 `json:"calories_per_serving"`
|
|
ProteinPerServing *float64 `json:"protein_per_serving"`
|
|
FatPerServing *float64 `json:"fat_per_serving"`
|
|
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
|
|
|
|
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"`
|
|
}
|
|
|
|
// RecipeIngredient is a single ingredient in a recipe's JSONB array.
|
|
type RecipeIngredient struct {
|
|
MappingID *string `json:"mapping_id"`
|
|
Name string `json:"name"`
|
|
Amount float64 `json:"amount"`
|
|
Unit string `json:"unit"`
|
|
Optional bool `json:"optional"`
|
|
}
|
|
|
|
// RecipeStep is a single step in a recipe's JSONB array.
|
|
type RecipeStep struct {
|
|
Number int `json:"number"`
|
|
Description string `json:"description"`
|
|
TimerSeconds *int `json:"timer_seconds"`
|
|
ImageURL *string `json:"image_url"`
|
|
}
|