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:
@@ -82,29 +82,32 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusBadRequest, "date and meal_type are required")
|
||||
return
|
||||
}
|
||||
if req.DishID == nil && req.Name == "" {
|
||||
writeError(w, http.StatusBadRequest, "dish_id or name is required")
|
||||
if req.DishID == nil && req.ProductID == nil && req.Name == "" {
|
||||
writeError(w, http.StatusBadRequest, "dish_id, product_id, or name is required")
|
||||
return
|
||||
}
|
||||
|
||||
if req.DishID == nil {
|
||||
dishID, _, resolveError := h.dishRepo.FindOrCreate(r.Context(), req.Name)
|
||||
if resolveError != nil {
|
||||
slog.Error("resolve dish for diary entry", "name", req.Name, "err", resolveError)
|
||||
writeError(w, http.StatusInternalServerError, "failed to resolve dish")
|
||||
return
|
||||
// Product-based entry: skip dish/recipe resolution entirely.
|
||||
if req.ProductID == nil {
|
||||
if req.DishID == nil {
|
||||
dishID, _, resolveError := h.dishRepo.FindOrCreate(r.Context(), req.Name)
|
||||
if resolveError != nil {
|
||||
slog.Error("resolve dish for diary entry", "name", req.Name, "err", resolveError)
|
||||
writeError(w, http.StatusInternalServerError, "failed to resolve dish")
|
||||
return
|
||||
}
|
||||
req.DishID = &dishID
|
||||
}
|
||||
req.DishID = &dishID
|
||||
}
|
||||
|
||||
if req.RecipeID == nil {
|
||||
recipeID, _, recipeError := h.recipeRepo.FindOrCreateRecipe(r.Context(), *req.DishID, 0, 0, 0, 0)
|
||||
if recipeError != nil {
|
||||
slog.Error("find or create recipe for diary entry", "dish_id", *req.DishID, "err", recipeError)
|
||||
writeError(w, http.StatusInternalServerError, "failed to resolve recipe")
|
||||
return
|
||||
if req.RecipeID == nil {
|
||||
recipeID, _, recipeError := h.recipeRepo.FindOrCreateRecipe(r.Context(), *req.DishID, 0, 0, 0, 0)
|
||||
if recipeError != nil {
|
||||
slog.Error("find or create recipe for diary entry", "dish_id", *req.DishID, "err", recipeError)
|
||||
writeError(w, http.StatusInternalServerError, "failed to resolve recipe")
|
||||
return
|
||||
}
|
||||
req.RecipeID = &recipeID
|
||||
}
|
||||
req.RecipeID = &recipeID
|
||||
}
|
||||
|
||||
entry, createError := h.repo.Create(r.Context(), userID, req)
|
||||
|
||||
Reference in New Issue
Block a user