diff --git a/app/lib/calendrical_events/models/calendrical_event.dart b/app/lib/calendrical_events/models/calendrical_event.dart index 8f9cc1eda..8f3143d08 100644 --- a/app/lib/calendrical_events/models/calendrical_event.dart +++ b/app/lib/calendrical_events/models/calendrical_event.dart @@ -51,7 +51,7 @@ class CalendricalEvent { startTime: Time.parse(data['startTime'] as String), endTime: Time.parse(data['endTime'] as String), title: data['title'] as String, - groupType: groupTypeFromString(data['groupType'] as String), + groupType: GroupType.values.byName(data['groupType'] as String), eventType: getEventTypeFromString(data['eventType'] as String), detail: data['detail'] as String, place: data['place'] as String, @@ -63,7 +63,7 @@ class CalendricalEvent { Map toJson() { return { 'groupID': groupID, - 'groupType': groupTypeToString(groupType), + 'groupType': groupType?.name, 'eventType': getEventTypeToString(eventType), 'authorID': authorID, 'date': date.toDateString, diff --git a/app/lib/groups/group_join/models/group_info_with_selection_state.dart b/app/lib/groups/group_join/models/group_info_with_selection_state.dart index 8b9b045cf..444e7cfd9 100644 --- a/app/lib/groups/group_join/models/group_info_with_selection_state.dart +++ b/app/lib/groups/group_join/models/group_info_with_selection_state.dart @@ -30,7 +30,7 @@ class GroupInfoWithSelectionState { factory GroupInfoWithSelectionState.fromData(Map data) { return GroupInfoWithSelectionState( id: data['id'] as String, - groupType: groupTypeFromString(data['groupType'] as String), + groupType: GroupType.values.byName(data['groupType'] as String), name: data['name'] as String, abbreviation: data['abbreviation'] as String, design: Design.fromData(data['design']), diff --git a/app/lib/timetable/src/models/lesson.dart b/app/lib/timetable/src/models/lesson.dart index 6cbb557b3..2a55eeddb 100644 --- a/app/lib/timetable/src/models/lesson.dart +++ b/app/lib/timetable/src/models/lesson.dart @@ -44,7 +44,7 @@ class Lesson { return Lesson( lessonID: id, groupID: data['groupID'] as String, - groupType: groupTypeFromString(data['groupType'] as String), + groupType: GroupType.values.byName(data['groupType'] as String), startDate: Date.parseOrNull(data['startDate'] as String), endDate: Date.parseOrNull(data['endDate'] as String), startTime: Time.parse(data['startTime'] as String), @@ -60,7 +60,7 @@ class Lesson { Map toJson() { return { 'groupID': groupID, - 'groupType': groupTypeToString(groupType), + 'groupType': groupType?.name, 'startDate': startDate?.toDateString, 'endDate': endDate?.toDateString, 'startTime': startTime?.time, diff --git a/app/lib/util/api/connections_gateway.dart b/app/lib/util/api/connections_gateway.dart index b1ed4089b..3b5fef14d 100644 --- a/app/lib/util/api/connections_gateway.dart +++ b/app/lib/util/api/connections_gateway.dart @@ -109,9 +109,9 @@ class ConnectionsGateway implements MyConnectionsAccesor { }, SetOptions(merge: true)); } - /// Warum wird nicht einfach [groupTypeToString(type)] verwendet? Für + /// Warum wird nicht einfach [type.name] verwendet? Für /// [addConnectionCreate] ist es notwenig, dass der Wert für z.B. Kurse - /// "Courses" ist. Mit [groupTypeToString(type)] ist der Wert jedoch + /// "Courses" ist. Mit [type.name] ist der Wert jedoch /// "courses", wodurch der Client diesen Kurs ignoriert (es entsteht dieser /// Bug: https://gitlab.com/codingbrain/sharezone/sharezone-app/-/issues/984) String _getCamelCaseGroupType(GroupType groupType) { @@ -167,7 +167,7 @@ class ConnectionsGateway implements MyConnectionsAccesor { }) async { return references.functions.joinWithGroupId( id: id, - type: groupTypeToString(type), + type: type.name, uId: memberID, ); } @@ -176,7 +176,7 @@ class ConnectionsGateway implements MyConnectionsAccesor { {@required String id, @required GroupType type}) { return references.functions.leave( id: id, - type: groupTypeToString(type), + type: type.name, memberID: memberID, ); } @@ -187,7 +187,7 @@ class ConnectionsGateway implements MyConnectionsAccesor { SchoolClassDeleteType schoolClassDeleteType}) { return references.functions.groupDelete( groupID: id, - type: groupTypeToString(type), + type: type.name, schoolClassDeleteType: schoolClassTypeToString(schoolClassDeleteType), ); } diff --git a/app/lib/util/api/course_gateway.dart b/app/lib/util/api/course_gateway.dart index eec32e252..57fedf68a 100644 --- a/app/lib/util/api/course_gateway.dart +++ b/app/lib/util/api/course_gateway.dart @@ -105,7 +105,7 @@ class CourseGateway { String courseID, String kickedMemberID) async { return references.functions.leave( id: courseID, - type: groupTypeToString(GroupType.course), + type: GroupType.course.name, memberID: kickedMemberID, ); } @@ -114,7 +114,7 @@ class CourseGateway { return references.functions.groupEdit( id: course.id, data: course.toEditJson(), - type: groupTypeToString(GroupType.course), + type: GroupType.course.name, ); } @@ -132,21 +132,21 @@ class CourseGateway { return references.functions.groupEditSettings( id: courseID, settings: courseSettings.toJson(), - type: groupTypeToString(GroupType.course), + type: GroupType.course.name, ); } Future> generateNewMeetingID(String courseID) async { return references.functions.generateNewMeetingID( id: courseID, - type: groupTypeToString(GroupType.course), + type: GroupType.course.name, ); } Future> deleteCourse(String courseID) async { return references.functions.groupDelete( groupID: courseID, - type: groupTypeToString(GroupType.course), + type: GroupType.course.name, ); } @@ -194,8 +194,8 @@ class CourseGateway { @required MemberRole newRole}) { return references.functions.memberUpdateRole( id: courseID, - type: groupTypeToString(GroupType.course), - role: memberRoleEnumToString(newRole), + type: GroupType.course.name, + role: newRole.name, memberID: newMemberID, ); } diff --git a/app/lib/util/api/school_class_gateway.dart b/app/lib/util/api/school_class_gateway.dart index 3cbafeb21..08296bc2d 100644 --- a/app/lib/util/api/school_class_gateway.dart +++ b/app/lib/util/api/school_class_gateway.dart @@ -54,8 +54,8 @@ class SchoolClassGateway { return references.functions.memberUpdateRole( id: schoolClassID, memberID: memberID, - role: memberRoleEnumToString(newRole), - type: groupTypeToString(GroupType.schoolclass), + role: newRole.name, + type: GroupType.schoolclass.name, ); } @@ -65,14 +65,14 @@ class SchoolClassGateway { memberID: memberID, id: schoolClass.id, data: schoolClass.toCreateJson(), - type: groupTypeToString(GroupType.schoolclass), + type: GroupType.schoolclass.name, ); } Future> generateNewMeetingID(String schoolClassID) { return references.functions.generateNewMeetingID( id: schoolClassID, - type: groupTypeToString(GroupType.schoolclass), + type: GroupType.schoolclass.name, ); } @@ -85,7 +85,7 @@ class SchoolClassGateway { data: courseData.copyWith( id: courseID, referenceSchoolClassIDs: [schoolClassID]).toCreateJson(memberID), - type: groupTypeToString(GroupType.course), + type: GroupType.course.name, ); } @@ -93,7 +93,7 @@ class SchoolClassGateway { return references.functions.groupEdit( id: schoolClass.id, data: schoolClass.toJson(), - type: groupTypeToString(GroupType.schoolclass), + type: GroupType.schoolclass.name, ); } @@ -118,7 +118,7 @@ class SchoolClassGateway { return references.functions.groupEditSettings( id: schoolClassID, settings: schoolClassSettings.toJson(), - type: groupTypeToString(GroupType.schoolclass), + type: GroupType.schoolclass.name, ); } @@ -126,7 +126,7 @@ class SchoolClassGateway { String schoolClassID, String kickedMemberID) async { return references.functions.leave( id: schoolClassID, - type: groupTypeToString(GroupType.schoolclass), + type: GroupType.schoolclass.name, memberID: kickedMemberID, ); } diff --git a/lib/group_domain_models/lib/src/accessors/group_member_accessor.dart b/lib/group_domain_models/lib/src/accessors/group_member_accessor.dart index ac0bff3f0..58f4e1157 100644 --- a/lib/group_domain_models/lib/src/accessors/group_member_accessor.dart +++ b/lib/group_domain_models/lib/src/accessors/group_member_accessor.dart @@ -7,7 +7,6 @@ // SPDX-License-Identifier: EUPL-1.2 import 'package:common_domain_models/common_domain_models.dart'; -import 'package:flutter/foundation.dart'; import 'package:group_domain_models/group_domain_models.dart'; import 'package:sharezone_common/api_errors.dart'; @@ -19,8 +18,8 @@ class GroupMemberAccessor { final SchoolClassMemberAccessor schoolClassMemberAccessor; const GroupMemberAccessor({ - @required this.courseMemberAccessor, - @required this.schoolClassMemberAccessor, + required this.courseMemberAccessor, + required this.schoolClassMemberAccessor, }); Stream> streamAllMembers(GroupKey groupKey) { diff --git a/lib/group_domain_models/lib/src/models/connections_data.dart b/lib/group_domain_models/lib/src/models/connections_data.dart index 39ce0af1e..531b81b79 100644 --- a/lib/group_domain_models/lib/src/models/connections_data.dart +++ b/lib/group_domain_models/lib/src/models/connections_data.dart @@ -6,24 +6,27 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'package:flutter/foundation.dart'; import 'package:group_domain_models/group_domain_models.dart'; import 'package:sharezone_common/helper_functions.dart'; import 'package:sharezone_common/references.dart'; class ConnectionsData { - final Map schoolClass; - final Map courses; + final Map? schoolClass; + final Map courses; - const ConnectionsData._({@required this.schoolClass, @required this.courses}); + const ConnectionsData._({ + required this.schoolClass, + required this.courses, + }); - factory ConnectionsData.fromData({@required Map data}) { + static ConnectionsData? fromData({required Map? data}) { if (data == null) { return const ConnectionsData._( schoolClass: null, courses: {}, ); } + Map schoolClasses = decodeMap( data[CollectionNames.schoolClasses], (key, data) => SchoolClass.fromData(data, id: key)); @@ -35,7 +38,7 @@ class ConnectionsData { } ConnectionsData copyWithJoinedCourses(List joinedCourses) { - Map courseMap = Map.of(courses); + Map courseMap = Map.of(courses); for (Course course in joinedCourses) { if (!courseMap.containsKey(course.id)) { courseMap[course.id] = course; @@ -46,24 +49,4 @@ class ConnectionsData { courses: courseMap, ); } - - GroupInfo getGroupInfo(GroupKey groupKey) { - if (groupKey.groupType == GroupType.course) { - return courses[groupKey.id].toGroupInfo(); - } else if (groupKey.groupType == GroupType.schoolclass) { - return schoolClass[groupKey.id].toGroupInfo(); - } - return null; - } - - List getGroups() { - final courseList = - courses.values.map((courseInfo) => courseInfo.toGroupInfo()); - final schoolClassList = - schoolClass.values.map((schoolClass) => schoolClass.toGroupInfo()); - final list = []; - list.addAll(courseList); - list.addAll(schoolClassList); - return list; - } } diff --git a/lib/group_domain_models/lib/src/models/course.dart b/lib/group_domain_models/lib/src/models/course.dart index 2cd4e6af4..bc5c857d0 100644 --- a/lib/group_domain_models/lib/src/models/course.dart +++ b/lib/group_domain_models/lib/src/models/course.dart @@ -10,42 +10,43 @@ import 'package:common_domain_models/common_domain_models.dart'; import 'package:design/design.dart'; import 'package:flutter/foundation.dart'; import 'package:sharezone_common/helper_functions.dart'; -import 'member_role.dart'; -import 'write_permissions.dart'; + import 'group_info.dart'; import 'group_type.dart'; -import 'group_key.dart'; +import 'member_role.dart'; +import 'write_permissions.dart'; class Course { - final String id, name, subject, abbreviation, sharecode, joinLink, meetingID; - final MemberRole myRole; + final String id; + final String? name, subject, abbreviation, sharecode, joinLink, meetingID; + final MemberRole? myRole; final CourseSettings settings; final bool version2; - final GroupId groupId; - final Design design, personalDesign; - final String personalSharecode, personalJoinLink; + final GroupId? groupId; + final Design? design, personalDesign; + final String? personalSharecode, personalJoinLink; const Course._({ - @required this.id, - @required this.name, - @required this.settings, - @required this.sharecode, - @required this.joinLink, - @required this.subject, - @required this.abbreviation, - @required this.meetingID, - @required this.myRole, - @required this.design, - @required this.personalDesign, - @required this.personalSharecode, - @required this.personalJoinLink, - @required this.groupId, + required this.id, + required this.name, + required this.settings, + required this.sharecode, + required this.joinLink, + required this.subject, + required this.abbreviation, + required this.meetingID, + required this.myRole, + required this.design, + required this.personalDesign, + required this.personalSharecode, + required this.personalJoinLink, + required this.groupId, this.version2 = true, }); factory Course.create() { return Course._( - id: null, + id: "", name: "", subject: "", sharecode: null, @@ -63,7 +64,7 @@ class Course { ); } - factory Course.fromData(Map data, {@required String id}) { + factory Course.fromData(Map data, {required String id}) { return Course._( id: id, name: data['name'] ?? "", @@ -76,7 +77,7 @@ class Course { groupId: GroupId(id), abbreviation: data['abbreviation'] ?? _getAbbreviationFromName(data['name'] ?? ""), - myRole: memberRoleEnumFromString(data['myRole'] ?? 'standard'), + myRole: MemberRole.values.byName(data['myRole'] ?? 'standard'), settings: CourseSettings.fromData(data['settings']), design: Design.fromData(data['design']), personalDesign: data['personalDesign'] != null @@ -93,7 +94,7 @@ class Course { 'publicKey': sharecode, 'joinLink': joinLink, 'meetingID': meetingID, - 'myRole': memberRoleEnumToString(myRole), + 'myRole': myRole?.name, 'settings': settings.toJson(), 'design': design?.toJson(), }; @@ -109,17 +110,17 @@ class Course { } Course copyWith({ - String id, - String name, - String subject, - String abbreviation, - String sharecode, - String joinLink, - String meetingID, - MemberRole myRole, - CourseSettings settings, - bool version2, - Design design, + String? id, + String? name, + String? subject, + String? abbreviation, + String? sharecode, + String? joinLink, + String? meetingID, + MemberRole? myRole, + CourseSettings? settings, + bool? version2, + Design? design, personalDesign, }) { return Course._( @@ -145,18 +146,18 @@ class Course { return personalDesign ?? design ?? Design.standard(); } - String getPublicKey() { + String? getPublicKey() { return personalSharecode ?? sharecode; } - String getJoinLink() { + String? getJoinLink() { return personalJoinLink ?? joinLink; } GroupInfo toGroupInfo() { return GroupInfo( id: id, - name: name, + name: name!, abbreviation: abbreviation, design: getDesign(), meetingID: meetingID, @@ -166,37 +167,34 @@ class Course { myRole: myRole, ); } - - GroupKey getGroupKey() { - return GroupKey(id: id, groupType: GroupType.course); - } } class CourseData { - final String id, name, subject, description, abbreviation; - final String sharecode, joinLink, referenceSchoolID, meetingID; - final List referenceSchoolClassIDs; + final String id; + final String? name, subject, description, abbreviation; + final String? sharecode, joinLink, referenceSchoolID, meetingID; + final List? referenceSchoolClassIDs; final CourseSettings settings; final Design design; const CourseData._({ - @required this.id, - @required this.name, - @required this.subject, - @required this.description, - @required this.abbreviation, - @required this.sharecode, - @required this.joinLink, - @required this.meetingID, - @required this.referenceSchoolID, - @required this.referenceSchoolClassIDs, - @required this.settings, - @required this.design, + required this.id, + required this.name, + required this.subject, + required this.description, + required this.abbreviation, + required this.sharecode, + required this.joinLink, + required this.meetingID, + required this.referenceSchoolID, + required this.referenceSchoolClassIDs, + required this.settings, + required this.design, }); factory CourseData.create() { return CourseData._( - id: null, + id: '', name: "", subject: "", description: "", @@ -211,8 +209,10 @@ class CourseData { ); } - factory CourseData.fromData( - {@required String id, @required Map data}) { + factory CourseData.fromData({ + required String id, + required Map data, + }) { return CourseData._( id: id, name: data['name'], @@ -241,7 +241,7 @@ class CourseData { 'settings': settings.toJson(), 'referenceSchoolClassIDs': referenceSchoolClassIDs, 'referenceSchoolID': referenceSchoolID, - 'design': design?.toJson(), + 'design': design.toJson(), }; } @@ -274,16 +274,16 @@ class CourseData { } CourseData copyWith({ - String id, + String? id, name, subject, description, abbreviation, - String publicKey, - String joinLink, + String? publicKey, + String? joinLink, referenceSchoolID, - List referenceSchoolClassIDs, - CourseSettings settings, + List? referenceSchoolClassIDs, + CourseSettings? settings, }) { return CourseData._( id: id ?? this.id, @@ -310,9 +310,9 @@ class CourseSettings { final WritePermission writePermission; const CourseSettings._({ - @required this.isPublic, - @required this.isMeetingEnabled, - @required this.writePermission, + required this.isPublic, + required this.isMeetingEnabled, + required this.writePermission, }); static const CourseSettings standard = CourseSettings._( @@ -321,13 +321,13 @@ class CourseSettings { writePermission: WritePermission.everyone, ); - factory CourseSettings.fromData(Map data) { + factory CourseSettings.fromData(Map? data) { if (data == null) return standard; return CourseSettings._( isPublic: data['isPublic'] ?? true, isMeetingEnabled: data['isMeetingEnabled'] ?? true, writePermission: - writePermissionEnumFromString(data['writePermission'] ?? 'everyone'), + WritePermission.values.byName(data['writePermission'] ?? 'everyone'), ); } @@ -335,14 +335,14 @@ class CourseSettings { return { 'isPublic': isPublic, 'isMeetingEnabled': isMeetingEnabled, - 'writePermission': writePermissionEnumToString(writePermission), + 'writePermission': writePermission.name, }; } CourseSettings copyWith({ - bool isPublic, - bool isMeetingEnabled, - WritePermission writePermission, + bool? isPublic, + bool? isMeetingEnabled, + WritePermission? writePermission, }) { return CourseSettings._( isPublic: isPublic ?? this.isPublic, @@ -353,13 +353,6 @@ class CourseSettings { } String _getAbbreviationFromName(String name) { - if (name != null) { - if (name.length > 2) { - return name.substring(0, 2); - } else { - return name; - } - } else { - return null; - } + if (name.length > 2) return name.substring(0, 2); + return name; } diff --git a/lib/group_domain_models/lib/src/models/group_info.dart b/lib/group_domain_models/lib/src/models/group_info.dart index 92ad6013f..e463c121c 100644 --- a/lib/group_domain_models/lib/src/models/group_info.dart +++ b/lib/group_domain_models/lib/src/models/group_info.dart @@ -6,32 +6,29 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'package:flutter/foundation.dart'; -import 'package:group_domain_models/group_domain_models.dart'; import 'package:design/design.dart'; +import 'package:group_domain_models/group_domain_models.dart'; class GroupInfo { final String id; - final String name, abbreviation; + final String? name, abbreviation; final Design design; - final String sharecode, joinLink; - final String meetingID; - final MemberRole myRole; + final String? sharecode, joinLink; + final String? meetingID; + final MemberRole? myRole; final GroupType groupType; const GroupInfo({ - @required this.id, - @required this.name, - @required this.design, - @required this.abbreviation, - @required this.sharecode, - @required this.meetingID, - @required this.joinLink, - @required this.groupType, + required this.id, + required String this.name, + required this.design, + required this.abbreviation, + required this.sharecode, + required this.meetingID, + required this.joinLink, + required this.groupType, this.myRole, - }) : assert(id != null), - assert(name != null), - assert(groupType != null); + }); factory GroupInfo.fromData(Map data) { return GroupInfo( @@ -43,7 +40,7 @@ class GroupInfo { sharecode: data['publicKey'], meetingID: data['meetingID'], joinLink: data['joinLink'], - groupType: groupTypeFromString(data['groupType']), + groupType: GroupType.values.byName(data['groupType']), ); } @@ -51,13 +48,6 @@ class GroupInfo { } String _getAbbreviationFromName(String name) { - if (name != null) { - if (name.length > 2) { - return name.substring(0, 2); - } else { - return name; - } - } else { - return null; - } + if (name.length > 2) return name.substring(0, 2); + return name; } diff --git a/lib/group_domain_models/lib/src/models/group_key.dart b/lib/group_domain_models/lib/src/models/group_key.dart index 7e73a7356..46c5095cc 100644 --- a/lib/group_domain_models/lib/src/models/group_key.dart +++ b/lib/group_domain_models/lib/src/models/group_key.dart @@ -6,14 +6,16 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'package:flutter/material.dart'; import 'group_type.dart'; class GroupKey { final String id; final GroupType groupType; - const GroupKey({@required this.id, @required this.groupType}); + const GroupKey({ + required this.id, + required this.groupType, + }); @override operator ==(other) { diff --git a/lib/group_domain_models/lib/src/models/group_type.dart b/lib/group_domain_models/lib/src/models/group_type.dart index 6bd64585b..fb1407ab6 100644 --- a/lib/group_domain_models/lib/src/models/group_type.dart +++ b/lib/group_domain_models/lib/src/models/group_type.dart @@ -6,10 +6,4 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'package:sharezone_common/helper_functions.dart'; - enum GroupType { course, schoolclass } - -GroupType groupTypeFromString(String data) => - enumFromString(GroupType.values, data, orElse: GroupType.course); -String groupTypeToString(GroupType groupType) => enumToString(groupType); diff --git a/lib/group_domain_models/lib/src/models/member.dart b/lib/group_domain_models/lib/src/models/member.dart index a02a301be..6f125e5ce 100644 --- a/lib/group_domain_models/lib/src/models/member.dart +++ b/lib/group_domain_models/lib/src/models/member.dart @@ -10,29 +10,28 @@ import 'package:common_domain_models/common_domain_models.dart'; import 'package:flutter/foundation.dart'; import 'package:sharezone_common/helper_functions.dart'; import 'package:user/user.dart'; + import 'member_role.dart'; @immutable class MemberData { final UserId id; final String name, abbreviation; - final MemberRole role; - final TypeOfUser typeOfUser; + final MemberRole? role; + final TypeOfUser? typeOfUser; final DateTime joinedOn; const MemberData({ - @required this.id, - @required this.name, - @required this.abbreviation, - @required this.typeOfUser, - @required this.role, - @required this.joinedOn, + required this.id, + required this.name, + required this.abbreviation, + required this.typeOfUser, + required this.role, + required this.joinedOn, }); factory MemberData.create( - {@required String id, - @required MemberRole role, - @required AppUser user}) { + {required String id, required MemberRole role, required AppUser user}) { return MemberData( id: UserId(id), name: user.name, @@ -43,15 +42,16 @@ class MemberData { ); } - factory MemberData.fromData(Map data, - {@required String id}) { - if (data == null) return null; + factory MemberData.fromData( + Map data, { + required String id, + }) { return MemberData( id: UserId(id), name: data['name'] ?? "", abbreviation: data['abbreviation'] ?? "", - typeOfUser: enumFromString(TypeOfUser.values, data['typeOfUser']), - role: memberRoleEnumFromString(data['role']), + typeOfUser: TypeOfUser.values.byName(data['typeOfUser']), + role: MemberRole.values.byName(data['role']), joinedOn: dateTimeFromTimestamp(data['joinedOn']), ); } @@ -62,24 +62,24 @@ class MemberData { 'name': name, 'abbreviation': abbreviation, 'typeOfUser': enumToString(typeOfUser), - 'role': memberRoleEnumToString(role), + 'role': role?.name, 'joinedOn': timestampFromDateTime(joinedOn), }; } MemberData copyWith({ - String name, + String? name, abbreviation, - DateTime joinedOn, - MemberData role, - TypeOfUser typeOfUser, + DateTime? joinedOn, + MemberData? role, + TypeOfUser? typeOfUser, }) { return MemberData( id: id, name: name ?? this.name, abbreviation: abbreviation ?? this.abbreviation, typeOfUser: typeOfUser ?? this.typeOfUser, - role: role ?? this.role, + role: role as MemberRole? ?? this.role, joinedOn: joinedOn ?? this.joinedOn, ); } diff --git a/lib/group_domain_models/lib/src/models/member_role.dart b/lib/group_domain_models/lib/src/models/member_role.dart index 984a19cb6..4be746bd8 100644 --- a/lib/group_domain_models/lib/src/models/member_role.dart +++ b/lib/group_domain_models/lib/src/models/member_role.dart @@ -6,8 +6,6 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'package:sharezone_common/helper_functions.dart'; - enum MemberRole { owner, admin, @@ -16,10 +14,6 @@ enum MemberRole { none, } -MemberRole memberRoleEnumFromString(String data) => - enumFromString(MemberRole.values, data); -String memberRoleEnumToString(MemberRole memberRole) => - enumToString(memberRole); const Map memberRoleAsString = { MemberRole.admin: "Admin", MemberRole.creator: "Aktives Mitglied (Schreib- und Leserechte)", diff --git a/lib/group_domain_models/lib/src/models/school_class.dart b/lib/group_domain_models/lib/src/models/school_class.dart index 408e1c75f..7cefb973d 100644 --- a/lib/group_domain_models/lib/src/models/school_class.dart +++ b/lib/group_domain_models/lib/src/models/school_class.dart @@ -8,39 +8,41 @@ import 'package:common_domain_models/common_domain_models.dart'; import 'package:design/design.dart'; -import 'package:flutter/foundation.dart'; -import 'group_type.dart'; import 'package:user/user.dart'; -import 'group_info.dart'; + import 'course.dart'; -import 'group_key.dart'; +import 'group_info.dart'; +import 'group_type.dart'; import 'member_role.dart'; class SchoolClass { - final String id, name, sharecode, joinLink, meetingID; + final String id; + final String? name, sharecode, joinLink, meetingID; GroupId get groupId => GroupId(id); - final MemberRole myRole; + final MemberRole? myRole; final CourseSettings settings; - final String personalSharecode, personalJoinLink; + final String? personalSharecode, personalJoinLink; SchoolClass._({ - @required this.id, - @required this.name, - @required this.myRole, - @required this.settings, - @required this.sharecode, - @required this.meetingID, - @required this.joinLink, - @required this.personalSharecode, - @required this.personalJoinLink, + required this.id, + required this.name, + required this.myRole, + required this.settings, + required this.sharecode, + required this.meetingID, + required this.joinLink, + required this.personalSharecode, + required this.personalJoinLink, }); - factory SchoolClass.fromData(Map data, - {@required String id}) { + factory SchoolClass.fromData( + Map data, { + required String id, + }) { return SchoolClass._( id: id, name: data['name'] ?? '', - myRole: memberRoleEnumFromString(data['myRole']), + myRole: MemberRole.values.byName(data['myRole']), sharecode: data['publicKey'], joinLink: data['joinLink'], meetingID: data['meetingID'] ?? '', @@ -58,13 +60,13 @@ class SchoolClass { } SchoolClass copyWith({ - String id, - String name, - String sharecode, - String meetingID, - MemberRole myRole, - CourseSettings settings, - String joinLink, + String? id, + String? name, + String? sharecode, + String? meetingID, + MemberRole? myRole, + CourseSettings? settings, + String? joinLink, }) { return SchoolClass._( id: id ?? this.id, @@ -83,18 +85,18 @@ class SchoolClass { return Design.standard(); } - String getPublicKey() { + String? getPublicKey() { return personalSharecode ?? sharecode; } - String getJoinLink() { + String? getJoinLink() { return personalJoinLink ?? joinLink; } GroupInfo toGroupInfo() { return GroupInfo( id: id, - name: name, + name: name!, abbreviation: generateAbbreviation(name), design: getDesign(), meetingID: meetingID, @@ -104,33 +106,30 @@ class SchoolClass { myRole: myRole, ); } - - GroupKey getGroupKey() { - return GroupKey(id: id, groupType: GroupType.schoolclass); - } } class SchoolClassData { - final String id, name, description, abbreviation, meetingID; - final String sharecode, joinLink, referenceSchoolID; + final String id; + final String? name, description, abbreviation, meetingID; + final String? sharecode, joinLink, referenceSchoolID; final CourseSettings settings; const SchoolClassData._({ - @required this.id, - @required this.name, - @required this.description, - @required this.meetingID, - @required this.abbreviation, - @required this.sharecode, - @required this.joinLink, - @required this.referenceSchoolID, - @required this.settings, + required this.id, + required this.name, + required this.description, + required this.meetingID, + required this.abbreviation, + required this.sharecode, + required this.joinLink, + required this.referenceSchoolID, + required this.settings, }); factory SchoolClassData.create() { return const SchoolClassData._( - id: null, + id: '', name: "", description: "", abbreviation: "", @@ -143,7 +142,9 @@ class SchoolClassData { } factory SchoolClassData.fromData( - {@required String id, @required Map data}) { + Map data, { + required String id, + }) { return SchoolClassData._( id: id, name: data['name'], @@ -179,14 +180,14 @@ class SchoolClassData { } SchoolClassData copyWith({ - String id, - String name, - String description, - String abbreviation, - String sharecode, - String joinLink, + String? id, + String? name, + String? description, + String? abbreviation, + String? sharecode, + String? joinLink, referenceSchoolID, - CourseSettings settings, + CourseSettings? settings, }) { return SchoolClassData._( id: id ?? this.id, diff --git a/lib/group_domain_models/lib/src/models/sharecode.dart b/lib/group_domain_models/lib/src/models/sharecode.dart index 11bb10d42..632007521 100644 --- a/lib/group_domain_models/lib/src/models/sharecode.dart +++ b/lib/group_domain_models/lib/src/models/sharecode.dart @@ -19,7 +19,7 @@ class Sharecode { /// Checks if [sharecode] has the attributes of a sharecode: /// only small and big letters from alphabet and a length of 6. - static bool isValid(String sharecode) { + static bool isValid(String? sharecode) { if (sharecode == null) return false; final sharecodeRegEx = RegExp(r"^[a-zA-Z0-9]{6}$"); return sharecodeRegEx.hasMatch(sharecode); diff --git a/lib/group_domain_models/lib/src/models/write_permissions.dart b/lib/group_domain_models/lib/src/models/write_permissions.dart index 3cb90aea2..1a9415059 100644 --- a/lib/group_domain_models/lib/src/models/write_permissions.dart +++ b/lib/group_domain_models/lib/src/models/write_permissions.dart @@ -6,15 +6,8 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'package:sharezone_common/helper_functions.dart'; - enum WritePermission { everyone, onlyAdmins } -WritePermission writePermissionEnumFromString(String data) => - enumFromString(WritePermission.values, data); -String writePermissionEnumToString(WritePermission writePermissions) => - enumToString(writePermissions); - String writePermissionAsUiString(WritePermission writePermission) { switch (writePermission) { case WritePermission.everyone: diff --git a/lib/group_domain_models/pubspec.yaml b/lib/group_domain_models/pubspec.yaml index b8af4e7ba..d17baeecd 100644 --- a/lib/group_domain_models/pubspec.yaml +++ b/lib/group_domain_models/pubspec.yaml @@ -9,11 +9,10 @@ name: group_domain_models description: A new Flutter package project. version: 0.0.1 -homepage: publish_to: none environment: - sdk: ">=2.10.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: common_domain_models: diff --git a/lib/group_domain_models/test/models/sharecode_test.dart b/lib/group_domain_models/test/models/sharecode_test.dart index e291e38be..8f5008875 100644 --- a/lib/group_domain_models/test/models/sharecode_test.dart +++ b/lib/group_domain_models/test/models/sharecode_test.dart @@ -10,9 +10,9 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:group_domain_models/group_domain_models.dart'; void main() { - group('sharecode', () { - void testSharecode(String sharecode, bool expactedValue) { - expect(Sharecode.isValid(sharecode), expactedValue); + group('Sharecode', () { + void testSharecode(String? sharecode, bool expectedValue) { + expect(Sharecode.isValid(sharecode), expectedValue); } const validSharecode1 = "000000";