Add animated classroom grouping with saved editable plans
CI / build-and-test (push) Canceled after 0s

This commit is contained in:
admin committed 2026-09-29 22:17:49 +02:00
1 parent d4b1419f9a
commit f0462bd2a1
27 files changed
+775 -46

No files matched your search

+4
View File
@@ -41,6 +41,7 @@ public class LiteDbContext : IDisposable
public ILiteCollection<Student> Students => _db.GetCollection<Student>("students");
public ILiteCollection<LearningGroup> Groups => _db.GetCollection<LearningGroup>("groups");
public ILiteCollection<SeatingPlan> SeatingPlans => _db.GetCollection<SeatingPlan>("seating_plans");
public ILiteCollection<StudentGroupPlan> StudentGroupPlans => _db.GetCollection<StudentGroupPlan>("student_group_plans");
public ILiteCollection<GroupMembership> Memberships => _db.GetCollection<GroupMembership>("group_memberships");
public ILiteCollection<Exam> Exams => _db.GetCollection<Exam>("exams");
public ILiteCollection<ExamResult> ExamResults => _db.GetCollection<ExamResult>("exam_results");
@@ -141,6 +142,8 @@ public class LiteDbContext : IDisposable
foreach (var plan in SeatingPlans.Find(p => p.GroupId == id).ToList())
SeatingPlans.Delete(plan.Id);
foreach (var plan in StudentGroupPlans.Find(p => p.GroupId == id).ToList())
StudentGroupPlans.Delete(plan.Id);
// Dokumentation und Arbeitszeit sind historische Nachweise. Sie bleiben erhalten,
// werden aber von der nicht mehr existierenden Lerngruppe entkoppelt.
@@ -659,6 +662,7 @@ public class LiteDbContext : IDisposable
Groups.EnsureIndex(x => x.SchoolYear);
Groups.EnsureIndex(x => x.IsActive);
SeatingPlans.EnsureIndex(x => x.GroupId);
StudentGroupPlans.EnsureIndex(x => x.GroupId);
Memberships.EnsureIndex(x => x.StudentId);
Memberships.EnsureIndex(x => x.GroupId);
Memberships.EnsureIndex("ux_student_group",
@@ -34,7 +34,9 @@ public class StudentRepository(LiteDbContext db) : IStudentRepository
db.Grades.Count(g => g.StudentId == studentId),
db.ReportGrades.Count(g => g.StudentId == studentId),
db.ParticipationEntries.Count(e => e.StudentId == studentId),
db.Documentation.FindAll().Count(d => d.Concerns(studentId)));
db.Documentation.FindAll().Count(d => d.Concerns(studentId)),
db.StudentGroupPlans.FindAll().Count(plan =>
plan.Groups.Any(group => group.StudentIds.Contains(studentId))));
public void Save(Student s)
{
s.ExternalIds ??= [];
@@ -0,0 +1,55 @@
using LehrerApp.Core.Interfaces;
using LehrerApp.Core.Models;
namespace LehrerApp.Data.Repositories;
public class StudentGroupPlanRepository(LiteDbContext db) : IStudentGroupPlanRepository
{
public StudentGroupPlan? GetById(Guid id) => db.StudentGroupPlans.FindById(id);
public List<StudentGroupPlan> GetByGroup(Guid groupId) =>
db.StudentGroupPlans.Find(p => p.GroupId == groupId)
.OrderByDescending(p => p.UpdatedAt).ToList();
public List<StudentGroupPlan> GetByStudent(Guid studentId) =>
db.StudentGroupPlans.FindAll()
.Where(plan => plan.Groups.Any(group => group.StudentIds.Contains(studentId)))
.OrderByDescending(plan => plan.UpdatedAt).ToList();
public void Save(StudentGroupPlan plan)
{
if (db.Groups.FindById(plan.GroupId) is null)
throw new InvalidOperationException("Die zugehörige Lerngruppe existiert nicht.");
ArchivedGroupWriteGuard.EnsureActive(db, plan.GroupId);
plan.Name = plan.Name?.Trim() ?? "";
if (plan.Name.Length == 0)
throw new ArgumentException("Bitte einen Namen für die Gruppeneinteilung eingeben.");
plan.Groups ??= [];
if (plan.Groups.Count == 0)
throw new InvalidOperationException("Die Gruppeneinteilung enthält keine Gruppen.");
var ids = plan.Groups.SelectMany(g => g.StudentIds ?? []).ToList();
if (ids.Count != ids.Distinct().Count())
throw new InvalidOperationException("Ein Schüler darf nur in einer Gruppe stehen.");
if (db.StudentGroupPlans.Find(p => p.GroupId == plan.GroupId)
.Any(p => p.Id != plan.Id && string.Equals(p.Name, plan.Name, StringComparison.OrdinalIgnoreCase)))
throw new InvalidOperationException("Eine gespeicherte Einteilung mit diesem Namen gibt es bereits.");
if (db.StudentGroupPlans.FindById(plan.Id) is { } existing)
{
if (existing.GroupId != plan.GroupId)
throw new InvalidOperationException("Eine Gruppeneinteilung kann nicht in eine andere Lerngruppe verschoben werden.");
plan.CreatedAt = existing.CreatedAt;
}
plan.UpdatedAt = DateTime.UtcNow;
db.StudentGroupPlans.Upsert(plan);
db.OnChange?.Invoke(nameof(StudentGroupPlan), plan.Id.ToString(), "Save", plan);
}
public void Delete(Guid id)
{
if (db.StudentGroupPlans.FindById(id) is not { } plan) return;
ArchivedGroupWriteGuard.EnsureActive(db, plan.GroupId);
db.StudentGroupPlans.Delete(id);
db.OnChange?.Invoke(nameof(StudentGroupPlan), id.ToString(), "Delete", null);
}
}