-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add teachers to substitution plan #1647
Changes from 8 commits
c5fbb85
b84edbe
1f59c67
1e6f344
abde76b
12fb7bd
a33c7ea
e13e90f
dc9de3a
11c3265
fdcff7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
// SPDX-License-Identifier: EUPL-1.2 | ||
|
||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:collection/collection.dart'; | ||
import 'package:common_domain_models/common_domain_models.dart'; | ||
import 'package:date/date.dart'; | ||
import 'package:sharezone/timetable/src/models/substitution_id.dart'; | ||
|
@@ -18,13 +19,17 @@ enum SubstitutionType { | |
/// The lesson is moved to another room. | ||
locationChanged, | ||
|
||
/// The teacher changed for the lesson. | ||
teacherChanged, | ||
|
||
/// Unknown substitution type. | ||
unknown; | ||
|
||
String toDatabaseString() { | ||
return switch (this) { | ||
lessonCanceled => 'lessonCanceled', | ||
locationChanged => 'placeChanged', | ||
teacherChanged => 'teacherChanged', | ||
unknown => 'unknown', | ||
}; | ||
} | ||
|
@@ -33,6 +38,7 @@ enum SubstitutionType { | |
return switch (value) { | ||
'lessonCanceled' => lessonCanceled, | ||
'placeChanged' => locationChanged, | ||
'teacherChanged' => teacherChanged, | ||
_ => unknown, | ||
}; | ||
} | ||
|
@@ -94,6 +100,14 @@ sealed class Substitution { | |
isDeleted: isDeleted, | ||
updatedBy: updatedBy, | ||
), | ||
SubstitutionType.teacherChanged => TeacherChangedSubstitution( | ||
id: id, | ||
date: Date.parse(data['date'] as String), | ||
createdBy: createdBy, | ||
newTeacher: data['newTeacher'] as String, | ||
isDeleted: isDeleted, | ||
updatedBy: updatedBy, | ||
), | ||
SubstitutionType.unknown => UnknownSubstitution( | ||
id: id, | ||
date: Date.parse(data['date'] as String), | ||
|
@@ -154,6 +168,29 @@ class LocationChangedSubstitution extends Substitution { | |
} | ||
} | ||
|
||
class TeacherChangedSubstitution extends Substitution { | ||
final String newTeacher; | ||
|
||
const TeacherChangedSubstitution({ | ||
required super.id, | ||
required this.newTeacher, | ||
required super.date, | ||
required super.createdBy, | ||
super.isDeleted, | ||
super.updatedBy, | ||
}) : super(type: SubstitutionType.teacherChanged); | ||
|
||
@override | ||
Map<String, dynamic> toCreateJson({ | ||
required bool notifyGroupMembers, | ||
}) { | ||
return { | ||
...super.toCreateJson(notifyGroupMembers: notifyGroupMembers), | ||
'newTeacher': newTeacher, | ||
}; | ||
} | ||
} | ||
|
||
Comment on lines
+182
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You did it like this so that only one class for a Substitution is needed both for creating a new substitution and reading an existing substitution out of a lesson, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean its the pattern you already used, but I can't remember if there was a specific reason why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I correctly understand you, do mean like splitting in into a DTO class or something like this? If yes: I used just one class to keep it simple for now |
||
class UnknownSubstitution extends Substitution { | ||
const UnknownSubstitution({ | ||
required super.id, | ||
|
@@ -163,3 +200,23 @@ class UnknownSubstitution extends Substitution { | |
super.updatedBy, | ||
}) : super(type: SubstitutionType.unknown); | ||
} | ||
|
||
extension SubstitutionList on List<Substitution?> { | ||
LocationChangedSubstitution? getLocationChangedSubstitution() { | ||
return firstWhereOrNull( | ||
(substitution) => substitution is LocationChangedSubstitution) | ||
as LocationChangedSubstitution?; | ||
} | ||
|
||
TeacherChangedSubstitution? getTeacherChangedSubstitution() { | ||
return firstWhereOrNull( | ||
(substitution) => substitution is TeacherChangedSubstitution) | ||
as TeacherChangedSubstitution?; | ||
} | ||
|
||
LessonCanceledSubstitution? getLessonCanceledSubstitution() { | ||
return firstWhereOrNull( | ||
(substitution) => substitution is LessonCanceledSubstitution) | ||
as LessonCanceledSubstitution?; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or should we use
substitutionTeacher
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think
substitutionTeacher
is better.