Repository navigation
Add update_food_entry tool to edit or move a logged entry - #76
paultristanwagner wants to merge 1 commit into
Conversation
The app changes a serving's amount with /api/v2/edit_serving, re-sending the whole serving. The meal group lives in the high bits of `order`, and edit_serving accepts a new order too, so one call changes the amount, the measure and the meal. Claude-Session: https://claude.ai/code/session_01MCJFDo71qoSqTRtcGfkpXJ
|
|
||
| serving = dict(serving) | ||
| if grams is not None: | ||
| serving["grams"] = grams |
There was a problem hiding this comment.
Cronometer's API uses grams misleadingly - for regular foods and weight-based recipes, it holds actual grams.
For serving-based recipes, it holds a reference-serving count instead. Editing such an entry to grams=100 therefore sends 100 reference servings.
Take a look at enrich_diary_servings which already handles this. It may be useful to extract that shared measure logic to a small helper.
|
This conflicts with current main, because #88 and #92 replaced the hard-coded group map with account-specific groups. Locally, I resolved it this way:
The full suite passes, with |
|
A clean patch / conflict resolution would be much appreciated |
|
Opened #96 with the conflict resolved against current |
* Add update_food_entry tool to edit or move a logged entry The app changes a serving's amount with /api/v2/edit_serving, re-sending the whole serving. The meal group lives in the high bits of `order`, and edit_serving accepts a new order too, so one call changes the amount, the measure and the meal. Claude-Session: https://claude.ai/code/session_01MCJFDo71qoSqTRtcGfkpXJ * fix: accept any account diary group in update_serving update_serving limited diary_group to 1-4, the old default layout. Groups now come from resolve_diary_group, so any enabled group is valid (for example a custom group 5). Add server-level tests for moving to a named custom group and for rejecting "auto". * Fix recipe amount validation and concurrent diary edits Reject gram-weight edits for serving-based recipes, whose API amounts are reference-serving counts. Keep measure and group edits available and document the restriction. Lock each serving's full fetch-modify-save cycle so concurrent partial edits preserve each other's changes. Cover both fixes with regression tests. --------- Co-authored-by: Paul Tristan Wagner <paultristanwagner@gmail.com> Co-authored-by: Randy Westergren <rawestergren@gmail.com>
|
Addressed by #96 |
Part of #73.
Adds an
update_food_entrytool: change a logged entry's amount ormeasure, or move it to another meal. Until now the only way was to remove
the entry and log it again.
The app changes an amount with
POST /api/v2/edit_serving, sending the whole serving back with thenew
grams:{"serving": {"servingId": …, "day": …, "order": 65537, "foodId": …, "measureId": …, "grams": 400.0, …}, "auth": {…}, "config": {"call_version": 2}}The meal group lives in the high bits of
order, asadd_servingalreadybuilds it (
(group << 16) | position). The app moves an entry with aseparate
POST /api/v2/update_order{"diaryEntries": [<serving with new order>]}, butedit_servingaccepts a newordertoo, so one call doesboth. Verified against the live API on 1900-01-02: amount, meal and both at
once.
Changes:
update_serving(serving_id, day, *, grams, measure_id, diary_group)reads the serving fromget_diary, changes the givenfields and sends it back. A moved entry goes to the end of its new meal;
staying in the same meal keeps its position. Arguments are validated
before any request.
update_food_entrytool. The meal-name map thatadd_food_entrybuilt inline is now a module constant both tools use.https://claude.ai/code/session_01MCJFDo71qoSqTRtcGfkpXJ