Automate overdue homework and show outstanding work in teaching mode
CI / build-and-test (push) Canceled after 0s
CI / build-and-test (push) Canceled after 0s
This commit is contained in:
1 parent
f3e23ad207
commit
4b73d2bea2
10 files changed
+314
-2
No files matched your search
@@ -0,0 +1,33 @@
|
||||
using LehrerApp.Core.Interfaces;
|
||||
using LehrerApp.Core.Models;
|
||||
|
||||
namespace LehrerApp.Desktop.Services;
|
||||
|
||||
/// <summary>Schließt nicht nachgereichte Hausaufgaben 14 Kalendertage nach der Unterrichtsstunde.
|
||||
/// Nur noch offene Nachreichungen werden geändert; andere Stati und archivierte Gruppen bleiben
|
||||
/// unangetastet.</summary>
|
||||
public sealed class HomeworkOverdueService(
|
||||
IGroupRepository groups, IParticipationSessionRepository sessions,
|
||||
IParticipationRepository participation)
|
||||
{
|
||||
public const int GracePeriodDays = 14;
|
||||
|
||||
public int Advance(DateOnly today)
|
||||
{
|
||||
var cutoff = today.AddDays(-GracePeriodDays);
|
||||
var activeGroupIds = groups.GetAll().Where(g => g.IsActive).Select(g => g.Id).ToHashSet();
|
||||
var changed = 0;
|
||||
foreach (var session in sessions.GetAll()
|
||||
.Where(s => s.Date <= cutoff && activeGroupIds.Contains(s.GroupId)))
|
||||
foreach (var entry in participation.GetBySession(session.Id))
|
||||
{
|
||||
if (entry.Homework != HomeworkStatus.MissingOpen &&
|
||||
!(entry.Homework is null && entry.HomeworkMissing)) continue;
|
||||
entry.Homework = HomeworkStatus.MissingOverdue;
|
||||
entry.HomeworkMissing = true;
|
||||
participation.Save(entry);
|
||||
changed++;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user