Backend: - GET /dishes/search — hybrid FTS (english + simple) + trgm + ILIKE search - GET /diary/recent — recently used dishes and products for the current user - product search upgraded: FTS on canonical_name and product_aliases, ranked by GREATEST(ts_rank, similarity) - importoff: collect product_name_ru/de/fr/... as product_aliases for multilingual search (e.g. "сникерс" → "Snickers") - migrations: FTS + trgm indexes merged into 001_initial_schema.sql (002 removed) Flutter: - FoodSearchSheet: debounced search field, recently-used section, product/dish results, scan-photo and barcode chips - DishPortionSheet: quick ½/1/1½/2 buttons + custom input - + button in meal card now opens FoodSearchSheet instead of going directly to AI scan - 7 new l10n keys across all 12 languages Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
2.1 KiB
Go
59 lines
2.1 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
|
|
GetRecentFn func(ctx context.Context, userID string, limit int) ([]*diary.RecentDiaryItem, 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)
|
|
}
|
|
|
|
func (m *MockDiaryRepository) GetRecent(ctx context.Context, userID string, limit int) ([]*diary.RecentDiaryItem, error) {
|
|
if m.GetRecentFn != nil {
|
|
return m.GetRecentFn(ctx, userID, limit)
|
|
}
|
|
return []*diary.RecentDiaryItem{}, nil
|
|
}
|