5.1 KiB
Tasks: Garmin Login Improvements
Branch: 003-loginimprovements-use-the | Date: 2025-10-10 | Spec: /home/sstent/Projects/FitTrack_GarminSync/specs/003-loginimprovements-use-the/spec.md
Summary
This plan outlines the implementation of Garmin login improvements, enabling users to link their Garmin accounts via a /login endpoint. The system will store credentials, automatically refresh tokens, and operate statelessly for API callers, implicitly using stored Garmin credentials for sync operations.
Phase 1: Setup Tasks (Project Initialization)
- T001: Ensure Python 3.13 virtual environment is set up and activated.
- T002: Install core dependencies: FastAPI, garth, garminconnect, httpx, pydantic.
- T003: Verify
centralDBconnection and schema forGarminCredentialsentity.
Phase 2: Foundational Tasks (Blocking Prerequisites)
- T004: Implement
GarminCredentialsPydantic model inbackend/src/schemas.pybased ondata-model.md. - T005: Implement
GarminLoginRequestandGarminLoginResponsePydantic models inbackend/src/schemas.pybased ongarmin_auth_login.json. - T006: Implement
ActivitySyncRequestPydantic model inbackend/src/schemas.pybased onsync_garmin_activities.json. - T007: Update
CentralDBServiceinbackend/src/services/central_db_service.pyto include methods forcreate_garmin_credentials,get_garmin_credentials, andupdate_garmin_credentials. - T008: Implement
GarminAuthServiceinbackend/src/services/garmin_auth_service.pywithinitial_loginmethod to authenticate with Garmin and returnGarminCredentials.
Phase 3: User Story 1 - Initial Garmin Account Setup (P1)
Goal: User can link their Garmin account via /api/garmin/login.
Independent Test Criteria: Call /api/garmin/login with valid/invalid credentials and verify centralDB state and response.
- T009 [US1]: Implement
/api/garmin/loginendpoint inbackend/src/api/garmin_auth.pyto acceptGarminLoginRequest. - T010 [US1]: Integrate
GarminAuthService.initial_loginandCentralDBServicemethods into/api/garmin/loginendpoint. - T011 [US1]: Ensure
/api/garmin/loginreturnsGarminLoginResponseon success and appropriate error on failure. - T012 [US1]: Write unit tests for
/api/garmin/loginendpoint inbackend/tests/api/test_garmin_auth_api.pycovering success and failure scenarios.
Phase 4: User Story 3 - Stateless Garmin Sync Operations (P1)
Goal: Garmin Sync operations retrieve tokens from centralDB without client-side authentication.
Independent Test Criteria: Call /api/sync/garmin/activities after successful login and verify sync initiation.
- T013 [US3]: Modify
get_current_userdependency inbackend/src/dependencies.pyto retrieveuser_idimplicitly (e.g., from a fixed value for single-user system) and then fetchGarminCredentialsfromCentralDBService. - T014 [US3]: Implement
GarminActivityServiceinbackend/src/services/garmin_activity_service.pyto useGarminCredentialsfromCentralDBServicefor Garmin API calls. - T015 [US3]: Implement
/api/sync/garmin/activitiesendpoint inbackend/src/api/garmin_sync.pyto acceptActivitySyncRequest. - T016 [US3]: Integrate
GarminActivityServiceinto/api/sync/garmin/activitiesendpoint. - T017 [US3]: Write unit tests for
/api/sync/garmin/activitiesendpoint inbackend/tests/api/test_garmin_sync_api.pycovering successful sync initiation.
Phase 5: User Story 2 - Automatic Garmin Token Refresh (P1)
Goal: System automatically refreshes Garmin authentication tokens. Independent Test Criteria: Simulate expired token and verify refresh during a sync operation.
- T018 [US2]: Enhance
GarminAuthServiceto include a method for checking token expiration and refreshing tokens. - T019 [US2]: Integrate token refresh logic into
GarminActivityService(and other Garmin services) before making Garmin API calls. - T020 [US2]: Ensure
CentralDBServiceis updated with new tokens after refresh. - T021 [US2]: Write integration tests for automatic token refresh in
backend/tests/integration/test_garmin_token_refresh.py.
Final Phase: Polish & Cross-Cutting Concerns
- T022: Review and update
README.mdwith instructions for setting up and running the service. - T023: Ensure all new code adheres to project's code quality standards (Black, Flake8, Mypy, Isort).
- T024: Update
GEMINI.mdwith any new technologies or commands.
Dependencies
- Phase 1 -> Phase 2
- Phase 2 -> Phase 3
- Phase 3 -> Phase 4
- Phase 4 -> Phase 5
- Phase 5 -> Final Phase
Parallel Execution Examples
- Phase 2: T004, T005, T006 can be executed in parallel.
- Phase 3 (US1): T009, T010, T011 can be executed in parallel after T008.
- Phase 4 (US3): T014, T015, T016 can be executed in parallel after T013.
Implementation Strategy
We will follow an MVP-first approach, delivering User Story 1, then User Story 3, and finally User Story 2. This ensures core login and stateless sync functionality is established before implementing automatic token refresh.