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:
@@ -76,12 +76,21 @@ func (h *Handler) getDailyGoal(ctx context.Context, userID string) int {
|
||||
}
|
||||
|
||||
// getLoggedCalories returns total calories logged in meal_diary for today.
|
||||
// Supports both recipe-based entries (via recipes JOIN) and catalog product entries (via products JOIN).
|
||||
func (h *Handler) getLoggedCalories(ctx context.Context, userID, date string) float64 {
|
||||
var total float64
|
||||
_ = h.pool.QueryRow(ctx,
|
||||
`SELECT COALESCE(SUM(calories * portions), 0)
|
||||
FROM meal_diary
|
||||
WHERE user_id = $1 AND date::text = $2`,
|
||||
`SELECT COALESCE(SUM(
|
||||
COALESCE(
|
||||
r.calories_per_serving * md.portions,
|
||||
p.calories_per_100g * md.portion_g / 100,
|
||||
0
|
||||
)
|
||||
), 0)
|
||||
FROM meal_diary md
|
||||
LEFT JOIN recipes r ON r.id = md.recipe_id
|
||||
LEFT JOIN products p ON p.id = md.product_id
|
||||
WHERE md.user_id = $1 AND md.date::text = $2`,
|
||||
userID, date,
|
||||
).Scan(&total)
|
||||
return total
|
||||
@@ -153,7 +162,7 @@ func (h *Handler) getExpiringSoon(ctx context.Context, userID string) []Expiring
|
||||
WITH p AS (
|
||||
SELECT name, quantity, unit,
|
||||
(added_at + storage_days * INTERVAL '1 day') AS expires_at
|
||||
FROM products
|
||||
FROM user_products
|
||||
WHERE user_id = $1
|
||||
)
|
||||
SELECT name, quantity, unit,
|
||||
|
||||
Reference in New Issue
Block a user