feat: extend equipment and workout models with service tracking

This commit is contained in:
Blake Ridgway
2026-02-12 10:09:50 -06:00
parent eb9ac1b67a
commit 178ffb3425
37 changed files with 4005 additions and 40 deletions

115
TODO.md
View File

@@ -14,15 +14,15 @@
- [ ] **Adaptive Scheduling**: Auto-reschedule based on missed sessions, fatigue, weather
- [ ] **Workout Scheduling**: Calendar view, drag-drop, ICS sync (Google/Apple/Outlook)
- [ ] **Goal Setting & Tracking**: SMART goals with real-time progress bars
- [ ] **Templates Library**: Plan & session templates (endurance, threshold, VO2, strength)
- [ ] **Export Structured Workouts**: .zwo (Zwift), Garmin FIT/Workout, Wahoo, TrainerRoad
- [x] **Templates Library**: Plan & session templates (endurance, threshold, VO2, strength)
- [x] **Export Structured Workouts**: .zwo (Zwift), Garmin FIT/Workout, Wahoo, TrainerRoad
- [ ] **Race/Event Planner**: Target events, taper builder, gear checklist
## Workout Tracking
- [ ] **Workout Logging**: Exercises, sets/reps/weight; power, HR, cadence, GPS
- [ ] **Device Capture**: Live recording (Bluetooth/ANT+ when supported), file upload (FIT/TCX/GPX)
- [x] **Device Capture**: File upload (FIT/TCX/GPX activity import with metric extraction)
- [ ] **Tags & Notes**: RPE, mood, conditions, injuries, equipment used
- [ ] **Equipment Tracking**: Bike/components mileage, service reminders
- [x] **Equipment Tracking**: Bike/components mileage auto-tracking, service reminders
## Advanced Analytics
- [ ] **Interactive Dashboards**: Charts for load (CTL/ATL/TSB), power curves, trends
@@ -55,10 +55,10 @@
- [ ] **Rewards & Incentives**: Points store, partner discounts, raffles
## Integrations & Data
- [ ] **Wearable Sync**: Garmin, Wahoo, COROS, Apple Health, Google Fit
- [~] **Wearable Sync**: Garmin, Wahoo, COROS, Apple Health, Google Fit (Garmin + Wahoo OAuth & push implemented)
- [ ] **Platform Sync**: Strava, TrainingPeaks, Intervals.icu (calendar + workout push)
- [ ] **Music Integration**: Spotify/Apple Music workout-matched playlists
- [ ] **Data Import/Export**: Bulk FIT/TCX/GPX import; CSV/JSON export; takeout ZIP
- [~] **Data Import/Export**: FIT/TCX/GPX activity import implemented; CSV/JSON export & bulk import pending
- [ ] **Public API & Webhooks**: For partners, coaches, clubs
## Notifications & Comms
@@ -130,18 +130,97 @@
---
## Next Phase: Phase 2 - User Profiles & Stats Endpoints
## Completed - Phase 2: User Profiles, Equipment & Workouts ✅
### Planned Features
- [ ] GET/PUT `/api/protected/profile` - Full profile management
- [ ] POST/GET `/api/equipment` - Bike/gear management
- [ ] POST/GET `/api/stats` - Ride statistics
- [ ] GET `/api/zones` - Calculate training zones (auto from FTP/HR)
- [ ] Equipment tracking (brand, model, weight, mileage)
- [ ] Stats aggregation and trending
### Profile & Equipment (completed earlier)
- [x] GET/PUT `/api/protected/profile` - Full profile management
- [x] POST/GET/PUT/DELETE `/api/protected/equipment` - Bike/gear CRUD
- [x] GET `/api/protected/zones` - Calculate HR & power training zones
- [x] Equipment tracking (brand, model, weight)
- [x] Equipment usage stats from workouts
### After Phase 2: Phase 3 - OAuth Integration
- [ ] Google OAuth 2.0
- [ ] Strava API integration
### Workouts (completed earlier)
- [x] POST/GET/PUT/DELETE `/api/protected/workouts` - Full workout CRUD
- [x] GET `/api/protected/workouts/month` - Calendar month filtering
- [x] GET `/api/protected/workout-types` - Predefined workout types
- [x] POST `/api/protected/workouts/upload` - ZWO file import & parsing
- [x] Structured workout segments (JSONB) with power/cadence targets
### Stats
- [x] GET `/api/protected/stats/summary` - Overall ride statistics
- [x] GET `/api/protected/stats/weekly` - Weekly aggregated stats
- [x] GET `/api/protected/stats/monthly` - Monthly aggregated stats
- [x] GET `/api/protected/stats/personal-bests` - Personal records
### Workout Templates
- [x] GET `/api/protected/workout-templates` - List predefined templates (with category filter)
- [x] GET `/api/protected/workout-templates/detail` - Get template with full segment data
- [x] POST `/api/protected/workouts/from-template` - Create workout from template
- [x] 11 built-in templates: Recovery, Endurance, Tempo, Sweet Spot, Threshold, Over-Unders, VO2max, Sprint, Ramp Test
---
## Completed - Phase 2.5: Workout Export & Device Integration ✅
### Workout Export
- [x] GET `/api/protected/workouts/export/fit` - FIT workout file export (Garmin-compatible)
- [x] GET `/api/protected/workouts/export/zwo` - ZWO file export (Zwift-compatible)
- [x] Segment-to-FIT mapping (warmup/steady/interval/cooldown/ramp/freeride)
- [x] Power targets converted from %FTP to absolute watts for device display
- [x] `github.com/muktihari/fit` library integration for FIT encoding
### OAuth Infrastructure
- [x] OAuthConnection model with AES-256-GCM token encryption
- [x] OAuthState model for CSRF protection during OAuth flows
- [x] Shared OAuth service (state management, PKCE, token exchange, auto-refresh)
- [x] OAuth config loader from environment variables
### Garmin Connect Integration
- [x] GET `/api/protected/garmin/auth` - OAuth2 PKCE flow initiation
- [x] GET `/api/garmin/callback` - OAuth callback handler
- [x] POST `/api/protected/workouts/push/garmin` - Push workout to Garmin Connect
- [x] GET `/api/protected/garmin/status` - Connection status check
- [x] DELETE `/api/protected/garmin/disconnect` - Revoke connection
### Wahoo Cloud API Integration
- [x] GET `/api/protected/wahoo/auth` - OAuth2 flow initiation
- [x] GET `/api/wahoo/callback` - OAuth callback handler
- [x] POST `/api/protected/workouts/push/wahoo` - Push workout as Wahoo plan
- [x] GET `/api/protected/wahoo/status` - Connection status check
- [x] DELETE `/api/protected/wahoo/disconnect` - Revoke connection
---
## Completed - Phase 2.6: Activity Import & Equipment Mileage ✅
### Activity File Import (FIT/TCX/GPX)
- [x] POST `/api/protected/workouts/import` - Import activity files (multipart upload)
- [x] FIT activity parser using `muktihari/fit` decoder (session-level metrics)
- [x] TCX activity parser (lap aggregation, trackpoint elevation gain)
- [x] GPX activity parser (Haversine distance, elevation gain, extension parsing)
- [x] Extracts: duration, distance, avg/max power, avg/max HR, elevation gain, calories, cadence
- [x] Can create new completed workout or update existing planned workout with actual data
- [x] Supports optional equipment_id assignment on import
### Equipment Mileage & Service Tracking
- [x] Auto-increment equipment mileage when activities are imported with equipment assigned
- [x] Total distance (km), total duration (seconds), total rides tracked per equipment
- [x] Service interval configuration (distance-based and/or duration-based)
- [x] Distance and duration since last service counters
- [x] POST `/api/protected/equipment/service` - Record service (resets counters)
- [x] GET `/api/protected/equipment/service-status` - Check if equipment needs servicing
- [x] Service status in GET `/api/protected/equipment` response (total_distance, total_rides, etc.)
---
## Next Phase: Phase 3 - OAuth Login & Platform Sync
### OAuth Login
- [ ] Google OAuth 2.0 (sign in with Google)
- [ ] Apple Sign-In
- [ ] Garmin Connect
- [ ] Strava OAuth (sign in + activity sync)
### Platform Sync
- [ ] Strava activity sync (import completed rides)
- [ ] TrainingPeaks calendar sync
- [ ] Intervals.icu integration