feat: model undergraduate schools terms and exam queries

This commit is contained in:
Codex
2026-10-14 23:14:48 +08:00
parent 3f28e0a1b6
commit 48367b8273
8 changed files with 176 additions and 27 deletions
+8 -1
View File
@@ -11,12 +11,14 @@ class Course {
required this.endPeriod,
required Set<int> weeks,
required this.source,
this.courseCode = '',
this.notes = '',
}) : weeks = Set.unmodifiable(weeks) {
if ([id, name, teacher, room].any((value) => value.trim().isEmpty) ||
weekday < 1 ||
weekday > 7 ||
startPeriod < 1 ||
endPeriod > 11 ||
endPeriod > 12 ||
endPeriod < startPeriod ||
weeks.isEmpty ||
weeks.any((week) => week < 1 || week > 30)) {
@@ -24,6 +26,7 @@ class Course {
}
}
final String id, name, teacher, room;
final String courseCode, notes;
final int weekday, startPeriod, endPeriod;
final Set<int> weeks;
final CourseSource source;
@@ -38,6 +41,8 @@ class Course {
'endPeriod': endPeriod,
'weeks': weeks.toList()..sort(),
'source': source.name,
'courseCode': courseCode,
'notes': notes,
};
static Course fromJson(Map<String, dynamic> json, {CourseSource? source}) {
@@ -62,6 +67,8 @@ class Course {
endPeriod: json['endPeriod'] as int,
weeks: rawWeeks.cast<int>().toSet(),
source: source ?? CourseSource.values.byName(json['source'] as String),
courseCode: (json['courseCode'] ?? '') as String,
notes: (json['notes'] ?? '') as String,
);
} catch (_) {
throw const FormatException('课程字段、节次或周次无效');