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>
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package diary
|
|
|
|
import "time"
|
|
|
|
// Entry is a single meal diary record.
|
|
type Entry struct {
|
|
ID string `json:"id"`
|
|
Date string `json:"date"` // YYYY-MM-DD
|
|
MealType string `json:"meal_type"`
|
|
Name string `json:"name"` // from dishes JOIN
|
|
Portions float64 `json:"portions"`
|
|
Calories *float64 `json:"calories,omitempty"` // recipe.calories_per_serving * portions
|
|
ProteinG *float64 `json:"protein_g,omitempty"`
|
|
FatG *float64 `json:"fat_g,omitempty"`
|
|
CarbsG *float64 `json:"carbs_g,omitempty"`
|
|
Source string `json:"source"`
|
|
DishID string `json:"dish_id"`
|
|
RecipeID *string `json:"recipe_id,omitempty"`
|
|
PortionG *float64 `json:"portion_g,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// CreateRequest is the body for POST /diary.
|
|
type CreateRequest struct {
|
|
Date string `json:"date"`
|
|
MealType string `json:"meal_type"`
|
|
Name string `json:"name"` // input-only; used if DishID is nil
|
|
Portions float64 `json:"portions"`
|
|
Source string `json:"source"`
|
|
DishID *string `json:"dish_id"`
|
|
RecipeID *string `json:"recipe_id"`
|
|
PortionG *float64 `json:"portion_g"`
|
|
}
|