diff --git a/lib/mock/db_mock.dart b/lib/mock/db_mock.dart index 313cece..dac8c9f 100644 --- a/lib/mock/db_mock.dart +++ b/lib/mock/db_mock.dart @@ -17,7 +17,7 @@ class DatabaseMock implements DatabaseService { final List _moodRecords = []; final List _sleepRecords = []; final List _relapseRecords = []; - final List _workoutRecords = []; + final List _workoutRecords = []; @override Future addMood(Mood mood) { @@ -60,4 +60,9 @@ class DatabaseMock implements DatabaseService { Future> getRelapseRecords() { return Future.value(_relapseRecords); } + + @override + Future> getWorkoutRecords() { + return Future.value(_workoutRecords); + } } diff --git a/lib/models/workout.dart b/lib/models/workout.dart index 0bba86a..67dd828 100644 --- a/lib/models/workout.dart +++ b/lib/models/workout.dart @@ -7,10 +7,16 @@ class Workout implements DatabaseRecord { Workout(this._motivationBefore, this._motivationAfter, this._workoutDate); + @override + factory Workout.fromDatabase(Map map) { + return Workout(map['motivationBefore'], map['motivationAfter'], + DateTime.parse(map['workoutDate'])); + } + @override factory Workout.fromMap(Map map) { - return Workout(map['_workoutDuration'], map['_motivationBefore'], - map['_motivationAfter']); + return Workout( + map['motivationBefore'], map['motivationAfter'], map['workoutDate']); } @override diff --git a/lib/services/database_service.dart b/lib/services/database_service.dart index 3996883..acc3ca0 100644 --- a/lib/services/database_service.dart +++ b/lib/services/database_service.dart @@ -63,6 +63,15 @@ class DatabaseService { return relapseList; } + Future> getWorkoutRecords() async { + Database db = await instance.database; + var workoutRecords = await db.query('workout'); + List workoutList = workoutRecords.isNotEmpty + ? workoutRecords.map((e) => Workout.fromDatabase(e)).toList() + : []; + return workoutList; + } + Future addMood(Mood mood) async { Database db = await instance.database; return await db.insert('mood', mood.toMap());