From 189307b548da64319f78a95943c572c404730d83 Mon Sep 17 00:00:00 2001 From: fy59 Date: Fri, 18 Sep 2026 05:32:39 +0200 Subject: [PATCH] Accept integral preparation weight targets --- tui/src/web_sessions.c | 14 ++++++++++---- tui/tests/test_web_sessions.c | 7 +++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tui/src/web_sessions.c b/tui/src/web_sessions.c index 83c360b..f13ea07 100644 --- a/tui/src/web_sessions.c +++ b/tui/src/web_sessions.c @@ -792,10 +792,16 @@ static TrainlogStatus insert_preparation_entry(TrainlogDatabase *database, value = yyjson_obj_get(entry, "target_weight_kg"); if (value == NULL || yyjson_is_null(value)) { (void)sqlite3_bind_null(statement, 11); - } else if (!yyjson_is_num(value) || !isfinite(yyjson_get_real(value)) || - yyjson_get_real(value) <= 0.0 || yyjson_get_real(value) > 2000.0 || - sqlite3_bind_double(statement, 11, yyjson_get_real(value)) != SQLITE_OK) { - goto invalid; + } else { + double target_weight; + if (!yyjson_is_num(value)) { + goto invalid; + } + target_weight = yyjson_get_num(value); + if (!isfinite(target_weight) || target_weight <= 0.0 || target_weight > 2000.0 || + sqlite3_bind_double(statement, 11, target_weight) != SQLITE_OK) { + goto invalid; + } } if (!bind_nullable_text(statement, 12, yyjson_obj_get(entry, "notes"))) { goto invalid; diff --git a/tui/tests/test_web_sessions.c b/tui/tests/test_web_sessions.c index a28c032..46dca42 100644 --- a/tui/tests/test_web_sessions.c +++ b/tui/tests/test_web_sessions.c @@ -46,8 +46,11 @@ static bool creation_replay_revision_and_pagination(void) { "\"occurrences\":[]}"; static const char DERIVED_BODY[] = "{\"title\":\"Derived\",\"session_type\":\"training\"," - "\"planned_for\":null,\"notes\":null,\"editing_state\":\"draft\"," - "\"occurrences\":[],\"source_proposal_id\":" + "\"planned_for\":\"2026-09-17\",\"notes\":null,\"editing_state\":\"ready\"," + "\"occurrences\":[{\"exercise_id\":\"ex_aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa\"," + "\"equipment_id\":null,\"load_mode\":\"external\",\"rest_seconds\":90," + "\"target_sets\":4,\"target_reps\":10,\"target_duration_seconds\":null," + "\"target_weight_kg\":39,\"notes\":null}],\"source_proposal_id\":" "\"aid_11111111-1111-4111-8111-111111111111\"," "\"source_payload_sha256\":" "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}";