Skip to content

Commit

Permalink
fix: exams not showing up (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes authored Sep 30, 2023
2 parents 873446e + 3fa3de1 commit d3f2dcb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import 'package:uni/model/entities/session.dart';
class AllCourseUnitsFetcher {
Future<List<CourseUnit>?> getAllCourseUnitsAndCourseAverages(
List<Course> courses,
Session session,
) async {
Session session, {
List<CourseUnit>? currentCourseUnits,
}) async {
final allCourseUnits = <CourseUnit>[];

for (final course in courses) {
try {
final courseUnits = await _getAllCourseUnitsAndCourseAveragesFromCourse(
course,
session,
currentCourseUnits: currentCourseUnits,
);
allCourseUnits.addAll(courseUnits.where((c) => c.enrollmentIsValid()));
} catch (e) {
Expand All @@ -30,8 +32,9 @@ class AllCourseUnitsFetcher {

Future<List<CourseUnit>> _getAllCourseUnitsAndCourseAveragesFromCourse(
Course course,
Session session,
) async {
Session session, {
List<CourseUnit>? currentCourseUnits,
}) async {
final url = '${NetworkRouter.getBaseUrl(course.faculty!)}'
'fest_geral.curso_percurso_academico_view';
final response = await NetworkRouter.getWithCookies(
Expand All @@ -41,6 +44,10 @@ class AllCourseUnitsFetcher {
},
session,
);
return parseCourseUnitsAndCourseAverage(response, course);
return parseCourseUnitsAndCourseAverage(
response,
course,
currentCourseUnits: currentCourseUnits,
);
}
}
13 changes: 10 additions & 3 deletions uni/lib/controller/parsers/parser_course_units.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:html/parser.dart';
import 'package:http/http.dart' as http;
import 'package:uni/model/entities/course.dart';
Expand All @@ -6,8 +7,9 @@ import 'package:uni/utils/url_parser.dart';

List<CourseUnit> parseCourseUnitsAndCourseAverage(
http.Response response,
Course course,
) {
Course course, {
List<CourseUnit>? currentCourseUnits,
}) {
final document = parse(response.body);
final table = document.getElementById('tabelapercurso');
if (table == null) {
Expand Down Expand Up @@ -68,11 +70,16 @@ List<CourseUnit> parseCourseUnitsAndCourseAverage(
continue;
}

final matchingCurrentCourseUnit = currentCourseUnits
?.firstWhereOrNull((element) => element.code == codeName);

final courseUnit = CourseUnit(
schoolYear:
'${firstSchoolYear + yearIncrement}/${firstSchoolYear + yearIncrement + 1}',
occurrId: int.parse(occurId),
abbreviation: codeName,
code: codeName,
abbreviation: matchingCurrentCourseUnit?.abbreviation ??
codeName, // FIXME: this is not the abbreviation
status: status,
grade: grade,
ects: double.parse(ects),
Expand Down
2 changes: 1 addition & 1 deletion uni/lib/model/providers/lazy/exam_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ExamProvider extends StateProviderNotifier {
}

Future<void> setFilteredExams(Map<String, bool> newFilteredExams) async {
unawaited(AppSharedPreferences.saveFilteredExams(filteredExamsTypes));
unawaited(AppSharedPreferences.saveFilteredExams(newFilteredExams));
_filteredExamsTypes = Map<String, bool>.from(newFilteredExams);
notifyListeners();
}
Expand Down
8 changes: 6 additions & 2 deletions uni/lib/model/providers/startup/profile_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ class ProfileProvider extends StateProviderNotifier {

Future<void> fetchCourseUnitsAndCourseAverages(Session session) async {
final courses = profile.courses;
final allCourseUnits = await AllCourseUnitsFetcher()
.getAllCourseUnitsAndCourseAverages(profile.courses, session);
final allCourseUnits =
await AllCourseUnitsFetcher().getAllCourseUnitsAndCourseAverages(
profile.courses,
session,
currentCourseUnits: profile.courseUnits,
);

if (allCourseUnits != null) {
_profile.courseUnits = allCourseUnits;
Expand Down
6 changes: 4 additions & 2 deletions uni/lib/view/home/widgets/exam_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ class ExamCard extends GenericCard {
children: [
if (locale == AppLocale.pt) ...[
DateRectangle(
date: '${exam.weekDay}, ${exam.begin.day} de ${exam.month}',
date: '''${exam.weekDay(locale)}, '''
'''${exam.begin.day} de ${exam.month(locale)}''',
)
] else ...[
DateRectangle(
date: '${exam.weekDay}, ${exam.begin.day} ${exam.month}',
date: '''${exam.weekDay(locale)}, '''
'''${exam.begin.day} ${exam.month(locale)}''',
)
],
RowContainer(
Expand Down

0 comments on commit d3f2dcb

Please sign in to comment.