DeutschLernen/GermanApp/Domain/Entities/StoryProgress.cs
Lasse Rune Hansen 5a514c5a2d feat(backend/story-integration): Phase 1 - Database & Models
Implement story integration foundation:
- Create Domain/Entities/StorySegment.cs with full CRUD methods
- Create Domain/Entities/StoryProgress.cs for user story progress tracking
- Create Application/DTOs/StorySegmentDto.cs with multiple DTO types
- Create Domain/Interfaces/IStoryRepository.cs
- Create Domain/Interfaces/IStoryProgressRepository.cs
- Create Infrastructure/Data/Repositories/StoryRepository.cs
- Create Infrastructure/Data/Repositories/StoryProgressRepository.cs
- Add DbSets and entity configurations to AppDbContext
- Add navigation properties to Level, Lesson, and User entities

Next: Phase 2 - Backend Services (StoryService, StoryGenerationService)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-13 13:23:12 +02:00

106 lines
2.9 KiB
C#

namespace GermanApp.Domain.Entities;
/// <summary>
/// Tracks a user's progress through story segments.
/// A user unlocks story segments by completing lessons.
/// </summary>
public class StoryProgress
{
public int Id { get; private set; }
/// <summary>
/// The user ID who owns this progress.
/// </summary>
public int UserId { get; private set; }
/// <summary>
/// The level ID this progress is for.
/// </summary>
public int LevelId { get; private set; }
/// <summary>
/// The story segment ID that was unlocked.
/// </summary>
public int StorySegmentId { get; private set; }
/// <summary>
/// Whether the user has read/listened to this segment.
/// </summary>
public bool IsCompleted { get; private set; }
/// <summary>
/// When the segment was unlocked.
/// </summary>
public DateTime UnlockedAt { get; private set; }
/// <summary>
/// When the segment was completed (read/listened to).
/// </summary>
public DateTime? CompletedAt { get; private set; }
/// <summary>
/// Timestamp when the progress record was created.
/// </summary>
public DateTime CreatedAt { get; private set; }
/// <summary>
/// Timestamp when the progress record was last updated.
/// </summary>
public DateTime? UpdatedAt { get; private set; }
// Navigation properties
public virtual User? User { get; private set; }
public virtual Level? Level { get; private set; }
public virtual StorySegment? StorySegment { get; private set; }
/// <summary>
/// Constructor for EF Core deserialization.
/// </summary>
private StoryProgress() { }
/// <summary>
/// Factory method to create a new story progress record.
/// </summary>
/// <param name="userId">The user ID</param>
/// <param name="levelId">The level ID</param>
/// <param name="storySegmentId">The story segment ID</param>
/// <returns>New StoryProgress instance</returns>
public static StoryProgress Create(int userId, int levelId, int storySegmentId)
{
return new StoryProgress
{
UserId = userId,
LevelId = levelId,
StorySegmentId = storySegmentId,
IsCompleted = false,
UnlockedAt = DateTime.UtcNow,
CreatedAt = DateTime.UtcNow
};
}
/// <summary>
/// Marks this story segment as completed (read/listened to).
/// </summary>
public void MarkAsCompleted()
{
if (!IsCompleted)
{
IsCompleted = true;
CompletedAt = DateTime.UtcNow;
UpdatedAt = DateTime.UtcNow;
}
}
/// <summary>
/// Marks this story segment as not completed.
/// </summary>
public void MarkAsIncomplete()
{
if (IsCompleted)
{
IsCompleted = false;
CompletedAt = null;
UpdatedAt = DateTime.UtcNow;
}
}
}