Skip to content

fix: partial settings update no longer zeroes omitted fields#37

Open
Cawlumm wants to merge 1 commit into
mainfrom
fix/settings-partial-update
Open

fix: partial settings update no longer zeroes omitted fields#37
Cawlumm wants to merge 1 commit into
mainfrom
fix/settings-partial-update

Conversation

@Cawlumm

@Cawlumm Cawlumm commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

PUT /api/v1/settings wrote every column from the request struct. A partial payload like {"calorie_target": 1800} therefore reset weight_unit to "" and zeroed protein/carb/fat targets. The handler also never called validate.Struct (so weight_unit: "stone" was accepted) and ignored the Exec error.

The frontend Settings page happens to send the full object today, so this is latent there — but the store's update(patch) API and any direct API consumer hit it.

Fix

  • UpdateSettingsRequest fields are now pointers, distinguishing absent from zero.
  • Handler merges the payload over the stored row (or defaults), validates, and surfaces write failures.
  • Added user_settings to the test schema + unit tests: partial update preserves other fields, invalid unit → 422, first-write fills defaults.

Verification

  • go test ./controllers/ green; Playwright e2e: 161 passed, 2 skipped.
  • Live check: PUT {"calorie_target":1801} → response keeps weight_unit, protein/carb/fat intact (zeroed before this fix).

🤖 Generated with Claude Code

PUT /settings wrote every column from the request struct, so a payload like
{"calorie_target": 1800} reset weight_unit to "" and zeroed the macro
targets. The handler also skipped validation entirely and ignored the Exec
error.

Use pointer fields to distinguish absent from zero, merge over the stored
row (or defaults), validate the payload, and surface write failures.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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