forked from firka/firka
kreta_client: add class groups
This commit is contained in:
@@ -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<List<ClassGroup>>? classGroupCache;
|
||||
|
||||
Future<ApiResponse<List<ClassGroup>>> 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<ClassGroup>.empty(growable: true);
|
||||
String? err;
|
||||
try {
|
||||
List<dynamic> 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<List<NoticeBoardItem>>? noticeBoardCache;
|
||||
|
||||
Future<ApiResponse<List<NoticeBoardItem>>> getNoticeBoard(
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
52
firka/lib/helpers/api/model/class_group.dart
Normal file
52
firka/lib/helpers/api/model/class_group.dart
Normal file
@@ -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<String, dynamic> 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"'
|
||||
')';
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ enum CacheId {
|
||||
getInfoBoard,
|
||||
getGrades,
|
||||
getOmissions,
|
||||
getTests
|
||||
getTests,
|
||||
getClassGroup
|
||||
}
|
||||
|
||||
@collection
|
||||
|
||||
Reference in New Issue
Block a user