DeutschLernen/GermanApp/Domain/Entities/Lesson.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

110 lines
3 KiB
C#

namespace GermanApp.Domain.Entities;
/// <summary>
/// Represents a lesson in the DeutschLernen system.
/// Lessons are organized within CEFR levels and must be completed in order.
/// </summary>
public class Lesson
{
public int Id { get; private set; }
public int LevelId { get; private set; }
public string Title { get; private set; } = string.Empty;
public int Order { get; private set; }
public string Topic { get; private set; } = string.Empty;
public string Description { get; private set; } = string.Empty;
public bool IsActive { get; private set; } = true;
public DateTime CreatedAt { get; private set; }
public DateTime? UpdatedAt { get; private set; }
// Navigation property (EF Core will handle this)
public virtual Level? Level { get; private set; }
/// <summary>
/// Constructor for EF Core deserialization.
/// </summary>
private Lesson() { }
/// <summary>
/// Factory method to create a new lesson.
/// </summary>
/// <param name="levelId">ID of the parent level</param>
/// <param name="title">Title of the lesson</param>
/// <param name="order">Sort order within the level</param>
/// <param name="topic">Main topic covered in the lesson</param>
/// <param name="description">Description of what the lesson covers</param>
public static Lesson Create(int levelId, string title, int order, string topic, string description = "")
{
return new Lesson
{
LevelId = levelId,
Title = title,
Order = order,
Topic = topic,
Description = description,
CreatedAt = DateTime.UtcNow
};
}
/// <summary>
/// Updates the lesson's title.
/// </summary>
public void UpdateTitle(string newTitle)
{
Title = newTitle;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// Updates the lesson's topic.
/// </summary>
public void UpdateTopic(string newTopic)
{
Topic = newTopic;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// Updates the lesson's description.
/// </summary>
public void UpdateDescription(string newDescription)
{
Description = newDescription;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// Updates the lesson's sort order.
/// </summary>
public void UpdateOrder(int newOrder)
{
Order = newOrder;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// Updates the lesson's level.
/// </summary>
public void UpdateLevel(int newLevelId)
{
LevelId = newLevelId;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// Activates the lesson.
/// </summary>
public void Activate()
{
IsActive = true;
UpdatedAt = DateTime.UtcNow;
}
/// <summary>
/// Deactivates the lesson.
/// </summary>
public void Deactivate()
{
IsActive = false;
UpdatedAt = DateTime.UtcNow;
}
}