Commit graph

15 commits

Author SHA1 Message Date
Lasse Rune Hansen
ef72cbea18 fix(backend/auth): Fix JWT token claim mapping for user ID
- Changed AuthService.GenerateJwtToken to use JWT standard claims:
  - JwtRegisteredClaimNames.Sub for user ID (instead of ClaimTypes.NameIdentifier)
  - JwtRegisteredClaimNames.Name for username
  - JwtRegisteredClaimNames.Email for email
  - JwtRegisteredClaimNames.UniqueName for additional username claim
  - Kept ClaimTypes.Role for role

- Updated AuthController.GetCurrentUser to use JwtRegisteredClaimNames.Sub
- Updated AdminController.DeleteUserAsync to use JwtRegisteredClaimNames.Sub

This fixes the 401 error when calling /me after login. The issue was that
tokens were being generated with ClaimTypes.NameIdentifier claim, but the
JWT middleware doesn't automatically map this to a claim that can be found
with User.FindFirst(). Using standard JWT claims (sub, name, email) ensures
proper compatibility with ASP.NET Core's JWT authentication.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-14 17:38:27 +02:00
Lasse Rune Hansen
42778ec34b fix(backend/auth): Fix authentication bugs
- Fix case-insensitive email lookups in AuthService (RegisterAsync, LoginAsync, CreateAdminUserAsync)
- Fix User.Create factory method to explicitly set Role property (C# object initializer behavior)
- Assign Admin role to seeded admin user in SeedDataExtension
- Add [AllowAnonymous] to Register and Login endpoints in AuthController (defensive programming)
- Increase JWT ClockSkew to 5 minutes for clock difference tolerance

These fixes resolve issues where:
- Login fails with 401 due to case-sensitive email comparison
- User role is null instead of 'User' or 'Admin'
- JWT token validation too strict on clock synchronization

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-14 16:40:01 +02:00
Lasse Rune Hansen
50f1b8a8dc feat(backend): Implement mandatory authentication and admin module
- Add Role property to User entity with migration
- Create BootstrapController for first admin user creation
- Remove [AllowAnonymous] from all learning content controllers
- Create AdminController with admin-only endpoints
- Create AdminService for user management
- Create UserReportService for progress reports
- Add UserRepository implementation
- Update AuthService with role support

feat(frontend): Implement authentication system
- Add AuthStore with React context for auth state management
- Create Login, Register, Landing, and Home pages
- Add ProtectedRoute and AdminRoute components
- Create Auth API types and client
- Configure Vite with @/ path alias
- Add comprehensive CSS styles for auth and landing pages

BREAKING CHANGE: All learning content now requires authentication.
Users must register and sign in before accessing lessons, quizzes, and stories.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-14 12:42:15 +02:00
Lasse Rune Hansen
be692886a9 feat(docs/admin): Add Admin Module feature specification and update roadmap
- Created admin-module.md with comprehensive feature documentation
- Updated README.md roadmap with current status and progress
- Added [Authorize] to StoryController GET endpoints
- Documented requirements:
  - Mandatory user registration before accessing content
  - Individual user progress tracking
  - Admin module (Lasse only)
  - Admin story generation functionality
  - Admin user progress reports
- Updated development roadmap with Phase 4 (Admin Module)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-14 11:45:55 +02:00
Lasse Rune Hansen
82df791907 fix(backend/api): Return empty array instead of 404 when no story segments exist
- GetSegmentsByLevelAsync now returns Ok([]) instead of NotFound() when no segments exist
- Prevents frontend from throwing errors when database has no story segments
- More RESTful: 200 with empty array vs 404 for non-existence

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-14 09:19:11 +02:00
Lasse Rune Hansen
de85cdec7c fix(backend/api): Remove [Authorize] from StoryController GET endpoints
- Removed class-level [Authorize] from StoryController
- Admin endpoints already have [Authorize(Roles = "Admin")]
- GET endpoints are now publicly accessible for development/testing
- Updated frontend API client to handle unauthenticated requests

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-14 07:41:50 +02:00
Mistral Vibe
518d1c8f27 feat(backend/story-integration): Phase 5 - Audio Generation
- Fixed audio file path generation in StoryGenerationService.GenerateAudioAsync
- Audio files now stored at wwwroot/audio/story/level{id}-segment{order}.wav
- Added static file serving in Program.cs (app.UseStaticFiles)
- Added wwwroot/audio/story directory creation on startup
- Updated StoryController.GetSegmentAudioAsync to return audio URL
- Static file middleware serves audio files automatically
- All 324 tests still pass

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-13 14:47:32 +02:00
Lasse Rune Hansen
6693165f83 feat(backend/story-integration): Phase 2 - Backend Services
Implement story integration backend services:
- Create StoryService (Application/Services/StoryService.cs) with full CRUD operations
- Create StoryGenerationService (Application/Services/StoryGenerationService.cs) for AI-powered story generation
  - Uses IMistralService for text generation
  - Uses ITtsService for audio generation
  - Splits stories into segments per lesson
- Create StoryUnlockService (Application/Services/StoryUnlockService.cs) for progress management
  - Handles lesson completion → story segment unlocking
- Create StoryController (Presentation/Controllers/StoryController.cs) with 12 endpoints:
  - GET /api/story/levels - list levels with stories
  - GET /api/story/levels/{levelId}/segments - get segments for level
  - GET /api/story/segments/{id} - get specific segment
  - POST /api/story/segments - create segment (Admin)
  - PUT /api/story/segments/{id} - update segment (Admin)
  - DELETE /api/story/segments/{id} - delete segment (Admin)
  - POST /api/story/levels/{levelId}/generate - generate story with AI (Admin)
  - POST /api/story/segments/{segmentId}/audio - generate audio (Admin)
  - GET /api/story/levels/{levelId}/progress - get user progress
  - POST /api/story/segments/{segmentId}/complete - mark as completed
  - GET /api/story/levels/{levelId}/next - get next segment
  - GET /api/story/segments/{segmentId}/unlocked - check if unlocked
  - GET /api/story/segments/{segmentId}/audio - get audio URL
  - GET /api/story/levels/{levelId}/lessons-with-stories - get lessons with story status
- Register all services in Program.cs DI container
- Update feature document to reflect Phase 2 completion

Next: Phase 3 - AI Integration (unit tests for services)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-13 13:37:16 +02:00
Lasse Rune Hansen
769c63b005 feat(backend/ai-services): Complete AI Services Phase 0-4 implementation
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- Add Domain interfaces: IMistralService, IVoskService, ITtsService
- Add Configuration classes: VoskConfig, CoquiConfig
- Add Application service: MistralService (text generation with Mistral)
- Add Infrastructure services: VoskService (speech recognition), TtsService (TTS)
- Add Presentation controllers: MistralController, SpeechController, TtsController
- Fix MistralService to use correct IMistralConnector methods (CompleteAsync, ChatAsync)
- Fix TtsController to use record constructor syntax
- Fix TtsService Task.FromResult type specification
- Fix Program.cs service registration and remove merge conflict markers
- Update docs/features/ai-services.md with progress (Phases 0-4 complete)
- Update docs/ROADMAP.md with AI Services status and test metrics (296 tests)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-13 10:09:19 +02:00
Lasse Rune Hansen
242d5ea60b feat(backend): Complete Quiz System implementation
- Add Quiz entity with full domain logic (Create, Update, Activate, Deactivate)
- Add QuizQuestion entity updated to use QuizId instead of LessonId
- Add QuizRepository with all CRUD and query methods
- Add QuizQuestionRepository with QuizId-based and LessonId-based (legacy) methods
- Add QuizDto, CreateQuizDto, UpdateQuizDto, QuizWithQuestionsDto, QuizListItemDto
- Add QuizQuestionDto updated with QuizId, LessonId, QuizTitle, Points fields
- Add CreateQuizCommand, UpdateQuizCommand, DeleteQuizCommand, GetQuizWithQuestionsCommand
- Add QuizService with full quiz management (CRUD, activate, deactivate, counts, queries)
- Add QuizQuestionService updated with QuizId-based methods
- Add QuizzesController with comprehensive endpoints (GET, POST, PUT, DELETE)
- Add QuizzesController endpoints for quiz questions (by-quiz, random, active)
- Update QuizQuestionsController with new QuizId-based endpoints (backward compatible)
- Register QuizRepository and QuizService in DI container
- Update IRepository interfaces with QuizId-based methods
- Add SubmitQuizDto for quiz answer submission

Clean Architecture layers maintained:
- Domain: Quiz, QuizQuestion entities with business logic
- Application: DTOs, Commands, Services
- Infrastructure: Repositories, DbContext
- Presentation: Controllers

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-13 07:41:46 +02:00
Lasse Rune Hansen
04ad7ef008 feat(backend/domain): add quiz question feature with Docker migration support
- Add QuizQuestion and QuizOption domain entities with QuestionType enum
- Add IQuizQuestionRepository and IQuizOptionRepository interfaces
- Add QuizQuestionRepository and QuizOptionRepository EF Core implementations
- Add QuizQuestionService with CRUD, quiz submission, and statistics
- Add QuizQuestionsController with comprehensive REST API endpoints
- Add QuizQuestionDto and related DTOs for API communication
- Add EF Core migration (20260612050652_AddQuizQuestionTables) for QuizQuestion and QuizOption
- Add seed data with sample quiz questions for Greetings, Numbers, Grammar lessons
- Update AppDbContext with DbSets and entity configurations
- Update Program.cs with migration retry logic for Docker
- Update docker-compose.yml with SeedDatabase configuration
- Add unit tests for QuizQuestionService

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-12 16:49:27 +02:00
Lasse Rune Hansen
a6021fb148 feat(backend/validation): add FluentValidation for DTOs and update controllers
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- Add FluentValidation.AspNetCore package
- Create LevelValidators (CreateLevelValidator, UpdateLevelValidator)
- Create LessonValidators (CreateLessonValidator, UpdateLessonValidator)
- Register FluentValidation in Program.cs with auto-validation
- Update LevelsController and LessonsController to use IActionResult
- Make service methods virtual for Moq testing compatibility
- Add 26 integration tests for LevelsController (13 tests)
- Add 34 integration tests for LessonsController (17 tests)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-09 17:35:14 +02:00
Lasse Rune Hansen
3caee4c21e feat(backend/presentation): add LevelsController and LessonsController for Lesson Management
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- Created LevelsController.cs with full CRUD operations
  - GET /api/levels - all levels
  - GET /api/levels/{id} - level by ID
  - GET /api/levels/by-code/{code} - level by code
  - GET /api/levels/first - first level
  - GET /api/levels/next/{id} - next level
  - POST /api/levels - create level (Admin)
  - PUT /api/levels/{id} - update level (Admin)
  - DELETE /api/levels/{id} - delete level (Admin)

- Created LessonsController.cs with full CRUD and filtering
  - GET /api/lessons - all lessons
  - GET /api/lessons/ordered - ordered lessons
  - GET /api/lessons/{id} - lesson by ID
  - GET /api/lessons/by-level/{levelId} - lessons by level
  - GET /api/lessons/beginner - beginner lessons
  - GET /api/lessons/advanced - advanced lessons
  - GET /api/lessons/first/{levelId} - first lesson in level
  - GET /api/lessons/next/{id} - next lesson
  - GET /api/lessons/accessible/{userId} - accessible lessons
  - GET /api/lessons/unlocked/{userId}/{lessonId} - check unlock
  - POST /api/lessons - create lesson (Admin)
  - PUT /api/lessons/{id} - update lesson (Admin)
  - DELETE /api/lessons/{id} - delete lesson (Admin)

- Added authorization: [Authorize] for most endpoints, [AllowAnonymous] for read-only
- Added Admin role requirement for write operations

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-09 07:20:29 +02:00
Lasse Rune Hansen
6bcf592918 feat(backend): complete unit tests for User Authentication feature
- Fix MSTest compatibility with .NET 9.0 by upgrading to MSTest.TestFramework 4.2.3
- Move Tests directory to solution level (Tests/) to prevent test files from being compiled with GermanApp
- Update test project references to point to GermanApp/GermanApp.csproj
- Add InternalsVisibleTo attributes for test assemblies
- Make RefreshToken properties internal for testability
- Fix User.ChangeEmail null handling
- Add 46 comprehensive unit tests for User and RefreshToken domain entities
- All tests passing successfully

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-05 17:07:15 +02:00
Lasse Rune Hansen
d508d498c0 feat(backend/auth): implement User Authentication feature
- Add DTOs: RegisterDto, LoginDto, AuthResponse
- Add IAuthService interface
- Implement AuthService with JWT token generation
- Create AuthController with register, login, me endpoints
- Add JWT configuration to appsettings.json
- Configure JWT Bearer authentication in Program.cs
- Add PasswordHasher for custom User entity
- Update User entity with ChangePassword method
- Add necessary NuGet packages for JWT auth

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-05 13:27:43 +02:00