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 { abstract class DatabaseRecord {
String toCSV(); String toCSV();
Map<String, dynamic> toMap(); 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, HIITWorkout(this._workoutDuration, this._commentBefore, this._commentAfter,
this._workoutDate); this._workoutDate);
/* @override //TODO Felder anpassen
HIITWorkout.fromMap(Map<String, dynamic> map) { @override
_workoutDuration = map['_workoutDuration']; factory HIITWorkout.fromMap(Map<String, dynamic> map) {
_commentBefore = map['_commentBefore']; return HIITWorkout(map['_workoutDuration'], map['_commentBefore'],
_commentAfter = map['_commentAfter']; map['_commentAfter'], map['_workoutDate']);
_workoutDate = map['_workoutDate']; }
} */
@override @override
String toCSV() => String toCSV() =>

View File

@ -1,15 +1,21 @@
import 'package:smoke_cess_app/interface/db_record.dart'; import 'package:smoke_cess_app/interface/db_record.dart';
class Mood implements DatabaseRecord { class Mood implements DatabaseRecord {
final double _moodValue; final int _moodValue;
final String _comment; final String _comment;
final DateTime _date; final DateTime _date;
Mood(this._moodValue, this._comment, this._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 @override
String toCSV() { String toCSV() {
return "${_date.toIso8601String()}, ${_moodValue.round().toString()}, $_comment"; return "${_date.toIso8601String()}, $_moodValue, $_comment";
} }
@override @override

View File

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