Skip to content

Commit

Permalink
Chore: Add final in data transfer object
Browse files Browse the repository at this point in the history
  • Loading branch information
ntut-xuan committed Feb 12, 2024
1 parent 1b5da58 commit e3f75f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
34 changes: 14 additions & 20 deletions lib/src/model/coursetable/course.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ part 'course.g.dart';

@JsonSerializable()
class Course {
late int id;
String name;
late double stage;
late double credit;
late int periodCount;
String category;
late List<String> teachers;
late List<String> classNames;
late List<CoursePeriod> coursePeriods;
late List<String> classrooms;
String applyStatus;
String language;
String syllabusLink;
String note;
late final int id;
final String name;
late final double stage;
late final double credit;
late final int periodCount;
final String category;
late final List<String> teachers;
late final List<String> classNames;
late final List<CoursePeriod> coursePeriods;
late final List<String> classrooms;
final String applyStatus;
final String language;
final String syllabusLink;
final String note;

Course(
{required this.id,
Expand Down Expand Up @@ -55,19 +55,13 @@ class Course {
required this.note,
}) {
id = JsonInit.intInit(idString);
name = JsonInit.stringInit(name).trim();
stage = JsonInit.doubleInit(stageString);
credit = JsonInit.doubleInit(creditString);
periodCount = JsonInit.intInit(periodCountString);
category = JsonInit.stringInit(category).trim();
teachers = teacherString.split(RegExp(r"\n")).map((element) => element.trim()).toList();
coursePeriods = _convertPeriodSlotsToCoursePeriods(periodSlots);
classrooms = classroomString.split(RegExp(r"\n")).map((element) => element.trim()).toList();
classNames = classNameString.split(RegExp(r"\n")).map((element) => element.trim()).toList();
applyStatus = JsonInit.stringInit(applyStatus).trim();
language = JsonInit.stringInit(language).trim();
syllabusLink = JsonInit.stringInit(syllabusLink).trim();
note = JsonInit.stringInit(note).trim();
}

bool isEmpty() => id == 0;
Expand Down
9 changes: 3 additions & 6 deletions lib/src/model/coursetable/course_period.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ part 'course_period.g.dart';

@JsonSerializable()
class CoursePeriod {
int weekday;
String period;
final int weekday;
final String period;

CoursePeriod({required this.weekday, required this.period}) {
weekday = weekday;
period = period;
}
CoursePeriod({required this.weekday, required this.period});

factory CoursePeriod.fromJson(Map<String, dynamic> json) => _$CoursePeriodFromJson(json);

Expand Down
12 changes: 4 additions & 8 deletions lib/src/model/coursetable/course_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ part 'course_table.g.dart';

@JsonSerializable()
class CourseTable {
int year;
int semester;
List<Course> courses;
User user;
final int year;
final int semester;
final List<Course> courses;
final User user;
late final Set<int> weekdays = {};
late final Set<String> periods = {};

CourseTable({required this.year, required this.semester, required this.courses, required this.user}) {
year = year;
semester = semester;
courses = courses;
user = user;
weekdays.addAll(courses
.map((course) => course.coursePeriods.map((coursePeriod) => coursePeriod.weekday))
.expand((element) => element));
Expand Down

0 comments on commit e3f75f4

Please sign in to comment.