feat: implement Iteration 2 — product management
Backend: - migrations/005: add pg_trgm extension + search indexes on ingredient_mappings - migrations/006: products table with computed expires_at column - ingredient: add Search method (aliases + ILIKE + trgm) + HTTP handler - product: full package — model, repository (CRUD + BatchCreate + ListForPrompt), handler - gemini: add AvailableProducts field to RecipeRequest, include in prompt - recommendation: add ProductLister interface, load user products for personalised prompts - server/main: wire ingredient and product handlers with new routes Flutter: - models: Product, IngredientMapping with json_serializable - ProductService: getProducts, createProduct, updateProduct, deleteProduct, searchIngredients - ProductsNotifier: create/update/delete with optimistic delete - ProductsScreen: expiring-soon section, normal section, swipe-to-delete, edit bottom sheet - AddProductScreen: name field with 300ms debounce autocomplete, qty/unit/days fields - app_router: /products/add route + Badge on Products nav tab showing expiring count - MainShell converted to ConsumerWidget for badge reactivity Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,11 +14,12 @@ type RecipeGenerator interface {
|
||||
|
||||
// RecipeRequest contains parameters for recipe generation.
|
||||
type RecipeRequest struct {
|
||||
UserGoal string // "weight_loss" | "maintain" | "gain"
|
||||
DailyCalories int
|
||||
Restrictions []string // e.g. ["gluten_free", "vegetarian"]
|
||||
CuisinePrefs []string // e.g. ["russian", "asian"]
|
||||
Count int
|
||||
UserGoal string // "weight_loss" | "maintain" | "gain"
|
||||
DailyCalories int
|
||||
Restrictions []string // e.g. ["gluten_free", "vegetarian"]
|
||||
CuisinePrefs []string // e.g. ["russian", "asian"]
|
||||
Count int
|
||||
AvailableProducts []string // human-readable list of products in user's pantry
|
||||
}
|
||||
|
||||
// Recipe is a recipe returned by Gemini.
|
||||
@@ -134,6 +135,13 @@ func buildRecipePrompt(req RecipeRequest) string {
|
||||
perMealCalories = 600
|
||||
}
|
||||
|
||||
productsSection := ""
|
||||
if len(req.AvailableProducts) > 0 {
|
||||
productsSection = "\nДоступные продукты (приоритет — скоро истекают ⚠):\n" +
|
||||
strings.Join(req.AvailableProducts, "\n") +
|
||||
"\nПредпочтительно использовать эти продукты в рецептах.\n"
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`Ты — диетолог-повар. Предложи %d рецептов на русском языке.
|
||||
|
||||
Профиль пользователя:
|
||||
@@ -141,7 +149,7 @@ func buildRecipePrompt(req RecipeRequest) string {
|
||||
- Дневная норма калорий: %d ккал
|
||||
- Ограничения: %s
|
||||
- Предпочтения: %s
|
||||
|
||||
%s
|
||||
Требования к каждому рецепту:
|
||||
- Калорийность на порцию: не более %d ккал
|
||||
- Время приготовления: до 60 минут
|
||||
@@ -165,7 +173,7 @@ func buildRecipePrompt(req RecipeRequest) string {
|
||||
"nutrition_per_serving": {
|
||||
"calories": 420, "protein_g": 48, "fat_g": 12, "carbs_g": 18
|
||||
}
|
||||
}]`, count, goal, req.DailyCalories, restrictions, cuisines, perMealCalories)
|
||||
}]`, count, goal, req.DailyCalories, restrictions, cuisines, productsSection, perMealCalories)
|
||||
}
|
||||
|
||||
func parseRecipesJSON(text string) ([]Recipe, error) {
|
||||
|
||||
Reference in New Issue
Block a user