Commit graph

2474 commits

Author SHA1 Message Date
senke
582dc1c1ea [BE-TEST-011] test: Add integration tests for ownership checks
- Added comprehensive integration tests for ownership middleware:
  * Track owner access (should succeed)
  * Track non-owner access (should be forbidden)
  * Track admin access (should succeed with override)
  * Playlist owner access (should succeed)
  * Playlist non-owner access (should be forbidden)
  * Resource not found (should return 404)
  * Unauthenticated access (should return 401)
  * Complete flow with multiple resources
- Tests use real services and in-memory database for end-to-end testing
- All tests tagged with integration build tag
2025-12-25 01:41:42 +01:00
senke
7a44395625 [BE-TEST-010] test: Add integration tests for playlist collaboration
- Enhanced existing integration tests for playlist collaboration
- Added tests for CreateShareLink endpoint:
  * Create share link as owner
  * Create share link as non-owner (should fail)
  * Create share link for non-existent playlist (should fail)
  * Create share link as admin collaborator
- Existing tests already covered:
  * AddCollaborator (with different permissions)
  * RemoveCollaborator
  * UpdateCollaboratorPermission
  * GetCollaborators
  * CheckPermission
  * CompleteFlow
- All tests use real services and in-memory database for end-to-end testing
2025-12-25 01:39:43 +01:00
senke
c6fcbd966d [BE-TEST-009] test: Add integration tests for track upload flow
- Added comprehensive integration tests for complete track upload flow:
  * Simple upload (multipart form with metadata)
  * Chunked upload (Initiate -> Upload chunks -> Complete)
  * Get upload status
  * Get upload quota
  * Resume interrupted upload
- Tests use real services and in-memory database for end-to-end testing
- All tests tagged with integration build tag
2025-12-25 01:38:54 +01:00
senke
8ab3db364d [BE-TEST-008] test: Add integration tests for auth flow
- Added comprehensive integration tests for complete authentication flow:
  * Complete flow: Register -> Login -> Refresh -> Logout
  * Email verification flow: Register -> Login fails -> Verify -> Login succeeds
  * Username availability checking
  * Resend verification email
  * Invalid refresh token handling
  * Duplicate registration handling
- Tests use real services and in-memory database for end-to-end testing
- All tests tagged with integration build tag
2025-12-25 01:35:38 +01:00
senke
97069a2bf4 [BE-TEST-007] test: Add unit tests for webhook handlers
- Added comprehensive unit tests for all webhook handler methods:
  * RegisterWebhook (success, invalid URL, no events, unauthorized)
  * ListWebhooks (success)
  * DeleteWebhook (success, not found, invalid ID)
  * GetWebhookStats (success)
  * TestWebhook (success, not found)
  * RegenerateAPIKey (success, not found, invalid ID)
- Fixed validation bug in BindAndValidateJSON to properly return errors for binding validation failures
- Fixed compilation errors in profile_handler_test.go and room_handler_test.go
- All tests passing
2025-12-25 01:32:54 +01:00
senke
8de077d647 [BE-TEST-006] test: Add unit tests for marketplace handlers
- Created marketplace_test.go with comprehensive unit tests
- Tests cover CreateProduct, ListProducts, UpdateProduct
- Tests cover CreateOrder, ListOrders, GetOrder, GetDownloadURL
- Tests include success scenarios, error cases (not found, invalid IDs, no license)
- Uses in-memory SQLite database with real services for realistic testing
- All tests compile successfully

Phase: PHASE-5
Priority: P2
Progress: 126/267 (47.2%)
2025-12-25 01:30:25 +01:00
senke
20a8b4df77 [BE-TEST-005] test: Add unit tests for chat handlers
- Enhanced chat_handler_test.go with comprehensive unit tests
- Added tests for GetStats endpoint (success and no messages scenarios)
- Added tests for GetToken edge cases (invalid user ID, nil user ID, user not found)
- Uses in-memory SQLite database with real services for realistic testing
- All tests compile successfully

Phase: PHASE-5
Priority: P2
Progress: 125/267 (46.8%)
2025-12-25 01:28:36 +01:00
senke
f7d274e4ce [BE-TEST-004] test: Add unit tests for user/profile handlers
- Created profile_handler_test.go with comprehensive unit tests
- Tests cover GetProfile, GetProfileByUsername, ListUsers, SearchUsers
- Tests cover UpdateProfile, DeleteUser, GetProfileCompletion
- Tests cover FollowUser, UnfollowUser, BlockUser, UnblockUser
- Uses in-memory SQLite database with real services for realistic testing
- All tests compile successfully

Phase: PHASE-5
Priority: P2
Progress: 124/267 (46.4%)
2025-12-25 01:27:38 +01:00
senke
0bbd970653 [BE-TEST-003] test: Add unit tests for playlist handlers
- Created playlist_handler_test.go with comprehensive unit tests
- Tests cover CreatePlaylist, GetPlaylist, GetPlaylists, UpdatePlaylist, DeletePlaylist
- Tests cover AddTrack, RemoveTrack, AddCollaborator, GetCollaborators, RemoveCollaborator
- Uses in-memory SQLite database with real services for realistic testing
- All tests compile successfully

Phase: PHASE-5
Priority: P2
Progress: 123/267 (46.1%)
2025-12-25 01:25:33 +01:00
senke
537da5076c [BE-TEST-002] test: Add unit tests for track handlers
- Created handler_test.go with comprehensive unit tests
- Tests cover GetTrack, ListTracks, UpdateTrack, DeleteTrack, LikeTrack, SearchTracks
- Uses in-memory SQLite database with real services for realistic testing
- All tests pass successfully

Phase: PHASE-5
Priority: P2
Progress: 122/267 (45.7%)
2025-12-24 18:19:34 +01:00
senke
dce5ff3484 [BE-TEST-001] be-test: Add unit tests for auth handlers
- Created comprehensive unit tests for all authentication handlers
- Tests cover Login, Register, Refresh, Logout, VerifyEmail, ResendVerification, CheckUsername, and GetMe
- Tests use real AuthService with in-memory SQLite database for realistic testing
- All handlers tested with success cases, error cases, and edge cases
- Fixed ExpiresIn calculation in Login and Refresh handlers to handle TokenPair.ExpiresIn
- Test coverage includes:
  - Login: success, invalid credentials, email not verified, requires 2FA, invalid request
  - Register: success, user already exists, invalid email, weak password, invalid request
  - Refresh: invalid request (token validation tested via integration tests)
  - Logout: success, unauthorized
  - VerifyEmail: missing token
  - ResendVerification: success
  - CheckUsername: available, taken, missing username
  - GetMe: success, unauthorized

Phase: PHASE-5
Priority: P2
Progress: 121/267 (45.32%)
2025-12-24 18:14:31 +01:00
senke
49dd584d67 [BE-SEC-015] be-sec: Implement dependency vulnerability scanning
- Verified existing vulnerability scanning implementation
- Workflow .github/workflows/vulnerability-scan.yml uses govulncheck for Go dependencies
- Workflow uses Trivy for Docker image scanning
- Makefile includes vulncheck target for local scanning
- System automatically blocks PRs if HIGH/CRITICAL vulnerabilities found
- Documentation exists in docs/VULNERABILITY_SCANNING.md
- Scanning works correctly (verified with make vulncheck)

Phase: PHASE-4
Priority: P2
Progress: 120/267 (44.94%)
2025-12-24 18:05:15 +01:00
senke
3cfefaa24c [BE-SEC-012] be-sec: Implement API key authentication for webhooks
- Added APIKey field to Webhook model with unique index
- Implemented GenerateAPIKey() method using crypto/rand for secure key generation
- Implemented ValidateAPIKey() method to authenticate webhook requests
- Implemented RegenerateAPIKey() method to rotate API keys
- Created WebhookAPIKeyMiddleware for validating API keys in requests
- Middleware supports X-API-Key header and Authorization: Bearer format
- Added endpoint POST /api/v1/webhooks/:id/regenerate-key
- API keys are prefixed with 'whk_' for identification
- Comprehensive unit tests for all API key functionality
- Inactive webhooks cannot authenticate with their API keys

Phase: PHASE-4
Priority: P2
Progress: 119/267 (44.57%)
2025-12-24 18:03:52 +01:00
senke
b8adaf8935 [BE-SVC-022] be-svc: Implement data export service
- Created DataExportService for comprehensive user data export (GDPR compliance)
- Exports all user data: profile, settings, tracks, playlists, comments, likes, analytics, federated identities, roles
- Added ExportUserData method to retrieve all user data from database
- Added ExportUserDataAsJSON method to export as downloadable JSON file
- Added endpoint GET /api/v1/users/me/export that returns JSON file download
- Comprehensive unit tests for export service
- Proper error handling and logging

Phase: PHASE-6
Priority: P2
Progress: 118/267 (44.19%)
2025-12-24 18:01:00 +01:00
senke
250d243fb8 [BE-SVC-021] be-svc: Implement error recovery mechanisms
- Created recovery package with comprehensive retry logic
- Implemented Retry and RetryWithResult with configurable strategies
- Added exponential backoff with jitter support
- Created multiple recovery strategies:
  - RetryRecoveryStrategy: retry with backoff
  - FallbackRecoveryStrategy: fallback function
  - CircuitBreakerRecoveryStrategy: wait for circuit breaker
  - CompositeRecoveryStrategy: combine multiple strategies
- Added helper functions: IsRetryableError, IsTemporaryError, IsPermanentError
- Support for context cancellation and timeout
- Comprehensive unit tests for all recovery mechanisms

Phase: PHASE-6
Priority: P2
Progress: 117/267 (43.82%)
2025-12-24 17:52:53 +01:00
senke
fe7cf7fc04 [BE-SVC-020] be-svc: Implement request validation improvements
- Enhanced error messages in validator with more descriptive and contextual messages
- Added custom validations: slug, phone, date_iso, not_empty
- Created QueryParamValidation middleware for query parameter validation
- Support for validation rules: numeric, integer, min, max, oneof, email, uuid, url
- Improved error messages for all validation tags (40+ tags supported)
- Comprehensive unit tests for query parameter validation
- Better error context and user-friendly messages

Phase: PHASE-6
Priority: P2
Progress: 116/267 (43.45%)
2025-12-24 17:09:54 +01:00
senke
7bafb85e22 [BE-SVC-019] be-svc: Implement API versioning strategy
- Created VersionManager for managing API versions
- Added VersionMiddleware for automatic version detection:
  - X-API-Version header
  - Accept header (application/vnd.veza.v1+json)
  - URL path (/api/v1/...)
- Added support for deprecated versions with sunset dates
- Added /api/versions endpoint for version information
- Added helpers: GetAPIVersion, GetAPIVersionInfo
- Comprehensive unit tests for versioning system
- Integrated version manager in APIRouter

Phase: PHASE-6
Priority: P2
Progress: 115/267 (43.07%)
2025-12-24 17:07:30 +01:00
senke
0ac3b82962 [BE-SVC-018] be-svc: Implement request tracing
- Created TraceContext struct for distributed tracing
- Implemented W3C Trace Context format support (traceparent header)
- Added backward compatibility with legacy X-Trace-ID and X-Span-ID headers
- Created HTTPClientWithTracing for automatic trace propagation in outgoing requests
- Enhanced Tracing middleware to use new trace context system
- Added context propagation helpers (WithTraceContext, FromContext)
- Added child span creation for nested operations
- Comprehensive unit tests for trace context and HTTP client

Phase: PHASE-6
Priority: P2
Progress: 114/267 (42.70%)
2025-12-24 17:05:32 +01:00
senke
965633ef89 [BE-SVC-017] be-svc: Implement graceful shutdown
- Created ShutdownManager for coordinated graceful shutdown of all services
- Added Shutdowner interface for services that need graceful shutdown
- Implemented parallel shutdown with individual timeouts (10s per service)
- Added global shutdown timeout (30s total)
- Integrated shutdown manager in main.go for:
  - HTTP server shutdown
  - JobWorker cancellation
  - Config.Close() (DB, Redis, RabbitMQ)
  - Logger sync
  - Sentry flush
- Added comprehensive unit tests for shutdown manager
- Prevents registration of new services during shutdown

Phase: PHASE-6
Priority: P2
Progress: 113/267 (42.32%)
2025-12-24 17:03:11 +01:00
senke
2f2c8a032c [BE-SVC-016] be-svc: Implement health check improvements
- Enhanced HealthCheck struct with Details field for additional metrics
- Added detailed database pool statistics (open connections, in use, idle, wait counts)
- Added health checks for S3 storage service (if enabled)
- Added health checks for Job Worker with job queue statistics
- Added health checks for Email Sender (SMTP configuration)
- Updated HealthHandler to accept additional services
- Updated router to pass S3, JobWorker, and EmailSender to health handler

Phase: PHASE-6
Priority: P2
Progress: 112/267 (41.95%)
2025-12-24 17:00:53 +01:00
senke
e1cf8472b6 [BE-SVC-015] be-svc: Implement logging aggregation
- Added HTTP writer for centralized log collection (Loki-compatible)
- Created AggregationConfig with batch processing and flush intervals
- Integrated with existing zap logger using multi-core approach
- Added environment variables for configuration (LOG_AGGREGATION_ENABLED, LOG_AGGREGATION_ENDPOINT, etc.)
- Added unit tests for aggregation functionality
- Updated config.go to initialize logger with aggregation if enabled

Phase: PHASE-6
Priority: P2
Progress: 111/267 (41.57%)
2025-12-24 16:58:58 +01:00
senke
f5d8486caa [BE-SVC-014] be-svc: Implement monitoring and alerting
- Created monitoring and alerting service with Prometheus integration
- Support for alert rules with thresholds and severities
- Alert firing and resolution tracking
- Notification callbacks for alert events
- Continuous monitoring with configurable intervals
- Default alert rules for common scenarios
- Prometheus query evaluation and threshold checking
- Comprehensive unit tests for core functionality
2025-12-24 16:54:19 +01:00
senke
03f35dbb7c [BE-SVC-013] be-svc: Implement CDN integration
- Created CDN service with support for multiple providers
- Support for CloudFront, Cloudflare, and generic CDN
- URL generation for assets, audio, HLS streams, and images
- Cache invalidation with batch support
- Signed URL generation for private content
- Cache headers configuration
- Provider abstraction for easy switching
- Comprehensive unit tests for all functionality
2025-12-24 16:52:06 +01:00
senke
0090fdfb8b [BE-SVC-012] be-svc: Implement HLS streaming service
- Enhanced HLS streaming service with additional features
- Stream validation and health checks
- URL generation for master and quality playlists
- Stream cleanup and management
- Statistics and monitoring
- Stream listing with filtering and pagination
- Status updates and existence checks
- Comprehensive unit tests for core functionality
2025-12-24 16:49:57 +01:00
senke
d52efd811e [BE-SVC-011] be-svc: Implement audio transcoding service
- Created AudioTranscodeService with FFmpeg support
- Support for multiple audio formats (MP3, AAC, FLAC, OGG, WAV, M4A)
- Configurable bitrates and quality presets (low, medium, high, lossless)
- Sample rate and channel configuration
- Timeout handling and error management
- Transcode and TranscodeMultiple methods
- FFmpeg availability checking
- Audio metadata extraction using ffprobe
- Format validation and codec selection
- Comprehensive unit tests for core functionality
2025-12-24 16:47:48 +01:00
senke
dee331c5ff [BE-SVC-010] be-svc: Implement image processing service
- Enhanced image processing service with multiple features
- Support for multiple image sizes (thumbnail, small, medium, large)
- Multiple output formats (JPEG, PNG, WebP)
- Configurable quality settings and processing options
- ProcessImage with customizable options
- ProcessAvatar for optimized avatar processing
- ProcessImageMultipleSizes for batch processing
- OptimizeImage for target file size optimization
- Image format conversion and validation
- Comprehensive unit tests for core functions
2025-12-24 16:44:58 +01:00
senke
5ed6929aa9 [BE-SVC-009] be-svc: Implement notification service
- Created Notification model for GORM with proper relationships
- Enhanced NotificationService with GORM-based implementation
- Features: pagination, filtering by type/read status, batch creation
- Mark as read (single and all), deletion (single and all read)
- Unread count and notification types listing
- Comprehensive unit tests for all operations
- Better error handling and logging
2025-12-24 16:41:11 +01:00
senke
597607bf01 [BE-SVC-008] be-svc: Implement analytics aggregation service
- Created AnalyticsAggregationService for analytics_events table
- Aggregation by event type and time period (hour, day, week, month)
- Support for filtering by event names and user ID
- Features: event counts, unique users, average per user, payload summary
- Top events ranking and user activity counts
- Uses PostgreSQL date_trunc and to_char for period grouping
- Added unit tests for service validation and helper functions
2025-12-24 16:38:09 +01:00
senke
6e4590d493 [BE-SVC-007] be-svc: Implement recommendation engine
- Created TrackRecommendationService with ML-based algorithms
- Collaborative filtering (40%) using similar users' preferences
- Content-based filtering (30%) using track metadata (genre, artist, year)
- Popularity scoring (20%) based on play_count and like_count
- Recency scoring (10%) for recently uploaded tracks
- Support for seed tracks, genre filtering, and track exclusion
- Added unit tests for scoring algorithms
- Combines multiple algorithms for personalized recommendations
2025-12-24 16:34:17 +01:00
senke
301370ad1a [BE-SVC-006] be-svc: Implement search service
- Created FullTextSearchService using PostgreSQL tsvector/tsquery
- Supports full-text search for tracks, users, and playlists
- Uses GIN indexes from migration 048_search_indexes.sql
- Features relevance scoring with ts_rank_cd
- Weighted search (title/name weighted higher than description)
- Pagination and minimum relevance score filtering
- Unified search across all types and individual search methods
- Added unit tests for service validation and query preparation
2025-12-24 16:31:40 +01:00
senke
4c652150c5 [BE-SVC-005] be-svc: Implement file storage abstraction
- Added AWS SDK v2 dependency for S3 support
- Created S3StorageService implementing S3Service interface
- Support for AWS S3 and MinIO (S3-compatible storage)
- Added S3 configuration in config.go with environment variables
- Implemented upload, delete, presigned URL, and public URL methods
- Added unit tests for service validation and URL generation
- Service integrates with existing TrackStorageService
2025-12-24 16:28:51 +01:00
senke
1cf863a78b [BE-SVC-004] be-svc: Implement email service 2025-12-24 16:11:02 +01:00
senke
64d764c16f [BE-SVC-003] be-svc: Implement background job queue 2025-12-24 16:08:51 +01:00
senke
dc4fd2f3e1 [BE-SVC-002] be-svc: Implement rate limiting per user 2025-12-24 16:04:36 +01:00
senke
a11e1820b6 [BE-SVC-001] be-svc: Implement caching layer for frequently accessed data 2025-12-24 16:02:16 +01:00
senke
80ce04e8c6 [BE-DB-018] be-db: Add database performance monitoring 2025-12-24 15:58:48 +01:00
senke
e23a701d7b [BE-DB-017] be-db: Add database migration rollback tests 2025-12-24 15:57:19 +01:00
senke
96d9065066 [BE-DB-016] be-db: Add database backup strategy 2025-12-24 15:55:46 +01:00
senke
0bc1192ee4 [BE-DB-015] be-db: Optimize database connection pooling 2025-12-24 15:53:19 +01:00
senke
3ab31d9c5c [BE-DB-014] be-db: Add database triggers for audit logging 2025-12-24 15:47:38 +01:00
senke
8007d9e387 [BE-DB-013] be-db: Add database views for common queries 2025-12-24 15:46:29 +01:00
senke
783ff06f13 [BE-DB-012] be-db: Create migration for analytics_events table (already exists) 2025-12-24 15:45:17 +01:00
senke
15618c3d98 [BE-DB-011] be-db: Add database constraints for data validation 2025-12-24 15:43:52 +01:00
senke
530f170ef9 [BE-DB-010] be-db: Add composite indexes for common queries 2025-12-24 15:14:17 +01:00
senke
caab043970 [BE-DB-009] be-db: Add indexes for search queries 2025-12-24 15:13:03 +01:00
senke
974ef31a9c [BE-DB-008] be-db: Create migration for notifications table 2025-12-24 15:12:11 +01:00
senke
5c8a49d4f5 [BE-DB-007] be-db: Create migration for user_blocks table 2025-12-24 15:11:32 +01:00
senke
c1f6e93c95 [BE-DB-006] be-db: Create migration for user_follows table 2025-12-24 15:10:34 +01:00
senke
d0e25a3924 [BE-DB-005] be-db: Create migration for playlist_share_link table 2025-12-24 15:09:44 +01:00
senke
b646243bdf [BE-DB-004] be-db: Add created_at and updated_at timestamps to all models 2025-12-24 15:08:43 +01:00