DeutschLernen/GermanApp/Domain/Interfaces/IRepository.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

135 lines
4.8 KiB
C#

using GermanApp.Domain.Entities;
namespace GermanApp.Domain.Interfaces;
/// <summary>
/// Generic repository interface for domain entities.
/// All repositories should implement this interface.
/// </summary>
/// <typeparam name="TEntity">The entity type</typeparam>
/// <typeparam name="TId">The identifier type (usually int or Guid)</typeparam>
public interface IRepository<TEntity, TId> where TEntity : class
{
/// <summary>
/// Gets an entity by its identifier.
/// </summary>
Task<TEntity?> GetByIdAsync(TId id, CancellationToken cancellationToken = default);
/// <summary>
/// Gets all entities.
/// </summary>
Task<IReadOnlyList<TEntity>> GetAllAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Adds a new entity.
/// </summary>
Task<TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing entity.
/// </summary>
Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
/// <summary>
/// Deletes an entity.
/// </summary>
Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default);
/// <summary>
/// Checks if an entity with the given identifier exists.
/// </summary>
Task<bool> ExistsAsync(TId id, CancellationToken cancellationToken = default);
}
/// <summary>
/// Repository interface for Level entities.
/// </summary>
public interface ILevelRepository : IRepository<Level, int>
{
/// <summary>
/// Gets a level by its code (e.g., "A1", "B2").
/// </summary>
Task<Level?> GetByCodeAsync(string code, CancellationToken cancellationToken = default);
/// <summary>
/// Gets all levels ordered by their sort order.
/// </summary>
Task<IReadOnlyList<Level>> GetAllOrderedAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Gets the first level (lowest order number).
/// </summary>
Task<Level?> GetFirstLevelAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Gets the next level after the specified one.
/// </summary>
Task<Level?> GetNextLevelAsync(int currentLevelId, CancellationToken cancellationToken = default);
}
/// <summary>
/// Repository interface for Lesson entities.
/// </summary>
public interface ILessonRepository : IRepository<Lesson, int>
{
/// <summary>
/// Gets lessons by level.
/// </summary>
Task<IReadOnlyList<Lesson>> GetByLevelAsync(int levelId, CancellationToken cancellationToken = default);
/// <summary>
/// Gets all lessons ordered by level and lesson order.
/// </summary>
Task<IReadOnlyList<Lesson>> GetAllOrderedAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Gets the first lesson in a level.
/// </summary>
Task<Lesson?> GetFirstLessonInLevelAsync(int levelId, CancellationToken cancellationToken = default);
/// <summary>
/// Gets the next lesson after the specified one (in the same level).
/// </summary>
Task<Lesson?> GetNextLessonAsync(int currentLessonId, CancellationToken cancellationToken = default);
/// <summary>
/// Gets lessons that the user can access (completed previous lessons or first in level).
/// </summary>
Task<IReadOnlyList<Lesson>> GetAccessibleLessonsAsync(int userId, CancellationToken cancellationToken = default);
}
/// <summary>
/// Repository interface for UserProgress entities.
/// </summary>
public interface IUserProgressRepository : IRepository<UserProgress, int>
{
/// <summary>
/// Gets user progress for a specific user and lesson.
/// </summary>
Task<UserProgress?> GetByUserAndLessonAsync(int userId, int lessonId, CancellationToken cancellationToken = default);
/// <summary>
/// Gets all progress records for a user.
/// </summary>
Task<IReadOnlyList<UserProgress>> GetByUserAsync(int userId, CancellationToken cancellationToken = default);
/// <summary>
/// Gets progress for all lessons in a specific level for a user.
/// </summary>
Task<IReadOnlyList<UserProgress>> GetByUserAndLevelAsync(int userId, int levelId, CancellationToken cancellationToken = default);
/// <summary>
/// Checks if a user has completed a lesson (with 80% or higher score).
/// </summary>
Task<bool> HasUserCompletedLessonAsync(int userId, int lessonId, CancellationToken cancellationToken = default);
/// <summary>
/// Gets the user's average score for a level.
/// </summary>
Task<double> GetAverageScoreForLevelAsync(int userId, int levelId, CancellationToken cancellationToken = default);
/// <summary>
/// Gets the percentage of lessons completed in a level.
/// </summary>
Task<double> GetLevelCompletionPercentageAsync(int userId, int levelId, CancellationToken cancellationToken = default);
}