changed models, added function from db to model

main
Julian Gegner 2023-02-25 18:54:23 +01:00
parent 9a13cfb9f1
commit abbbc4a8c4
4 changed files with 33 additions and 16 deletions

View File

@ -1,5 +1,5 @@
abstract class DatabaseRecord {
String toCSV();
Map<String, dynamic> toMap();
DatabaseRecord.fromMap(Map<String, dynamic> map);
DatabaseRecord.fromDatabase(Map<String, dynamic> map);
}

View File

@ -9,13 +9,12 @@ class HIITWorkout implements DatabaseRecord {
HIITWorkout(this._workoutDuration, this._commentBefore, this._commentAfter,
this._workoutDate);
/* @override
HIITWorkout.fromMap(Map<String, dynamic> map) {
_workoutDuration = map['_workoutDuration'];
_commentBefore = map['_commentBefore'];
_commentAfter = map['_commentAfter'];
_workoutDate = map['_workoutDate'];
} */
//TODO Felder anpassen
@override
factory HIITWorkout.fromMap(Map<String, dynamic> map) {
return HIITWorkout(map['_workoutDuration'], map['_commentBefore'],
map['_commentAfter'], map['_workoutDate']);
}
@override
String toCSV() =>

View File

@ -1,15 +1,21 @@
import 'package:smoke_cess_app/interface/db_record.dart';
class Mood implements DatabaseRecord {
final double _moodValue;
final int _moodValue;
final String _comment;
final DateTime _date;
Mood(this._moodValue, this._comment, this._date);
@override
factory Mood.fromDatabase(Map<String, dynamic> map) {
DateTime date = DateTime.parse(map['date']);
return Mood(map['value'], map['comment'], date);
}
@override
String toCSV() {
return "${_date.toIso8601String()}, ${_moodValue.round().toString()}, $_comment";
return "${_date.toIso8601String()}, $_moodValue, $_comment";
}
@override

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:smoke_cess_app/interface/db_record.dart';
class Sleep implements DatabaseRecord {
final double _sleepQualityValue;
final int _sleepQualityValue;
final String _comment;
final DateTime _date;
final TimeOfDay _sleepedAt;
@ -11,19 +11,31 @@ class Sleep implements DatabaseRecord {
Sleep(this._sleepQualityValue, this._comment, this._date, this._sleepedAt,
this._wokeUpAt);
@override
factory Sleep.fromDatabase(Map<String, dynamic> map) {
DateTime date = DateTime.parse(map['date']);
TimeOfDay sleepedAt =
TimeOfDay(hour: map['sleepedAtHour'], minute: map['sleepedAtMinute']);
TimeOfDay wokeUpAt =
TimeOfDay(hour: map['wokeUpAtHour'], minute: map['wokeUpAtMinute']);
return Sleep(map['value'], map['comment'], date, sleepedAt, wokeUpAt);
}
@override
String toCSV() {
return "${_date.toIso8601String()}, ${_sleepQualityValue.round().toString()}, $_sleepedAt, $_wokeUpAt, $_comment";
return "${_date.toIso8601String()}, $_sleepQualityValue, ${_sleepedAt.hour}:${_sleepedAt.minute}, ${_wokeUpAt.hour}:${_wokeUpAt.minute}, $_comment";
}
@override
Map<String, dynamic> toMap() {
return {
'sleepQualityValue': _sleepQualityValue,
'value': _sleepQualityValue,
'comment': _comment,
'date': _date,
'sleepedAt': _sleepedAt,
'wokeUpAt': _wokeUpAt,
'date': _date.toIso8601String(),
'sleepedAtHour': _sleepedAt.hour,
'sleepedAtMinute': _sleepedAt.minute,
'wokeUpAtHour': _wokeUpAt.hour,
'wokeUpAtMinute': _wokeUpAt.minute,
};
}
}