Skip to content
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 functionality for converting Session models to json #74

Merged
merged 4 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/models/session.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import 'package:json_annotation/json_annotation.dart';

part 'session.g.dart';

/// Represents the metadata for data collection session.
@JsonSerializable()
class Session {
/// Unique identifier for the participant
final String participantID;
Expand All @@ -24,4 +29,9 @@ class Session {
return "Session(participantID: $participantID, sessionID: $sessionID, "
"startTime: $startTime, endTime: $endTime)";
}

/// Convert the [Session] object to its json representation.
/// This method is particularly useful when uploading data to Firebase and
/// similar no-sql dbs.
Map<String, dynamic> toJson() => _$SessionToJson(this);
}
21 changes: 21 additions & 0 deletions lib/models/session.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions test/models/session_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,20 @@ void main() {
"endTime: ${session.endTime})";
expect(session.toString(), strRep);
});

test(
"Session.toJson() returns a valid json representation",
() {
final Session session = Session(
participantID: '101',
sessionID: '001',
startTime: DateTime.now(),
endTime: DateTime.now(),
);

final Map<String, dynamic> sessionJson = session.toJson();

expect(sessionJson, isMap);
},
);
}
Loading