feat(types): add create/delete for nutrition-log and hydration-log - #14
Open
saiteja007-mv wants to merge 1 commit into
Open
saiteja007-mv wants to merge 1 commit into
saiteja007-mv wants to merge 1 commit into
Conversation
Fixes Google-Health-API#6. Both types accept dataPoints create and dataPoints:batchDelete, but the registry marked them read-only, so `ghealth data nutrition-log create` did not exist. Verified against the live v4 API (own account, entries deleted and 404-confirmed afterwards): nutrition-log create 200 delete 200 PATCH 500 INTERNAL hydration-log create 200 delete 200 PATCH 500 INTERNAL "update" is deliberately omitted for both. PATCH returns 500 INTERNAL with a field mask and without one, and the stored value is unchanged afterwards, so exposing an update subcommand here would only ever fail. Editing means delete + create. A test pins that, so a later blanket "make writable types consistent" change does not add it back. The food catalog stays read-only: a custom food is an anonymous nutrition-log entry with inline nutrients, not a new catalog entry. That is pinned too, since "nutrition types are now writable" invites the opposite assumption. Create payloads nest under the type's own DataPoint key, e.g. ghealth data nutrition-log create --json '{"nutritionLog":{ "interval":{"startTime":"2026-09-03T19:00:00Z","startUtcOffset":"-18000s", "endTime":"2026-09-03T19:01:00Z","endUtcOffset":"-18000s"}, "foodDisplayName":"Oats","mealType":"BREAKFAST","serving":{"amount":1}, "energy":{"kcal":300},"totalCarbohydrate":{"grams":50},"totalFat":{"grams":5}}}' Two API behaviours worth knowing when writing these, both confirmed the same way: the interval must be non-empty (startTime == endTime is rejected 400 INVALID_TIME_RANGE), and omitting startUtcOffset/endUtcOffset is accepted but files the entry at UTC wall-clock time rather than the user's, so a 12:55 -05:00 entry lands at 12:55Z. go test ./... and go vet ./... pass.
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.
Fixes #6.
nutrition-logandhydration-logacceptdataPointscreate anddataPoints:batchDelete, but the registry marked them read-only, soghealth data nutrition-log createdid not exist.Verified against the live v4 API
Run on my own account; every data point created during testing was deleted and confirmed gone with a 404 read-back.
nutrition-loghydration-logweight(control, already writable)End-to-end with the built binary after the change:
Why
updateis deliberately omittedPATCH on either type returns
500 INTERNAL— with a field mask and without one — and the stored value is unchanged afterwards. Exposing anupdatesubcommand here would ship a command that can only fail, so both types are create/delete-only. Editing means delete + create. There is a test pinning this, so a later "make the writable types consistent" pass doesn't quietly add it back.The food catalog stays read-only, also pinned by a test: a custom food is an anonymous
nutrition-logentry with inline nutrients, not a new catalog entry. Marking the nutrition types writable invites the opposite assumption.Two API behaviours worth knowing when writing these
Both confirmed the same way, and they cost me real debugging time:
startTime == endTimeis rejected with400 INVALID_TIME_RANGE. A one-shot "log this now" needs a synthesised end (e.g. +60s).startUtcOffset/endUtcOffsetis accepted, and silently wrong. They are documented as required, but a write without them succeeds and files the entry at UTC wall-clock time rather than the user's — a 12:55 −05:00 entry lands at 12:55Z, five hours out. Sincecreatepasses--jsonthrough untouched, anyone modelling a payload by hand will hit this. Happy to send a follow-up PR adding a pre-flight warning for it if that's wanted.Example payload for the docs, if useful:
go test ./...andgo vet ./...pass. CLA signed.