feat: rename ingredients→products, products→user_products; add barcode/OFF import

- Rename catalog: ingredient/* → product/* (canonical_name, barcode, nutrition per 100g)
- Rename pantry: product/* → userproduct/* (user-owned items with expiry)
- Squash migrations into single 001_initial_schema.sql (clean-db baseline)
- product_categories: add English canonical name column; fix COALESCE in queries
- Remove product_translations: product names are stored in their original language
- Add default_unit_name to product API responses via unit_translations JOIN
- Add cmd/importoff: bulk import from OpenFoodFacts JSONL dump (COPY + ON CONFLICT)
- Diary: support product_id entries alongside dish_id (CHECK num_nonnulls = 1)
- Home: getLoggedCalories joins both recipes and catalog products
- Flutter: rename models/providers/services to match backend rename
- Flutter: add barcode scan flow for diary (mobile_scanner, product_portion_sheet)
- Flutter: localise 6 new keys across 12 languages (barcode scan, portion weight)
- Routes: GET /products/search, GET /products/barcode/{barcode}, /user-products

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-03-21 12:45:48 +02:00
parent 6861e5e754
commit 205edbdade
72 changed files with 2588 additions and 1444 deletions

View File

@@ -6,7 +6,6 @@ import (
"github.com/food-ai/backend/internal/domain/diary"
"github.com/food-ai/backend/internal/domain/dish"
"github.com/food-ai/backend/internal/domain/home"
"github.com/food-ai/backend/internal/domain/ingredient"
"github.com/food-ai/backend/internal/domain/menu"
"github.com/food-ai/backend/internal/domain/product"
"github.com/food-ai/backend/internal/domain/recipe"
@@ -14,6 +13,7 @@ import (
"github.com/food-ai/backend/internal/domain/recommendation"
"github.com/food-ai/backend/internal/domain/savedrecipe"
"github.com/food-ai/backend/internal/domain/user"
"github.com/food-ai/backend/internal/domain/userproduct"
"github.com/food-ai/backend/internal/infra/config"
"github.com/jackc/pgx/v5/pgxpool"
)
@@ -37,14 +37,15 @@ func initApp(appConfig *config.Config, pool *pgxpool.Pool) (*App, error) {
openaiClient := newOpenAIClient(mainGeminiAPIKey)
mainPexelsAPIKey := newPexelsAPIKey(appConfig)
pexelsClient := newPexelsClient(mainPexelsAPIKey)
productRepository := product.NewRepository(pool)
recommendationHandler := recommendation.NewHandler(openaiClient, pexelsClient, userRepository, productRepository)
userProductRepository := userproduct.NewRepository(pool)
recommendationHandler := recommendation.NewHandler(openaiClient, pexelsClient, userRepository, userProductRepository)
dishRepository := dish.NewRepository(pool)
savedrecipeRepository := savedrecipe.NewRepository(pool, dishRepository)
savedrecipeHandler := savedrecipe.NewHandler(savedrecipeRepository)
ingredientRepository := ingredient.NewRepository(pool)
ingredientHandler := ingredient.NewHandler(ingredientRepository)
productHandler := product.NewHandler(productRepository)
productRepository := product.NewRepository(pool)
openFoodFactsClient := product.NewOpenFoodFacts()
productHandler := product.NewHandler(productRepository, openFoodFactsClient)
userProductHandler := userproduct.NewHandler(userProductRepository)
// Kafka producer
kafkaProducer, kafkaProducerError := newKafkaProducer(appConfig)
@@ -55,10 +56,10 @@ func initApp(appConfig *config.Config, pool *pgxpool.Pool) (*App, error) {
// Recognition pipeline
jobRepository := recognition.NewJobRepository(pool)
sseBroker := recognition.NewSSEBroker(pool, jobRepository)
recognitionHandler := recognition.NewHandler(openaiClient, ingredientRepository, jobRepository, kafkaProducer, sseBroker)
recognitionHandler := recognition.NewHandler(openaiClient, productRepository, jobRepository, kafkaProducer, sseBroker)
menuRepository := menu.NewRepository(pool)
menuHandler := menu.NewHandler(menuRepository, openaiClient, pexelsClient, userRepository, productRepository, dishRepository)
menuHandler := menu.NewHandler(menuRepository, openaiClient, pexelsClient, userRepository, userProductRepository, dishRepository)
diaryRepository := diary.NewRepository(pool)
diaryHandler := diary.NewHandler(diaryRepository, dishRepository, dishRepository)
homeHandler := home.NewHandler(pool)
@@ -77,8 +78,8 @@ func initApp(appConfig *config.Config, pool *pgxpool.Pool) (*App, error) {
userHandler,
recommendationHandler,
savedrecipeHandler,
ingredientHandler,
productHandler,
userProductHandler,
recognitionHandler,
menuHandler,
diaryHandler,