refreshCourseOffering method
- int id
Fetches a course offering's syllabus from the network and writes it to the CourseOfferings row.
The watchCourseOffering stream automatically emits the updated value.
Network errors propagate to the caller. No-ops when the offering is
missing or has no syllabusId / number.
Implementation
Future<void> refreshCourseOffering(int id) async {
final raw = await (_database.select(
_database.courseOfferings,
)..where((o) => o.id.equals(id))).getSingleOrNull();
if (raw == null) return;
if (raw.syllabusId == null || raw.number == null) return;
final syllabus = await _authRepository.withAuth(
() => _courseService.getSyllabus(
courseNumber: raw.number!,
syllabusId: raw.syllabusId!,
),
sso: [.courseService],
);
await (_database.update(
_database.courseOfferings,
)..where((o) => o.id.equals(id))).write(
CourseOfferingsCompanion(
courseType: Value(syllabus.type),
enrolled: Value(syllabus.enrolled),
withdrawn: Value(syllabus.withdrawn),
syllabusUpdatedAt: Value(syllabus.lastUpdated),
objective: Value(syllabus.objective),
weeklyPlan: Value(syllabus.weeklyPlan),
evaluation: Value(syllabus.evaluation),
textbooks: Value(syllabus.materials),
syllabusRemarks: Value(syllabus.remarks),
fetchedAt: Value(DateTime.now()),
),
);
}