- Add Role property to User entity with migration - Create BootstrapController for first admin user creation - Remove [AllowAnonymous] from all learning content controllers - Create AdminController with admin-only endpoints - Create AdminService for user management - Create UserReportService for progress reports - Add UserRepository implementation - Update AuthService with role support feat(frontend): Implement authentication system - Add AuthStore with React context for auth state management - Create Login, Register, Landing, and Home pages - Add ProtectedRoute and AdminRoute components - Create Auth API types and client - Configure Vite with @/ path alias - Add comprehensive CSS styles for auth and landing pages BREAKING CHANGE: All learning content now requires authentication. Users must register and sign in before accessing lessons, quizzes, and stories. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using GermanApp.Domain.Entities;
|
|
using GermanApp.Domain.Interfaces;
|
|
using GermanApp.Infrastructure.Data.DbContext;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace GermanApp.Infrastructure.Data.Repositories;
|
|
|
|
/// <summary>
|
|
/// Entity Framework Core implementation of IRepository<User, int>.
|
|
/// This is part of the Infrastructure layer.
|
|
/// </summary>
|
|
public class UserRepository : IRepository<User, int>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public UserRepository(AppDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<User?> GetByIdAsync(int id, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _context.Users
|
|
.Include(u => u.StoryProgress)
|
|
.FirstOrDefaultAsync(u => u.Id == id, cancellationToken);
|
|
}
|
|
|
|
public async Task<IReadOnlyList<User>> GetAllAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
return await _context.Users
|
|
.AsNoTracking()
|
|
.ToListAsync(cancellationToken);
|
|
}
|
|
|
|
public async Task<User> AddAsync(User entity, CancellationToken cancellationToken = default)
|
|
{
|
|
await _context.Users.AddAsync(entity, cancellationToken);
|
|
await _context.SaveChangesAsync(cancellationToken);
|
|
return entity;
|
|
}
|
|
|
|
public async Task UpdateAsync(User entity, CancellationToken cancellationToken = default)
|
|
{
|
|
_context.Users.Update(entity);
|
|
await _context.SaveChangesAsync(cancellationToken);
|
|
}
|
|
|
|
public async Task DeleteAsync(User entity, CancellationToken cancellationToken = default)
|
|
{
|
|
_context.Users.Remove(entity);
|
|
await _context.SaveChangesAsync(cancellationToken);
|
|
}
|
|
|
|
public async Task<bool> ExistsAsync(int id, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _context.Users
|
|
.AnyAsync(u => u.Id == id, cancellationToken);
|
|
}
|
|
}
|