add workout get db function

main
Julian Gegner 2023-03-02 19:04:40 +01:00
parent a042933a2d
commit c8a140678d
3 changed files with 23 additions and 3 deletions

View File

@ -17,7 +17,7 @@ class DatabaseMock implements DatabaseService {
final List<Mood> _moodRecords = [];
final List<Sleep> _sleepRecords = [];
final List<Relapse> _relapseRecords = [];
final List<DatabaseRecord> _workoutRecords = [];
final List<Workout> _workoutRecords = [];
@override
Future<int> addMood(Mood mood) {
@ -60,4 +60,9 @@ class DatabaseMock implements DatabaseService {
Future<List<Relapse>> getRelapseRecords() {
return Future.value(_relapseRecords);
}
@override
Future<List<Workout>> getWorkoutRecords() {
return Future.value(_workoutRecords);
}
}

View File

@ -7,10 +7,16 @@ class Workout implements DatabaseRecord {
Workout(this._motivationBefore, this._motivationAfter, this._workoutDate);
@override
factory Workout.fromDatabase(Map<String, dynamic> map) {
return Workout(map['motivationBefore'], map['motivationAfter'],
DateTime.parse(map['workoutDate']));
}
@override
factory Workout.fromMap(Map<String, dynamic> map) {
return Workout(map['_workoutDuration'], map['_motivationBefore'],
map['_motivationAfter']);
return Workout(
map['motivationBefore'], map['motivationAfter'], map['workoutDate']);
}
@override

View File

@ -63,6 +63,15 @@ class DatabaseService {
return relapseList;
}
Future<List<Workout>> getWorkoutRecords() async {
Database db = await instance.database;
var workoutRecords = await db.query('workout');
List<Workout> workoutList = workoutRecords.isNotEmpty
? workoutRecords.map((e) => Workout.fromDatabase(e)).toList()
: [];
return workoutList;
}
Future<int> addMood(Mood mood) async {
Database db = await instance.database;
return await db.insert('mood', mood.toMap());