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>
51 lines
1.8 KiB
Go
51 lines
1.8 KiB
Go
package mocks
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/food-ai/backend/internal/domain/diary"
|
|
)
|
|
|
|
// MockDishRepository is a test double implementing diary.DishRepository.
|
|
type MockDishRepository struct {
|
|
FindOrCreateFn func(ctx context.Context, name string) (string, bool, error)
|
|
}
|
|
|
|
func (m *MockDishRepository) FindOrCreate(ctx context.Context, name string) (string, bool, error) {
|
|
if m.FindOrCreateFn != nil {
|
|
return m.FindOrCreateFn(ctx, name)
|
|
}
|
|
return "", false, nil
|
|
}
|
|
|
|
// MockRecipeRepository is a test double implementing diary.RecipeRepository.
|
|
type MockRecipeRepository struct {
|
|
FindOrCreateRecipeFn func(ctx context.Context, dishID string, calories, proteinG, fatG, carbsG float64) (string, bool, error)
|
|
}
|
|
|
|
func (m *MockRecipeRepository) FindOrCreateRecipe(ctx context.Context, dishID string, calories, proteinG, fatG, carbsG float64) (string, bool, error) {
|
|
if m.FindOrCreateRecipeFn != nil {
|
|
return m.FindOrCreateRecipeFn(ctx, dishID, calories, proteinG, fatG, carbsG)
|
|
}
|
|
return "", false, nil
|
|
}
|
|
|
|
// MockDiaryRepository is a test double implementing diary.DiaryRepository.
|
|
type MockDiaryRepository struct {
|
|
ListByDateFn func(ctx context.Context, userID, date string) ([]*diary.Entry, error)
|
|
CreateFn func(ctx context.Context, userID string, req diary.CreateRequest) (*diary.Entry, error)
|
|
DeleteFn func(ctx context.Context, id, userID string) error
|
|
}
|
|
|
|
func (m *MockDiaryRepository) ListByDate(ctx context.Context, userID, date string) ([]*diary.Entry, error) {
|
|
return m.ListByDateFn(ctx, userID, date)
|
|
}
|
|
|
|
func (m *MockDiaryRepository) Create(ctx context.Context, userID string, req diary.CreateRequest) (*diary.Entry, error) {
|
|
return m.CreateFn(ctx, userID, req)
|
|
}
|
|
|
|
func (m *MockDiaryRepository) Delete(ctx context.Context, id, userID string) error {
|
|
return m.DeleteFn(ctx, id, userID)
|
|
}
|