cpd_2022_zi/lib/models/relapse.dart

33 lines
749 B
Dart
Raw Normal View History

2023-02-26 23:24:23 +01:00
import 'package:smoke_cess_app/interface/db_record.dart';
class Relapse implements DatabaseRecord {
2023-02-27 02:28:26 +01:00
final String _category;
2023-02-26 23:24:23 +01:00
final String _comment;
final DateTime _date;
2023-02-27 02:28:26 +01:00
Relapse(this._category, this._comment, this._date);
2023-02-26 23:24:23 +01:00
2023-03-03 12:47:54 +01:00
String get category => _category;
DateTime get date => _date;
2023-02-26 23:24:23 +01:00
@override
factory Relapse.fromDatabase(Map<String, dynamic> map) {
DateTime date = DateTime.parse(map['date']);
2023-02-27 15:19:03 +01:00
return Relapse(map['category'], map['comment'], date);
2023-02-26 23:24:23 +01:00
}
@override
String toCSV() {
2023-02-27 02:28:26 +01:00
return "${_date.toIso8601String()}, $_category, $_comment";
2023-02-26 23:24:23 +01:00
}
@override
Map<String, dynamic> toMap() {
return {
2023-02-27 15:19:03 +01:00
'category': _category,
2023-02-26 23:24:23 +01:00
'comment': _comment,
'date': _date.toIso8601String(),
};
}
}