DeutschLernen/GermanApp/Application/DTOs/LessonDto.cs
Lasse Rune Hansen d90e4792d6 Initial commit: GermanApp with Clean Architecture
- Domain layer: Lesson entity, GermanWord value object, repository interfaces
- Application layer: CQRS commands, DTOs with mapping
- Infrastructure layer: EF Core with SQLite, LessonRepository
- Presentation layer: Minimal API endpoints for lessons CRUD

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-05-31 18:14:51 +02:00

60 lines
1.5 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 Level,
string LevelDescription,
DateTime CreatedAt,
DateTime? UpdatedAt);
/// <summary>
/// Data Transfer Object for creating a new Lesson.
/// </summary>
public record CreateLessonDto(
string Title,
string Description,
int Level);
/// <summary>
/// Data Transfer Object for updating an existing Lesson.
/// </summary>
public record UpdateLessonDto(
string Title,
string Description,
int Level);
/// <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.Level,
GetLevelDescription(lesson.Level),
lesson.CreatedAt,
lesson.UpdatedAt);
private static string GetLevelDescription(int level) => level switch
{
1 => "A1 (Beginner)",
2 => "A2 (Elementary)",
3 => "B1 (Intermediate)",
4 => "B2 (Upper Intermediate)",
5 => "C1 (Advanced)",
_ => "Unknown"
};
public static Lesson ToEntity(this CreateLessonDto dto) =>
Lesson.Create(dto.Title, dto.Description, dto.Level);
}