diff --git a/firka/lib/helpers/api/client/kreta_client.dart b/firka/lib/helpers/api/client/kreta_client.dart index f4853f53..7008e3bb 100644 --- a/firka/lib/helpers/api/client/kreta_client.dart +++ b/firka/lib/helpers/api/client/kreta_client.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:math'; import 'package:dio/dio.dart'; +import 'package:firka/helpers/api/model/class_group.dart'; import 'package:firka/helpers/api/model/homework.dart'; import 'package:firka/helpers/api/model/timetable.dart'; import 'package:firka/helpers/db/models/generic_cache_model.dart'; @@ -186,6 +187,34 @@ class KretaClient { return ApiResponse(student, status, err, cached); } + ApiResponse>? classGroupCache; + + Future>> getClassGroups( + {bool forceCache = true}) async { + if (forceCache && classGroupCache != null) return classGroupCache!; + var (resp, status, ex, cached) = await _cachingGet(CacheId.getClassGroup, + KretaEndpoints.getClassGroups(model.iss!), forceCache, 0); + + final classGroups = List.empty(growable: true); + String? err; + try { + List rawItems = resp; + for (var item in rawItems) { + classGroups.add(ClassGroup.fromJson(item)); + } + } catch (ex) { + err = ex.toString(); + } + + if (ex != null) { + err = ex.toString(); + } + + if (ex == null) classGroupCache = ApiResponse(classGroups, 200, null, true); + + return ApiResponse(classGroups, status, err, cached); + } + ApiResponse>? noticeBoardCache; Future>> getNoticeBoard( diff --git a/firka/lib/helpers/api/consts.dart b/firka/lib/helpers/api/consts.dart index 787ac5eb..385c9143 100644 --- a/firka/lib/helpers/api/consts.dart +++ b/firka/lib/helpers/api/consts.dart @@ -64,6 +64,9 @@ class KretaEndpoints { static String getStudentUrl(String iss) => "${kreta(iss)}/ellenorzo/v3/sajat/TanuloAdatlap"; + static String getClassGroups(String iss) => + "${kreta(iss)}/ellenorzo/v3/sajat/OsztalyCsoportok"; + static String getNoticeBoard(String iss) => "${kreta(iss)}/ellenorzo/v3/sajat/FaliujsagElemek"; diff --git a/firka/lib/helpers/api/model/class_group.dart b/firka/lib/helpers/api/model/class_group.dart new file mode 100644 index 00000000..b7384a1d --- /dev/null +++ b/firka/lib/helpers/api/model/class_group.dart @@ -0,0 +1,52 @@ +import 'package:firka/helpers/api/model/generic.dart'; + +class ClassGroup { + final String uid; + final String name; + final UidObj? headTeacher; + final UidObj? substituteHeadTeacher; + final NameUidDesc studyGroup; + final int? studyGroupSortIndex; + final bool isActive; + final String type; + + ClassGroup( + {required this.uid, + required this.name, + required this.headTeacher, + required this.substituteHeadTeacher, + required this.studyGroup, + required this.studyGroupSortIndex, + required this.isActive, + required this.type}); + + factory ClassGroup.fromJson(Map json) { + return ClassGroup( + uid: json['Uid'], + name: json['Nev'], + headTeacher: json['OsztalyFonok'] != null + ? UidObj.fromJson(json['OsztalyFonok']) + : null, + substituteHeadTeacher: json['OsztalyFonokHelyettes'] != null + ? UidObj.fromJson(json['OsztalyFonokHelyettes']) + : null, + studyGroup: NameUidDesc.fromJson(json['OktatasNevelesiKategoria']), + studyGroupSortIndex: json['OktatasNevelesiKategoriaSortIndex'], + isActive: json['IsAktiv'], + type: json['Tipus']); + } + + @override + String toString() { + return 'ClassGroup(' + 'uid: "$uid", ' + 'name: "$name", ' + 'headTeacher: $headTeacher, ' + 'substituteHeadTeacher: $substituteHeadTeacher, ' + 'studyGroup: $studyGroup, ' + 'studyGroupSortIndex: $studyGroupSortIndex, ' + 'isActive: $isActive, ' + 'type: "$type"' + ')'; + } +} diff --git a/firka/lib/helpers/db/models/generic_cache_model.dart b/firka/lib/helpers/db/models/generic_cache_model.dart index 000755d5..c699afc5 100644 --- a/firka/lib/helpers/db/models/generic_cache_model.dart +++ b/firka/lib/helpers/db/models/generic_cache_model.dart @@ -8,7 +8,8 @@ enum CacheId { getInfoBoard, getGrades, getOmissions, - getTests + getTests, + getClassGroup } @collection