feat: add profile REST endpoints with HR zone validation

Implements GET /api/profile and PUT /api/profile endpoints with validation
of HR zones (must be contiguous, non-overlapping, 0-100%). Also updates
profile migration to use correct HR zone defaults (0-20, 20-40, etc.)
that match validation requirements.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 19:03:29 +02:00
parent 6f62686d29
commit 57be9065cd
5 changed files with 137 additions and 11 deletions

View File

@@ -7,15 +7,15 @@ CREATE TABLE profile (
rolling_window_days INTEGER NOT NULL DEFAULT 90,
max_heart_rate REAL,
resting_heart_rate REAL,
hr_zone1_min_pct REAL NOT NULL DEFAULT 50,
hr_zone1_max_pct REAL NOT NULL DEFAULT 60,
hr_zone2_min_pct REAL NOT NULL DEFAULT 60,
hr_zone2_max_pct REAL NOT NULL DEFAULT 70,
hr_zone3_min_pct REAL NOT NULL DEFAULT 70,
hr_zone3_max_pct REAL NOT NULL DEFAULT 80,
hr_zone4_min_pct REAL NOT NULL DEFAULT 80,
hr_zone4_max_pct REAL NOT NULL DEFAULT 90,
hr_zone5_min_pct REAL NOT NULL DEFAULT 90,
hr_zone1_min_pct REAL NOT NULL DEFAULT 0,
hr_zone1_max_pct REAL NOT NULL DEFAULT 20,
hr_zone2_min_pct REAL NOT NULL DEFAULT 20,
hr_zone2_max_pct REAL NOT NULL DEFAULT 40,
hr_zone3_min_pct REAL NOT NULL DEFAULT 40,
hr_zone3_max_pct REAL NOT NULL DEFAULT 60,
hr_zone4_min_pct REAL NOT NULL DEFAULT 60,
hr_zone4_max_pct REAL NOT NULL DEFAULT 80,
hr_zone5_min_pct REAL NOT NULL DEFAULT 80,
hr_zone5_max_pct REAL NOT NULL DEFAULT 100,
easy_warmup_minutes REAL NOT NULL DEFAULT 10,
easy_cooldown_minutes REAL NOT NULL DEFAULT 5,

View File

@@ -16,8 +16,8 @@ func TestProfile_DefaultsThenUpdate(t *testing.T) {
if p.RollingWindowDays != 90 {
t.Errorf("RollingWindowDays = %d, want 90 (migration default)", p.RollingWindowDays)
}
if p.HRZone1MinPct != 50 || p.HRZone5MaxPct != 100 {
t.Errorf("zone defaults = %+v, want Z1 min=50, Z5 max=100", p)
if p.HRZone1MinPct != 0 || p.HRZone5MaxPct != 100 {
t.Errorf("zone defaults = %+v, want Z1 min=0, Z5 max=100", p)
}
maxHR, restingHR := 190.0, 50.0