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:
@@ -1,41 +1,29 @@
|
||||
package product
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Product is a user's food item in their pantry.
|
||||
// Product is a catalog entry representing a food ingredient or packaged product.
|
||||
// CanonicalName holds the English name; localized names are resolved at query time.
|
||||
type Product struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
PrimaryIngredientID *string `json:"primary_ingredient_id"`
|
||||
Name string `json:"name"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Unit string `json:"unit"`
|
||||
Category *string `json:"category"`
|
||||
StorageDays int `json:"storage_days"`
|
||||
AddedAt time.Time `json:"added_at"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
DaysLeft int `json:"days_left"`
|
||||
ExpiringSoon bool `json:"expiring_soon"`
|
||||
}
|
||||
ID string `json:"id"`
|
||||
CanonicalName string `json:"canonical_name"`
|
||||
Aliases json.RawMessage `json:"aliases"` // []string, populated by read queries
|
||||
Category *string `json:"category"`
|
||||
CategoryName *string `json:"category_name"` // localized category display name
|
||||
DefaultUnit *string `json:"default_unit"`
|
||||
DefaultUnitName *string `json:"default_unit_name,omitempty"`
|
||||
Barcode *string `json:"barcode,omitempty"`
|
||||
|
||||
// CreateRequest is the body for POST /products.
|
||||
type CreateRequest struct {
|
||||
PrimaryIngredientID *string `json:"primary_ingredient_id"`
|
||||
// Accept both "primary_ingredient_id" (new) and "mapping_id" (legacy client) fields.
|
||||
MappingID *string `json:"mapping_id"`
|
||||
Name string `json:"name"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Unit string `json:"unit"`
|
||||
Category *string `json:"category"`
|
||||
StorageDays int `json:"storage_days"`
|
||||
}
|
||||
CaloriesPer100g *float64 `json:"calories_per_100g"`
|
||||
ProteinPer100g *float64 `json:"protein_per_100g"`
|
||||
FatPer100g *float64 `json:"fat_per_100g"`
|
||||
CarbsPer100g *float64 `json:"carbs_per_100g"`
|
||||
FiberPer100g *float64 `json:"fiber_per_100g"`
|
||||
|
||||
// UpdateRequest is the body for PUT /products/{id}.
|
||||
// All fields are optional (nil = keep existing value).
|
||||
type UpdateRequest struct {
|
||||
Name *string `json:"name"`
|
||||
Quantity *float64 `json:"quantity"`
|
||||
Unit *string `json:"unit"`
|
||||
Category *string `json:"category"`
|
||||
StorageDays *int `json:"storage_days"`
|
||||
StorageDays *int `json:"storage_days"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user