add workout get db function
parent
a042933a2d
commit
c8a140678d
|
@ -17,7 +17,7 @@ class DatabaseMock implements DatabaseService {
|
||||||
final List<Mood> _moodRecords = [];
|
final List<Mood> _moodRecords = [];
|
||||||
final List<Sleep> _sleepRecords = [];
|
final List<Sleep> _sleepRecords = [];
|
||||||
final List<Relapse> _relapseRecords = [];
|
final List<Relapse> _relapseRecords = [];
|
||||||
final List<DatabaseRecord> _workoutRecords = [];
|
final List<Workout> _workoutRecords = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<int> addMood(Mood mood) {
|
Future<int> addMood(Mood mood) {
|
||||||
|
@ -60,4 +60,9 @@ class DatabaseMock implements DatabaseService {
|
||||||
Future<List<Relapse>> getRelapseRecords() {
|
Future<List<Relapse>> getRelapseRecords() {
|
||||||
return Future.value(_relapseRecords);
|
return Future.value(_relapseRecords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<Workout>> getWorkoutRecords() {
|
||||||
|
return Future.value(_workoutRecords);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,16 @@ class Workout implements DatabaseRecord {
|
||||||
|
|
||||||
Workout(this._motivationBefore, this._motivationAfter, this._workoutDate);
|
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
|
@override
|
||||||
factory Workout.fromMap(Map<String, dynamic> map) {
|
factory Workout.fromMap(Map<String, dynamic> map) {
|
||||||
return Workout(map['_workoutDuration'], map['_motivationBefore'],
|
return Workout(
|
||||||
map['_motivationAfter']);
|
map['motivationBefore'], map['motivationAfter'], map['workoutDate']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -63,6 +63,15 @@ class DatabaseService {
|
||||||
return relapseList;
|
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 {
|
Future<int> addMood(Mood mood) async {
|
||||||
Database db = await instance.database;
|
Database db = await instance.database;
|
||||||
return await db.insert('mood', mood.toMap());
|
return await db.insert('mood', mood.toMap());
|
||||||
|
|
Loading…
Reference in New Issue