- 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>
63 lines
2 KiB
C#
63 lines
2 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 Lesson entities.
|
|
/// </summary>
|
|
public interface ILessonRepository : IRepository<Lesson, int>
|
|
{
|
|
/// <summary>
|
|
/// Gets lessons by level.
|
|
/// </summary>
|
|
Task<IReadOnlyList<Lesson>> GetByLevelAsync(int level, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Gets beginner-level lessons.
|
|
/// </summary>
|
|
Task<IReadOnlyList<Lesson>> GetBeginnerLessonsAsync(CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Gets advanced-level lessons.
|
|
/// </summary>
|
|
Task<IReadOnlyList<Lesson>> GetAdvancedLessonsAsync(CancellationToken cancellationToken = default);
|
|
}
|