3 KiB
3 KiB
API v2 Migration Guide
Status: In Progress
The web app is being migrated to use API v2 exclusively. API v2 provides:
- Standard OAuth2/JWT Bearer token authentication
- RESTful endpoint patterns
- Better error handling with standard HTTP status codes
- Token refresh mechanism
Backend Implementation Status
✅ Completed
- Created
AuthApiV2with OAuth2 endpoints - Created
JwtServicefor token generation/verification - Created
authorizeV2middleware for Bearer token auth - Created
PacksApiV2basic structure - Mounted v2 APIs at
/api/v2path - Separated v1 and v2 authorization middleware
⚠️ Needs Completion
- Fix JwtService HMAC-SHA256 implementation (use proper crypto library)
- Complete PacksApiV2 endpoints implementation
- Implement TestsApiV2
- Implement GamesApiV2
- Implement PurchasesApiV2
- Implement SubscriptionsApiV2
- Implement PromocodesApiV2
- Add comprehensive error responses
- Add API documentation (OpenAPI/Swagger)
Web App Implementation Status
✅ Completed
- Created
ApiConfigV2with all v2 endpoints - Created
HttpRepositoryV2with Bearer token auth - Updated
StorageModuleto use HttpRepositoryV2 - Updated
AuthServiceto use HttpRepositoryV2 - Updated dependency injection to use v2
⚠️ Needs Completion
- Update
GamesManagerto use HttpRepositoryV2 - Update
TestManagerto use HttpRepositoryV2 - Update
StatisticsServiceto use HttpRepositoryV2 - Update
SubscriptionServiceto use HttpRepositoryV2 - Update
PromocodeServiceto use HttpRepositoryV2 - Update
PackProgressServiceto use HttpRepositoryV2 - Write unit tests for HttpRepositoryV2
- Update integration tests
Backend Endpoints
Authentication (/api/v2/auth)
POST /api/v2/auth/oauth/google- Google OAuthPOST /api/v2/auth/refresh- Refresh access tokenGET /api/v2/auth/me- Get current userPOST /api/v2/auth/logout- Logout
Packs (/api/v2/packs)
GET /api/v2/packs- List packs (with pagination)GET /api/v2/packs/{packId}- Get pack detailsGET /api/v2/packs/{packId}/cards- Get pack cardsGET /api/v2/packs/{packId}/cards/{cardId}/image- Get card imageGET /api/v2/packs/{packId}/tests- Get pack tests
Tests (/api/v2/tests)
GET /api/v2/tests/{testId}- Get testPOST /api/v2/tests/{testId}/results- Submit resultsGET /api/v2/tests/{testId}/history- Get attempt history
Migration Steps
- Backend: Complete JWT implementation and all v2 endpoints
- Web App: Update all services to use HttpRepositoryV2
- Testing: Write comprehensive tests for v2 endpoints
- Deployment: Deploy backend v2 endpoints
- Verification: Test end-to-end with web app
- Deprecation: Mark v1 APIs as deprecated (keep for mobile app)
Next Steps
- Fix JWT service to use proper crypto library
- Complete backend v2 endpoint implementations
- Update web app services to use HttpRepositoryV2 methods
- Write tests
- Deploy and verify