- Created LevelDto.cs with LevelDto, CreateLevelDto, UpdateLevelDto - Created UserProgressDto.cs with UserProgressDto, UpdateUserProgressDto, LevelCompletionDto - Created LevelService.cs with CRUD operations for CEFR levels - Created LessonService.cs with CRUD operations and filtering by level - Created ProgressService.cs with user progress tracking, completion percentage, and lesson unlocking logic - Registered all new services in Program.cs - Fixed UserProgressDto ToEntity/UpdateFromDto to use domain entity methods Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
80 lines
2.1 KiB
C#
80 lines
2.1 KiB
C#
using GermanApp.Domain.Entities;
|
|
|
|
namespace GermanApp.Application.DTOs;
|
|
|
|
/// <summary>
|
|
/// Data Transfer Object for UserProgress - used for API responses.
|
|
/// This is a read-only representation of a UserProgress entity.
|
|
/// </summary>
|
|
public record UserProgressDto(
|
|
int Id,
|
|
int UserId,
|
|
int LessonId,
|
|
bool IsCompleted,
|
|
int QuizScore,
|
|
DateTime LastAttemptDate,
|
|
string? LessonTitle = null,
|
|
string? LevelName = null,
|
|
string? LevelCode = null);
|
|
|
|
/// <summary>
|
|
/// Data Transfer Object for creating/updating user progress.
|
|
/// </summary>
|
|
public record UpdateUserProgressDto(
|
|
int LessonId,
|
|
bool IsCompleted,
|
|
int QuizScore);
|
|
|
|
/// <summary>
|
|
/// Data Transfer Object for level completion summary.
|
|
/// </summary>
|
|
public record LevelCompletionDto(
|
|
int LevelId,
|
|
string LevelName,
|
|
string LevelCode,
|
|
int TotalLessons,
|
|
int CompletedLessons,
|
|
double CompletionPercentage);
|
|
|
|
/// <summary>
|
|
/// Extension methods for mapping between UserProgress entity and DTOs.
|
|
/// </summary>
|
|
public static class UserProgressDtoExtensions
|
|
{
|
|
public static UserProgressDto ToDto(this UserProgress userProgress) => new(
|
|
userProgress.Id,
|
|
userProgress.UserId,
|
|
userProgress.LessonId,
|
|
userProgress.IsCompleted,
|
|
userProgress.QuizScore,
|
|
userProgress.LastAttemptDate,
|
|
userProgress.Lesson?.Title,
|
|
userProgress.Lesson?.Level?.Name,
|
|
userProgress.Lesson?.Level?.Code);
|
|
|
|
public static UserProgress ToEntity(this UpdateUserProgressDto dto, int userId)
|
|
{
|
|
var progress = UserProgress.Create(userId, dto.LessonId);
|
|
if (dto.IsCompleted)
|
|
{
|
|
progress.MarkAsCompleted(dto.QuizScore);
|
|
}
|
|
else
|
|
{
|
|
progress.UpdateQuizScore(dto.QuizScore);
|
|
}
|
|
return progress;
|
|
}
|
|
|
|
public static void UpdateFromDto(this UserProgress userProgress, UpdateUserProgressDto dto)
|
|
{
|
|
if (dto.IsCompleted)
|
|
{
|
|
userProgress.MarkAsCompleted(dto.QuizScore);
|
|
}
|
|
else
|
|
{
|
|
userProgress.UpdateQuizScore(dto.QuizScore);
|
|
}
|
|
}
|
|
}
|