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

81 lines
2.1 KiB
C#

namespace GermanApp.Domain.Entities;
/// <summary>
/// Represents a user in the DeutschLernen system.
/// </summary>
public class User
{
public int Id { get; private set; }
public string Username { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty;
public string PasswordHash { get; private set; } = string.Empty;
public string CurrentLevel { get; private set; } = "A1";
public int Streak { get; private set; }
public int TotalPoints { get; private set; }
public DateTime CreatedAt { get; private set; }
/// <summary>
/// Constructor for EF Core deserialization.
/// </summary>
private User() { }
/// <summary>
/// Factory method to create a new user.
/// </summary>
public static User Create(string username, string email, string passwordHash)
{
return new User
{
Username = username,
Email = email.ToLowerInvariant(),
PasswordHash = passwordHash,
CurrentLevel = "A1",
Streak = 0,
TotalPoints = 0,
CreatedAt = DateTime.UtcNow
};
}
/// <summary>
/// Updates user's gamification stats.
/// </summary>
public void AddPoints(int points)
{
TotalPoints += points;
}
/// <summary>
/// Updates user's streak.
/// </summary>
public void UpdateStreak(int streak)
{
Streak = streak;
}
/// <summary>
/// Updates user's current level.
/// </summary>
public void UpdateLevel(string level)
{
CurrentLevel = level;
}
/// <summary>
/// Changes user's email.
/// </summary>
public void ChangeEmail(string newEmail)
{
Email = newEmail?.ToLowerInvariant() ?? string.Empty;
}
/// <summary>
/// Changes user's password hash.
/// </summary>
public void ChangePassword(string newPasswordHash)
{
PasswordHash = newPasswordHash;
}
// Navigation properties
public virtual ICollection<StoryProgress> StoryProgress { get; private set; } = new List<StoryProgress>();
}