Skip to content

Commit

Permalink
Migrate group_domain_models package null safety (#495)
Browse files Browse the repository at this point in the history
Closes #192

---------

Co-authored-by: Jonas Sander <[email protected]>
  • Loading branch information
nilsreichardt and Jonas-Sander authored Aug 17, 2023
1 parent 6f15ccb commit 54619c5
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 269 deletions.
4 changes: 2 additions & 2 deletions app/lib/calendrical_events/models/calendrical_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -63,7 +63,7 @@ class CalendricalEvent {
Map<String, dynamic> toJson() {
return {
'groupID': groupID,
'groupType': groupTypeToString(groupType),
'groupType': groupType?.name,
'eventType': getEventTypeToString(eventType),
'authorID': authorID,
'date': date.toDateString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GroupInfoWithSelectionState {
factory GroupInfoWithSelectionState.fromData(Map<String, dynamic> 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']),
Expand Down
4 changes: 2 additions & 2 deletions app/lib/timetable/src/models/lesson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -60,7 +60,7 @@ class Lesson {
Map<String, dynamic> toJson() {
return {
'groupID': groupID,
'groupType': groupTypeToString(groupType),
'groupType': groupType?.name,
'startDate': startDate?.toDateString,
'endDate': endDate?.toDateString,
'startTime': startTime?.time,
Expand Down
10 changes: 5 additions & 5 deletions app/lib/util/api/connections_gateway.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -167,7 +167,7 @@ class ConnectionsGateway implements MyConnectionsAccesor {
}) async {
return references.functions.joinWithGroupId(
id: id,
type: groupTypeToString(type),
type: type.name,
uId: memberID,
);
}
Expand All @@ -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,
);
}
Expand All @@ -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),
);
}
Expand Down
14 changes: 7 additions & 7 deletions app/lib/util/api/course_gateway.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand All @@ -114,7 +114,7 @@ class CourseGateway {
return references.functions.groupEdit(
id: course.id,
data: course.toEditJson(),
type: groupTypeToString(GroupType.course),
type: GroupType.course.name,
);
}

Expand All @@ -132,21 +132,21 @@ class CourseGateway {
return references.functions.groupEditSettings(
id: courseID,
settings: courseSettings.toJson(),
type: groupTypeToString(GroupType.course),
type: GroupType.course.name,
);
}

Future<AppFunctionsResult<bool>> generateNewMeetingID(String courseID) async {
return references.functions.generateNewMeetingID(
id: courseID,
type: groupTypeToString(GroupType.course),
type: GroupType.course.name,
);
}

Future<AppFunctionsResult<bool>> deleteCourse(String courseID) async {
return references.functions.groupDelete(
groupID: courseID,
type: groupTypeToString(GroupType.course),
type: GroupType.course.name,
);
}

Expand Down Expand Up @@ -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,
);
}
Expand Down
16 changes: 8 additions & 8 deletions app/lib/util/api/school_class_gateway.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand All @@ -65,14 +65,14 @@ class SchoolClassGateway {
memberID: memberID,
id: schoolClass.id,
data: schoolClass.toCreateJson(),
type: groupTypeToString(GroupType.schoolclass),
type: GroupType.schoolclass.name,
);
}

Future<AppFunctionsResult<bool>> generateNewMeetingID(String schoolClassID) {
return references.functions.generateNewMeetingID(
id: schoolClassID,
type: groupTypeToString(GroupType.schoolclass),
type: GroupType.schoolclass.name,
);
}

Expand All @@ -85,15 +85,15 @@ class SchoolClassGateway {
data: courseData.copyWith(
id: courseID,
referenceSchoolClassIDs: [schoolClassID]).toCreateJson(memberID),
type: groupTypeToString(GroupType.course),
type: GroupType.course.name,
);
}

Future<AppFunctionsResult<bool>> editSchoolClass(SchoolClass schoolClass) {
return references.functions.groupEdit(
id: schoolClass.id,
data: schoolClass.toJson(),
type: groupTypeToString(GroupType.schoolclass),
type: GroupType.schoolclass.name,
);
}

Expand All @@ -118,15 +118,15 @@ class SchoolClassGateway {
return references.functions.groupEditSettings(
id: schoolClassID,
settings: schoolClassSettings.toJson(),
type: groupTypeToString(GroupType.schoolclass),
type: GroupType.schoolclass.name,
);
}

Future<AppFunctionsResult<bool>> kickMember(
String schoolClassID, String kickedMemberID) async {
return references.functions.leave(
id: schoolClassID,
type: groupTypeToString(GroupType.schoolclass),
type: GroupType.schoolclass.name,
memberID: kickedMemberID,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -19,8 +18,8 @@ class GroupMemberAccessor {
final SchoolClassMemberAccessor schoolClassMemberAccessor;

const GroupMemberAccessor({
@required this.courseMemberAccessor,
@required this.schoolClassMemberAccessor,
required this.courseMemberAccessor,
required this.schoolClassMemberAccessor,
});

Stream<List<MemberData>> streamAllMembers(GroupKey groupKey) {
Expand Down
35 changes: 9 additions & 26 deletions lib/group_domain_models/lib/src/models/connections_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, SchoolClass> schoolClass;
final Map<String, Course> courses;
final Map<String, SchoolClass>? schoolClass;
final Map<String?, Course> courses;

const ConnectionsData._({@required this.schoolClass, @required this.courses});
const ConnectionsData._({
required this.schoolClass,
required this.courses,
});

factory ConnectionsData.fromData({@required Map<String, dynamic> data}) {
static ConnectionsData? fromData({required Map<String, dynamic>? data}) {
if (data == null) {
return const ConnectionsData._(
schoolClass: null,
courses: {},
);
}

Map<String, SchoolClass> schoolClasses = decodeMap(
data[CollectionNames.schoolClasses],
(key, data) => SchoolClass.fromData(data, id: key));
Expand All @@ -35,7 +38,7 @@ class ConnectionsData {
}

ConnectionsData copyWithJoinedCourses(List<Course> joinedCourses) {
Map<String, Course> courseMap = Map.of(courses);
Map<String?, Course> courseMap = Map.of(courses);
for (Course course in joinedCourses) {
if (!courseMap.containsKey(course.id)) {
courseMap[course.id] = course;
Expand All @@ -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<GroupInfo> getGroups() {
final courseList =
courses.values.map((courseInfo) => courseInfo.toGroupInfo());
final schoolClassList =
schoolClass.values.map((schoolClass) => schoolClass.toGroupInfo());
final list = <GroupInfo>[];
list.addAll(courseList);
list.addAll(schoolClassList);
return list;
}
}
Loading

0 comments on commit 54619c5

Please sign in to comment.