Skip to content

Let foods be measured per unit as well as per 100 g / 100 ml - #12

Merged
YarinQuapi merged 1 commit into
masterfrom
worktree-per-unit-calories
Nov 16, 2026
Merged

YarinQuapi merged 1 commit into
masterfrom
worktree-per-unit-calories

Conversation

@YarinQuapi

Copy link
Copy Markdown
Owner

What

Adds a unit food basis (egg, slice) alongside solid and liquid, across API, web and mobile.

  • API: new unit value on FoodBasis with a migration extending the enum on Food and DiaryEntry. scaleNutrients takes the basis: unit foods scale by amount, solid and liquid by amount / 100. Entry creation passes the food's basis through.
  • Web and mobile: a third "Per unit (egg, slice…)" option in the food form, "/ 1 unit" labels, a default amount of 1 for unit foods, and a unit-aware live kcal preview. English and Hebrew copy included. Mobile gets Copy.unitOf / perOf helpers replacing the repeated grams/ml ternaries.

Why

Foods like an egg or a slice of bread are logged by count, not weight.

Notes for reviewers

  • Nutrients for unit foods are stored per 1 unit (not per 100), so existing rows are unaffected.
  • Open Food Facts scans still produce solid or liquid only.
  • Custom unit names (e.g. "slice") are out of scope; the label is a generic "unit".
  • The migration has not been applied to a database yet.

Testing

  • API tests (50), including a new unit-scaling test; Flutter tests (19), including a new label test.
  • API and web type checks pass.
  • Not tried in a running UI.

🤖 Generated with Claude Code

Adds a "unit" food basis (egg, slice) across API, web and mobile.
Nutrients for unit foods are stored per 1 unit and scale by amount
instead of amount / 100. Includes the enum migration, per-unit labels,
a default amount of 1, and English and Hebrew copy.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@YarinQuapi
YarinQuapi merged commit 3c3a861 into master Nov 16, 2026
3 checks passed
@YarinQuapi
YarinQuapi deleted the worktree-per-unit-calories branch November 16, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant