Commit graph

59 commits

Author SHA1 Message Date
senke
0441c2adf6 [INT-AUTH-001] Ensure CSRF protection active in production 2025-12-25 22:28:46 +01:00
senke
24cf8f0b9d [FE-TEST-001] fe-test: Add unit tests for API services
- Created comprehensive unit tests for marketplaceService (11 tests)
- Created comprehensive unit tests for profileService (12 tests)
- Created comprehensive unit tests for avatarService (9 tests)
- Created comprehensive unit tests for 2fa-service (8 tests)
- All 40 tests pass successfully
- Tests cover success cases, error handling, edge cases, and validation scenarios

Files modified:
- apps/web/src/services/marketplaceService.test.ts (new)
- apps/web/src/features/profile/services/profileService.test.ts (new)
- apps/web/src/features/profile/services/avatarService.test.ts (new)
- apps/web/src/services/2fa-service.test.ts (new)
- VEZA_COMPLETE_MVP_TODOLIST.json
2025-12-25 15:55:53 +01:00
senke
dfbbc7dfa8 [INT-021] int: Add API monitoring and alerting
- Created APIMonitoringMiddleware to track API failures (5xx errors), slow requests, and timeouts
- Created HealthCheckMonitoring middleware for health check endpoints
- Integrated MonitoringAlertingService into router with automatic initialization
- Service starts monitoring in background with default alert rules
- Provides comprehensive monitoring and alerting for API health and failures
- Monitoring activates when PROMETHEUS_URL is configured

Files modified:
- veza-backend-api/internal/middleware/monitoring.go (new)
- veza-backend-api/internal/api/router.go
- VEZA_COMPLETE_MVP_TODOLIST.json
2025-12-25 15:53:13 +01:00
senke
60349069f2 [INT-018] int: Add CORS configuration validation
- Enhanced ValidateCORSConfiguration to accept environment parameter
- Enforce strict validation in production (fail-fast on wildcard or empty CORS)
- In production, startup fails if CORS is misconfigured
- In development/staging, warnings are logged but startup continues
- Updated router to use environment-aware validation

Files modified:
- veza-backend-api/internal/middleware/cors.go
- veza-backend-api/internal/api/router.go
- VEZA_COMPLETE_MVP_TODOLIST.json
2025-12-25 15:48:48 +01:00
senke
27517ae916 [INT-017] int: Add session management integration
- Fixed GetSessions handler to identify current session by comparing token hash
- Added session creation during token refresh to ensure sessions are tracked
- Sessions are now correctly identified as current in the frontend
- Updated Refresh handler to accept sessionService parameter

Files modified:
- veza-backend-api/internal/handlers/session.go
- veza-backend-api/internal/handlers/auth.go
- veza-backend-api/internal/api/router.go
- VEZA_COMPLETE_MVP_TODOLIST.json
2025-12-25 15:47:33 +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
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
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
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
a11e1820b6 [BE-SVC-001] be-svc: Implement caching layer for frequently accessed data 2025-12-24 16:02:16 +01:00
senke
ab1f78030b [BE-API-042] be-api: Implement OAuth callback endpoint 2025-12-24 15:05:40 +01:00
senke
5a41b8c976 [BE-API-041] be-api: Implement user delete endpoint with soft delete support 2025-12-24 15:03:21 +01:00
senke
0657b79d09 [BE-API-039] be-api: Implement marketplace order details endpoint 2025-12-24 15:00:32 +01:00
senke
04ea22149c [BE-API-038] be-api: Implement marketplace order list endpoint 2025-12-24 14:50:39 +01:00
senke
f6fa8d933a [BE-API-037] be-api: Implement marketplace product update endpoint 2025-12-24 14:49:41 +01:00
senke
3e4e2bb174 [BE-API-036] be-api: Implement track analytics dashboard endpoint 2025-12-24 14:48:28 +01:00
senke
20b8210339 [BE-API-035] be-api: Implement analytics events endpoint 2025-12-24 14:47:12 +01:00
senke
bc7ff26958 [BE-API-005] be-api: Implement playlist recommendations endpoint 2025-12-24 14:41:33 +01:00
senke
1394660da3 [BE-SEC-013] be-sec: Implement audit logging for security events
- Added comprehensive audit logging methods for security events
- LogPasswordChange, LogPasswordResetRequest, LogPasswordReset
- LogTwoFactorEnabled, LogTwoFactorDisabled, LogTwoFactorVerification
- LogAccessDenied, LogRoleChange, LogAccountLocked
- LogSecurityEvent for generic security events
- Integrated audit logging in password reset handlers
- All security events logged with IP, user agent, and metadata
2025-12-24 12:27:39 +01:00
senke
44517da6f6 [BE-SEC-007] security: Implement account lockout after failed login attempts
- Created AccountLockoutService to track failed login attempts
- Accounts are locked after 5 failed attempts within 15 minutes
- Lockout duration: 30 minutes (auto-unlock)
- Service uses Redis for persistence (fail-open if Redis unavailable)
- Integrated into AuthService Login method:
  * Check account lockout status before login
  * Record failed attempts (even for non-existent users to prevent enumeration)
  * Reset failed attempts counter on successful login
  * Auto-unlock expired accounts
- Added SetAccountLockoutService method to AuthService
- Service initialized in router when Redis is available

Phase: PHASE-4
Priority: P1
Progress: 9/267 (3.4%)
2025-12-24 12:10:41 +01:00
senke
33d1aa988c [BE-SEC-005] security: Implement rate limiting for authentication endpoints
- Applied RegisterRateLimit to POST /auth/register (3 attempts/hour)
- Applied PasswordResetRateLimit to password reset endpoints (3 attempts/hour)
- Added VerifyEmailRateLimit for POST /auth/verify-email (5 attempts/hour)
- Added ResendVerificationRateLimit for POST /auth/resend-verification (3 attempts/hour)
- Login endpoint already had rate limiting (5 attempts/15min)
- All rate limits are IP-based and use Redis for persistence
- Rate limiting disabled in test/e2e environments

Phase: PHASE-4
Priority: P1
Progress: 7/267 (2.6%)
2025-12-24 12:05:35 +01:00
senke
078e512770 [BE-SEC-004] security: Implement CSRF protection for all state-changing endpoints
- Created applyCSRFProtection helper function to apply CSRF middleware
- Applied CSRF protection to all protected routes with POST/PUT/DELETE:
  * Users routes (PUT, POST, DELETE)
  * Tracks routes (POST, PUT, DELETE)
  * Playlists routes (POST, PUT, DELETE)
  * Chat routes (POST)
  * Auth protected routes (POST logout, 2FA)
  * Roles routes (GET only, no state-changing)
  * Marketplace routes (POST)
  * Webhooks routes (POST, DELETE)
  * Comments routes (POST, DELETE)
- CSRF token endpoint (/csrf-token) remains accessible without CSRF check
- Middleware validates X-CSRF-Token header for all state-changing requests
- Protection only applies when Redis is available

Phase: PHASE-4
Priority: P1
Progress: 6/267 (2.2%)
2025-12-24 12:03:27 +01:00
senke
46fb0cc148 [BE-API-040] api: Implement user list endpoint
- Added ListUsers method to UserService with pagination and filtering
- Added ListUsers handler to ProfileHandler
- Registered GET /api/v1/users endpoint in router
- Supports filtering by role, is_active, is_verified, and search
- Supports sorting by created_at, username, email, last_login_at
- Includes pagination metadata (page, limit, total, total_pages, has_next, has_prev)

Phase: PHASE-2
Priority: P1
Progress: 5/267 (1.9%)
2025-12-24 11:59:56 +01:00
senke
78a25f63f7 [BE-API-032] be-api: Implement upload stats endpoint
- Added GetUploadStats method in TrackUploadService to calculate statistics from tracks table
- Standardized GetUploadStats handler to use RespondSuccess/RespondWithAppError
- Replaced c.Get with GetUserIDUUID helper
- Handler retrieves statistics: total_uploads, total_size, audio_files, image_files, video_files
- Updated UploadHandler to include TrackUploadService dependency
- Updated router to pass TrackUploadService to UploadHandler

Phase: PHASE-2
Priority: P2
Progress: 39/267 (14.6%)
2025-12-24 11:52:49 +01:00
senke
5bc2498744 [BE-API-027] be-api: Implement user liked tracks endpoint
- Standardized GetUserLikedTracks handler to use RespondSuccess/RespondWithAppError
- Added limit validation (max 100)
- Moved route from setupTrackRoutes to setupUserRoutes in protected group
- Handler uses existing TrackLikeService methods
- Handler returns paginated results with tracks, total, limit, and offset
- Handler uses standard API response format

Phase: PHASE-2
Priority: P1
Progress: 34/267 (12.7%)
2025-12-24 11:41:50 +01:00
senke
48734f8526 [BE-API-022] be-api: Implement avatar delete endpoint
- DeleteAvatar handler was already implemented and standardized
- Added route: DELETE /users/:userId/avatar
- Handler validates user authentication and ownership
- Handler deletes avatar file from storage and updates database
- Handler uses standard API response format

Phase: PHASE-2
Priority: P1
Progress: 31/267 (11.6%)
2025-12-24 11:36:15 +01:00
senke
3afc57dfbc [BE-API-021] be-api: Implement avatar upload endpoint
- Standardized UploadAvatar handler to use RespondSuccess/RespondWithAppError
- Replaced common.GetUserIDFromContext with GetUserIDUUID
- Handler accepts both :userId and :id parameters
- Added route: POST /users/:userId/avatar
- Handler validates user authentication and ownership
- Handler uses existing ImageService methods
- Handler updates avatar URL in database

Phase: PHASE-2
Priority: P1
Progress: 30/267 (11.2%)
2025-12-24 11:34:41 +01:00
senke
f75ebb5e20 [BE-API-020] be-api: Implement HLS stream info endpoint
- Added GetStreamInfo method to HLSService
- Added GetStreamInfo handler in HLSHandler
- Standardized GetStreamStatus handler to use RespondSuccess/RespondWithAppError
- Added routes: GET /tracks/:id/hls/info and GET /tracks/:id/hls/status
- GetStreamInfo returns general stream information
- GetStreamStatus returns status with processing info if applicable
- Handlers use standard API response format

Phase: PHASE-2
Priority: P1
Progress: 29/267 (10.9%)
2025-12-24 11:32:50 +01:00
senke
971f9253bb [BE-API-019] be-api: Implement track play analytics endpoint
- Added RecordPlay handler in TrackHandler
- Added playbackAnalyticsService field and SetPlaybackAnalyticsService method
- Initialized PlaybackAnalyticsService in router.go
- Added route: POST /tracks/:id/play
- Handler accepts optional play_time in request body
- Handler uses existing PlaybackAnalyticsService.RecordPlayback method
- Handler uses standard API response format

Phase: PHASE-2
Priority: P1
Progress: 28/267 (10.5%)
2025-12-24 11:31:02 +01:00
senke
78862c6ee1 [BE-API-018] be-api: Implement user block/unblock endpoints
- Added BlockUser and UnblockUser methods to SocialService
- Added BlockUser and UnblockUser handlers in ProfileHandler
- Added routes: POST /users/:id/block and DELETE /users/:id/block
- Handlers use existing SocialService methods
- Includes validation to prevent users from blocking themselves
- Added IsBlocked helper method to check block status
- Handlers use standard API response format

Phase: PHASE-2
Priority: P2
Progress: 27/267 (10.1%)
2025-12-24 11:28:49 +01:00
senke
94bac9a5fd [BE-API-017] be-api: Implement user follow/unfollow endpoints
- Added FollowUser and UnfollowUser handlers in ProfileHandler
- Added socialService field and SetSocialService method
- Initialized SocialService in setupUserRoutes
- Added routes: POST /users/:id/follow and DELETE /users/:id/follow
- Handlers use existing SocialService methods
- Includes validation to prevent users from following themselves
- Handlers use standard API response format

Phase: PHASE-2
Priority: P2
Progress: 26/267 (9.7%)
2025-12-24 11:26:32 +01:00
senke
398565d5a9 [BE-API-016] be-api: Implement notifications endpoints
- Standardized API responses in notification handlers
- Replaced c.Get with GetUserIDUUID for consistent user ID extraction
- Added routes: GET /notifications, POST /notifications/:id/read, POST /notifications/read-all
- Initialized NotificationService and NotificationHandlers in router
- Handlers and service already existed, only routes and response standardization were needed

Phase: PHASE-2
Priority: P1
Progress: 25/267 (9.4%)
2025-12-24 11:23:24 +01:00
senke
50f58f1f16 [BE-API-014] be-api: Implement track versions restore endpoint
- Added RestoreVersion handler method in TrackHandler
- Initialized TrackVersionService in setupTrackRoutes
- Added POST /tracks/:id/versions/:versionId/restore route (protected)
- Handler uses existing TrackVersionService.RestoreVersion method
- Includes ownership check (only track owner can restore versions)

Phase: PHASE-2
Priority: P2
Progress: 23/267 (8.6%)
2025-12-24 11:20:38 +01:00
senke
f90ddb0b0c [BE-API-013] be-api: Implement track comments endpoints
- Added GET /tracks/:id/comments route (public)
- Added POST /tracks/:id/comments route (protected)
- Added DELETE /comments/:id route (protected)
- Initialized CommentService and CommentHandler in setupTrackRoutes
- Standardized API responses in comment handlers
- Handlers use RespondSuccess and RespondWithAppError

Phase: PHASE-2
Priority: P1
Progress: 22/267 (8.2%)
2025-12-24 11:19:05 +01:00
senke
32c5f711d6 [BE-API-012] be-api: Implement conversation update endpoint
- Added UpdateRoom method to RoomService with ownership check
- Only room creator can update the room
- Added UpdateRoomRequest type
- Added UpdateRoom to RoomServiceInterface and RoomHandler
- Added PUT /conversations/:id route
- Handler uses standard API response format
- Service updates name and/or description fields

Phase: PHASE-2
Priority: P1
Progress: 21/267 (7.9%)
2025-12-23 10:51:18 +01:00
senke
461add8300 [BE-API-011] be-api: Implement conversation participants endpoints
- Added RemoveMember method to RoomService and RoomServiceInterface
- Corrected RemoveMember in RoomRepository to use uuid.UUID
- Added AddParticipant and RemoveParticipant handlers
- Added POST /conversations/:id/participants route
- Added DELETE /conversations/:id/participants/:userId route
- Handlers use standard API response format
- Handlers reuse AddMember/RemoveMember service methods

Phase: PHASE-2
Priority: P1
Progress: 20/267 (7.5%)
2025-12-23 10:49:17 +01:00
senke
d1343dabfb [BE-API-010] be-api: Implement conversation delete endpoint
- Added DeleteRoom method to RoomService with ownership check
- Only room creator can delete the room
- Added DeleteRoom to RoomServiceInterface and RoomHandler
- Added DELETE /conversations/:id route
- Handler uses standard API response format
- Service performs soft delete via GORM

Phase: PHASE-2
Priority: P1
Progress: 19/267 (7.1%)
2025-12-23 10:47:17 +01:00
senke
4959b44e8f [BE-API-009] be-api: Implement track search endpoint
- Added GET /tracks/search route in setupTrackRoutes
- Initialized TrackSearchService and set it in TrackHandler
- Handler SearchTracks and TrackSearchService already existed
- Supports query params: q, genre, artist, page, limit
- Service handles pagination, filtering, and returns tracks with pagination metadata

Phase: PHASE-2
Priority: P1
Progress: 18/267 (6.7%)
2025-12-23 10:45:08 +01:00
senke
dda16108e7 [BE-API-008] be-api: Implement user search endpoint
- Created SearchUsers method in UserService with pagination support
- SearchUsers searches by username, email, first_name, and last_name using ILIKE
- Added SearchUsers handler in ProfileHandler with query params (q, page, limit)
- Added GET /users/search route in setupUserRoutes
- Returns paginated results with total count
- Password hashes are excluded from results

Phase: PHASE-2
Priority: P1
Progress: 17/267 (6.4%)
2025-12-23 10:42:26 +01:00
senke
714f17f4c6 [BE-API-007] be-api: Implement roles management endpoints
- Standardized API responses in RoleHandler (RespondSuccess, RespondWithAppError)
- Added GET /api/v1/roles endpoint
- Added GET /api/v1/roles/:id endpoint
- Added POST /api/v1/users/:userId/roles endpoint
- Added DELETE /api/v1/users/:userId/roles/:roleId endpoint
- Created setupRoleRoutes function for role routes
- Handlers support both :id and :userId parameters
- All endpoints require authentication

