From 4811519ced07f1a76b8f212c084e8edb51abe18f Mon Sep 17 00:00:00 2001 From: Armand <4831c0@proton.me> Date: Sun, 1 Mar 2026 12:49:59 +0100 Subject: [PATCH] firka_wear: sync API models from firka (Lesson, Grade, Subject, generic) --- firka_wear/lib/helpers/api/model/generic.dart | 34 +++++--- firka_wear/lib/helpers/api/model/grade.dart | 85 +++++++++++++------ firka_wear/lib/helpers/api/model/subject.dart | 40 ++++++--- .../lib/helpers/api/model/timetable.dart | 74 +++++++++++++--- 4 files changed, 168 insertions(+), 65 deletions(-) diff --git a/firka_wear/lib/helpers/api/model/generic.dart b/firka_wear/lib/helpers/api/model/generic.dart index 1e63b74..cb2d276 100644 --- a/firka_wear/lib/helpers/api/model/generic.dart +++ b/firka_wear/lib/helpers/api/model/generic.dart @@ -3,12 +3,22 @@ class NameUidDesc { final String? name; final String? description; - NameUidDesc( - {required this.uid, required this.name, required this.description}); + NameUidDesc({ + required this.uid, + required this.name, + required this.description, + }); factory NameUidDesc.fromJson(Map json) { return NameUidDesc( - uid: json['Uid'], name: json['Nev'], description: json['Leiras']); + uid: json['Uid'], + name: json['Nev'], + description: json['Leiras'], + ); + } + + Map toJson() { + return {'Uid': uid, 'Nev': name, 'Leiras': description}; } @override @@ -25,16 +35,14 @@ class NameUid { final String uid; final String name; - NameUid({ - required this.uid, - required this.name, - }); + NameUid({required this.uid, required this.name}); factory NameUid.fromJson(Map json) { - return NameUid( - uid: json['Uid'], - name: json['Nev'], - ); + return NameUid(uid: json['Uid'], name: json['Nev']); + } + + Map toJson() { + return {'Uid': uid, 'Nev': name}; } } @@ -44,9 +52,7 @@ class UidObj { UidObj({required this.uid}); factory UidObj.fromJson(Map json) { - return UidObj( - uid: json['Uid'], - ); + return UidObj(uid: json['Uid']); } @override diff --git a/firka_wear/lib/helpers/api/model/grade.dart b/firka_wear/lib/helpers/api/model/grade.dart index 1611a01..0b0d5c3 100644 --- a/firka_wear/lib/helpers/api/model/grade.dart +++ b/firka_wear/lib/helpers/api/model/grade.dart @@ -20,38 +20,47 @@ class Grade { final UidObj? classGroup; final int sortIndex; - Grade( - {required this.uid, - required this.recordDate, - required this.creationDate, - this.ackDate, - required this.subject, - this.topic, - required this.type, - this.mode, - required this.valueType, - required this.teacher, - this.kind, - this.numericValue, - required this.strValue, - this.weightPercentage, - this.shortStrValue, - this.classGroup, - required this.sortIndex}); + Grade({ + required this.uid, + required this.recordDate, + required this.creationDate, + this.ackDate, + required this.subject, + this.topic, + required this.type, + this.mode, + required this.valueType, + required this.teacher, + this.kind, + this.numericValue, + required this.strValue, + this.weightPercentage, + this.shortStrValue, + this.classGroup, + required this.sortIndex, + }); factory Grade.fromJson(Map json) { return Grade( uid: json['Uid'], - recordDate: DateTime.parse(json['RogzitesDatuma']), - creationDate: DateTime.parse(json['KeszitesDatuma']), + recordDate: DateTime.parse(json['RogzitesDatuma']).toLocal(), + creationDate: DateTime.parse(json['KeszitesDatuma']).toLocal(), ackDate: json['LattamozasDatuma'] != null - ? DateTime.parse(json['LattamozasDatuma']) + ? DateTime.parse(json['LattamozasDatuma']).toLocal() : null, - subject: Subject.fromJson(json['Tantargy']), + subject: Subject.fromJson( + Map.from(json['Tantargy'] as Map), + ), topic: json['Tema'], - type: NameUidDesc.fromJson(json['Tipus']), - mode: json['Mod'] != null ? NameUidDesc.fromJson(json['Mod']) : null, - valueType: NameUidDesc.fromJson(json['ErtekFajta']), + type: NameUidDesc.fromJson( + Map.from(json['Tipus'] as Map), + ), + mode: json['Mod'] != null + ? NameUidDesc.fromJson(Map.from(json['Mod'] as Map)) + : null, + valueType: NameUidDesc.fromJson( + Map.from(json['ErtekFajta'] as Map), + ), teacher: json['ErtekeloTanarNeve'], kind: json['Kind'], numericValue: json['SzamErtek'], @@ -59,12 +68,36 @@ class Grade { weightPercentage: json['SulySzazalekErteke'], shortStrValue: json['SzovegesErtekelesRovidNev'], classGroup: json['OsztalyCsoport'] != null - ? UidObj.fromJson(json['OsztalyCsoport']) + ? UidObj.fromJson( + Map.from(json['OsztalyCsoport'] as Map), + ) : null, sortIndex: json['SortIndex'], ); } + Map toJson() { + return { + 'Uid': uid, + 'RogzitesDatuma': recordDate.toUtc().toIso8601String(), + 'KeszitesDatuma': creationDate.toUtc().toIso8601String(), + 'LattamozasDatuma': ackDate?.toUtc().toIso8601String(), + 'Tantargy': subject.toJson(), + 'Tema': topic, + 'Tipus': type.toJson(), + 'Mod': mode?.toJson(), + 'ErtekFajta': valueType.toJson(), + 'ErtekeloTanarNeve': teacher, + 'Kind': kind, + 'SzamErtek': numericValue, + 'SzovegesErtek': strValue, + 'SulySzazalekErteke': weightPercentage, + 'SzovegesErtekelesRovidNev': shortStrValue, + 'OsztalyCsoport': classGroup != null ? {'Uid': classGroup!.uid} : null, + 'SortIndex': sortIndex, + }; + } + @override String toString() { return 'Grade(' diff --git a/firka_wear/lib/helpers/api/model/subject.dart b/firka_wear/lib/helpers/api/model/subject.dart index 6204fa0..0bf02a0 100644 --- a/firka_wear/lib/helpers/api/model/subject.dart +++ b/firka_wear/lib/helpers/api/model/subject.dart @@ -1,23 +1,40 @@ -import 'generic.dart'; +import 'package:firka_wear/helpers/api/model/generic.dart'; class Subject { final String uid; final String name; final NameUidDesc category; final int sortIndex; + final String? teacherName; - Subject( - {required this.uid, - required this.name, - required this.category, - required this.sortIndex}); + Subject({ + required this.uid, + required this.name, + required this.category, + required this.sortIndex, + this.teacherName, + }); factory Subject.fromJson(Map json) { return Subject( - uid: json['Uid'], - name: json['Nev'], - category: NameUidDesc.fromJson(json['Kategoria']), - sortIndex: json['SortIndex']); + uid: json['Uid'], + name: json['Nev'], + category: NameUidDesc.fromJson( + Map.from(json['Kategoria'] as Map), + ), + sortIndex: json['SortIndex'], + teacherName: json['alkalmazottNev'], + ); + } + + Map toJson() { + return { + 'Uid': uid, + 'Nev': name, + 'Kategoria': category.toJson(), + 'SortIndex': sortIndex, + 'alkalmazottNev': teacherName, + }; } @override @@ -26,7 +43,8 @@ class Subject { 'uid: "$uid", ' 'name: "$name", ' 'category: $category, ' - 'sortIndex: $sortIndex' + 'sortIndex: $sortIndex, ' + 'teacherName: $teacherName' ')'; } } diff --git a/firka_wear/lib/helpers/api/model/timetable.dart b/firka_wear/lib/helpers/api/model/timetable.dart index 154b1ba..04b43fa 100644 --- a/firka_wear/lib/helpers/api/model/timetable.dart +++ b/firka_wear/lib/helpers/api/model/timetable.dart @@ -66,32 +66,43 @@ class Lesson { factory Lesson.fromJson(Map json) { var attachments = List.empty(growable: true); - var rawAttachments = json['Csatolmanyok']; + var rawAttachments = json['Csatolmanyok'] as List? ?? []; for (var attachment in rawAttachments) { - attachments.add(NameUid.fromJson(attachment)); + attachments.add( + NameUid.fromJson(Map.from(attachment as Map)), + ); } return Lesson( uid: json['Uid'], date: json['Datum'], - start: DateTime.parse(json['KezdetIdopont']), - end: DateTime.parse(json['VegIdopont']), + start: DateTime.parse(json['KezdetIdopont']).toLocal(), + end: DateTime.parse(json['VegIdopont']).toLocal(), name: json['Nev'], lessonNumber: json['Oraszam'], lessonSeqNumber: json['OraEvesSorszama'], classGroup: json['OsztalyCsoport'] != null - ? NameUid.fromJson(json['OsztalyCsoport']) + ? NameUid.fromJson( + Map.from(json['OsztalyCsoport'] as Map), + ) : null, teacher: json['TanarNeve'], - subject: - json['Tantargy'] != null ? Subject.fromJson(json['Tantargy']) : null, + subject: json['Tantargy'] != null + ? Subject.fromJson(Map.from(json['Tantargy'] as Map)) + : null, theme: json['Tema'], roomName: json['TeremNeve'], - type: NameUidDesc.fromJson(json['Tipus']), + type: NameUidDesc.fromJson( + Map.from(json['Tipus'] as Map), + ), studentPresence: json['TanuloJelenlet'] != null - ? NameUidDesc.fromJson(json['TanuloJelenlet']) + ? NameUidDesc.fromJson( + Map.from(json['TanuloJelenlet'] as Map), + ) : null, - state: NameUidDesc.fromJson(json['Allapot']), + state: NameUidDesc.fromJson( + Map.from(json['Allapot'] as Map), + ), substituteTeacher: json['HelyettesTanarNeve'], homeworkUid: json['HaziFeladatUid'], taskGroupUid: json['FeladatGroupUid'], @@ -105,13 +116,48 @@ class Lesson { digitalPlatformType: json['DigitalisPlatformTipus'], digitalSupportDeviceTypeList: json['DigitalisTamogatoEszkozTipusList'] != null - ? List.from(json['DigitalisTamogatoEszkozTipusList']) - : List.empty(), - createdAt: DateTime.parse(json['Letrehozas']), - lastModifiedAt: DateTime.parse(json['UtolsoModositas']), + ? List.from(json['DigitalisTamogatoEszkozTipusList']) + : List.empty(), + createdAt: DateTime.parse(json['Letrehozas']).toLocal(), + lastModifiedAt: DateTime.parse(json['UtolsoModositas']).toLocal(), ); } + Map toJson() { + final rawAttachments = attachments.map((e) => e.toJson()).toList(); + return { + 'Uid': uid, + 'Datum': date, + 'KezdetIdopont': start.toIso8601String(), + 'VegIdopont': end.toIso8601String(), + 'Nev': name, + 'Oraszam': lessonNumber, + 'OraEvesSorszama': lessonSeqNumber, + 'OsztalyCsoport': classGroup?.toJson(), + 'TanarNeve': teacher, + 'Tantargy': subject?.toJson(), + 'Tema': theme, + 'TeremNeve': roomName, + 'Tipus': type.toJson(), + 'TanuloJelenlet': studentPresence?.toJson(), + 'Allapot': state.toJson(), + 'HelyettesTanarNeve': substituteTeacher, + 'HaziFeladatUid': homeworkUid, + 'FeladatGroupUid': taskGroupUid, + 'NyelviFeladatGroupUid': languageTaskGroupUid, + 'BejelentettSzamonkeresUid': assessmentUid, + 'IsTanuloHaziFeladatEnabled': canStudentEditHomework, + 'IsHaziFeladatMegoldva': isHomeworkComplete, + 'Csatolmanyok': rawAttachments, + 'IsDigitalisOra': isDigitalLesson, + 'DigitalisEszkozTipus': digitalDeviceList, + 'DigitalisPlatformTipus': digitalPlatformType, + 'DigitalisTamogatoEszkozTipusList': digitalSupportDeviceTypeList, + 'Letrehozas': createdAt.toIso8601String(), + 'UtolsoModositas': lastModifiedAt.toIso8601String(), + }; + } + @override String toString() { return 'Lesson('