DeutschLernen/GermanApp/Application/DTOs/LessonDto.cs
Lasse Rune Hansen ba81359afa fix(backend): update Lesson entity and related code to use LevelId foreign key
- Updated Lesson entity to use LevelId (int) instead of Level (int)
- Added navigation property Level (Level entity)
- Added Order, Topic, and IsActive properties to Lesson
- Updated Lesson.Create() factory method signature to accept levelId, title, order, topic, description
- Split Update method into individual property update methods
- Updated LessonDto to use LevelId, LevelName, LevelCode instead of Level int
- Added CreateLessonDto and UpdateLessonDto with all required fields
- Added UpdateFromDto extension method for Lesson
- Updated CreateLessonCommand to validate LevelId instead of Level
- Updated SeedDataExtension to seed Level entities first, then use new Lesson.Create() signature
- Made SeedDatabaseAsync async and updated Program.cs to await it
- Updated LessonsEndpoints to use GetByLevelAsync for beginner/advanced queries
- Fixed missing using directive for Domain.Entities

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-07 21:25:46 +02:00

69 lines
1.7 KiB
C#

using GermanApp.Domain.Entities;
namespace GermanApp.Application.DTOs;
/// <summary>
/// Data Transfer Object for Lesson - used for API responses.
/// This is a read-only representation of a Lesson entity.
/// </summary>
public record LessonDto(
int Id,
string Title,
string Description,
int LevelId,
string LevelName,
string LevelCode,
int Order,
string Topic,
DateTime CreatedAt,
DateTime? UpdatedAt);
/// <summary>
/// Data Transfer Object for creating a new Lesson.
/// </summary>
public record CreateLessonDto(
string Title,
string Description,
int LevelId,
int Order,
string Topic);
/// <summary>
/// Data Transfer Object for updating an existing Lesson.
/// </summary>
public record UpdateLessonDto(
string Title,
string Description,
int LevelId,
int Order,
string Topic);
/// <summary>
/// Extension methods for mapping between Lesson entity and DTOs.
/// </summary>
public static class LessonDtoExtensions
{
public static LessonDto ToDto(this Lesson lesson) => new(
lesson.Id,
lesson.Title,
lesson.Description,
lesson.LevelId,
lesson.Level?.Name ?? "Unknown",
lesson.Level?.Code ?? "??",
lesson.Order,
lesson.Topic,
lesson.CreatedAt,
lesson.UpdatedAt);
public static Lesson ToEntity(this CreateLessonDto dto) =>
Lesson.Create(dto.LevelId, dto.Title, dto.Order, dto.Topic, dto.Description);
public static void UpdateFromDto(this Lesson lesson, UpdateLessonDto dto)
{
lesson.UpdateTitle(dto.Title);
lesson.UpdateDescription(dto.Description);
lesson.UpdateLevel(dto.LevelId);
lesson.UpdateOrder(dto.Order);
lesson.UpdateTopic(dto.Topic);
}
}