fix: partial settings update no longer zeroes omitted fields#37
Open
Cawlumm wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PUT /api/v1/settingswrote every column from the request struct. A partial payload like{"calorie_target": 1800}therefore resetweight_unitto""and zeroed protein/carb/fat targets. The handler also never calledvalidate.Struct(soweight_unit: "stone"was accepted) and ignored theExecerror.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
UpdateSettingsRequestfields are now pointers, distinguishing absent from zero.user_settingsto 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.PUT {"calorie_target":1801}→ response keepsweight_unit, protein/carb/fat intact (zeroed before this fix).🤖 Generated with Claude Code