Phase: PHASE-2
Priority: P1
Progress: 16/267 (6.0%)
2025-12-23 10:39:10 +01:00
senke
a3c055efbb [BE-API-006] be-api: Implement chat stats endpoint
- Added GetStats method to ChatService with database access
- Returns active_users (distinct users who sent messages in last 24h)
- Returns total_messages (non-deleted messages count)
- Returns rooms_active (rooms with messages in last 24h)
- Added GetStats handler and GET /chat/stats route
- Updated ChatService to use NewChatServiceWithDB for database access

Phase: PHASE-2
Priority: P1
Progress: 15/267 (5.6%)
2025-12-23 01:51:49 +01:00
senke
bd938d6750 [BE-API-004] be-api: Implement playlist share link endpoint
- Added POST /playlists/:id/share route in router.go
- Initialized PlaylistShareService and set it in PlaylistService
- Handler CreateShareLink already existed and was fully implemented
- Standardized API response to return shareLink directly
- Route requires ownership or admin permission via middleware

Phase: PHASE-2
Priority: P1
Progress: 14/267 (5.2%)
2025-12-23 01:51:00 +01:00
senke
fbe7349679 [BE-API-003] be-api: Implement playlist search endpoint
- Added GET /playlists/search route in router.go
- Handler SearchPlaylists and service method already existed
- Supports query params: q, user_id, is_public, page, limit
- Service handles pagination, access control, and search filtering
- Route added to protected playlist group

Phase: PHASE-2
Priority: P1
Progress: 13/267 (4.9%)
2025-12-23 01:49:21 +01:00
senke
f6ab2c6eeb [BE-API-002] api: Implement playlist collaborators endpoints
- Added routes in router.go: POST, GET, PUT, DELETE /playlists/:id/collaborators
- Applied RequireOwnershipOrAdmin middleware to POST, PUT, DELETE routes
- GET route accessible to collaborators (service layer checks permissions)
- Fixed UpdateCollaboratorPermission handler to use RespondWithAppError
- All handlers already existed in playlist_handler.go
- All endpoints properly authenticated and ownership checks enforced

Phase: PHASE-1
Priority: P0
Progress: 5/267 (1.9%)
2025-12-23 01:41:43 +01:00
senke
5e25825726 [BE-API-001] api: Implement 2FA endpoints (setup, verify, disable)
- Created TwoFactorHandler with SetupTwoFactor, VerifyTwoFactor, DisableTwoFactor, GetTwoFactorStatus
- Added routes: POST /auth/2fa/setup, POST /auth/2fa/verify, POST /auth/2fa/disable, GET /auth/2fa/status
- Updated LoginResponse DTO to include requires_2fa flag
- Updated Login handler to check 2FA status and return requires_2fa flag when enabled
- Reused existing TwoFactorService (already had QR generation and TOTP verification)
- Added VerifyTOTPCode helper method to TwoFactorService
- All endpoints properly authenticated with RequireAuth middleware

Phase: PHASE-1
Priority: P0
Progress: 4/267 (1.5%)
2025-12-23 01:40:28 +01:00
senke
246e3d9630 [BE-SEC-003] security: Fix ownership verification for playlist updates/deletes
- Added RequireOwnershipOrAdmin middleware to PUT/DELETE /playlists/:id routes
- Created playlistOwnerResolver that loads playlist from DB and returns owner user_id
- Service already handles ownership checks and collaborator permissions
- All existing integration tests pass (TestUpdatePlaylist_AsOwner, TestUpdatePlaylist_NotOwner, TestDeletePlaylist_AsOwner, TestDeletePlaylist_NotOwner)

Phase: PHASE-1
Priority: P0
Progress: 3/267 (1.1%)
2025-12-23 01:37:56 +01:00
senke
64336258e5 fix(MVP-014): Add CORS credentials configuration validation 2025-12-22 23:17:24 +01:00
senke
ccd4542f11 fix(MVP-009): Fix GetMe endpoint to return full user object from database 2025-12-22 23:03:46 +01:00
senke
114f363c65 fix(MVP-006): Standardize environment variable names (VITE_API_BASE_URL → VITE_API_URL) 2025-12-22 22:56:37 +01:00