From fca1b565f5150ce9cf483601b7c18d9bd4674ac0 Mon Sep 17 00:00:00 2001 From: Liat Ben-Haim Date: Sat, 3 Jun 2023 14:54:47 +0200 Subject: [PATCH] feat: add DailyStatusRepository for managing and persisting state - Also add model for DailyStatus --- lib/data_storage/daily_status_repository.dart | 51 +++++++++++++++++++ .../models/daily_entry_model.dart | 15 ++++++ 2 files changed, 66 insertions(+) create mode 100644 lib/data_storage/daily_status_repository.dart create mode 100644 lib/data_storage/models/daily_entry_model.dart diff --git a/lib/data_storage/daily_status_repository.dart b/lib/data_storage/daily_status_repository.dart new file mode 100644 index 0000000..ebe5c53 --- /dev/null +++ b/lib/data_storage/daily_status_repository.dart @@ -0,0 +1,51 @@ +import 'models/daily_entry_model.dart'; + +class DailyStatusRepository { + DailyEntry? currentDay; + + DailyStatusRepository(); + + void logFeelingMigrainy(bool status) { + if (currentDay == null) { + currentDay = DailyEntry( + date: getCurrentDate(), + feelingMigrainy: status, + tookZomig: false, + hadMigraine: false, + tookPainMeds: false); + } else { + currentDay = DailyEntry( + date: getCurrentDate(), + feelingMigrainy: status, + tookZomig: currentDay!.tookZomig, + hadMigraine: currentDay!.hadMigraine, + tookPainMeds: currentDay!.tookPainMeds + ); + } + } + + void logTookZomig(bool status) { + if (currentDay == null) { + currentDay = DailyEntry( + date: getCurrentDate(), + feelingMigrainy: false, + tookZomig: status, + hadMigraine: false, + tookPainMeds: false); + } else { + currentDay = DailyEntry( + date: getCurrentDate(), + feelingMigrainy: currentDay!.tookZomig, + tookZomig: status, + hadMigraine: currentDay!.hadMigraine, + tookPainMeds: currentDay!.tookPainMeds + ); + } + } + + DateTime getCurrentDate() { + DateTime now = DateTime.now(); + DateTime date = DateTime(now.year, now.month, now.day); + return date; + } +} \ No newline at end of file diff --git a/lib/data_storage/models/daily_entry_model.dart b/lib/data_storage/models/daily_entry_model.dart new file mode 100644 index 0000000..a3ab84a --- /dev/null +++ b/lib/data_storage/models/daily_entry_model.dart @@ -0,0 +1,15 @@ + +class DailyEntry { + final DateTime date; + final bool feelingMigrainy; + final bool tookZomig; + final bool hadMigraine; + final bool tookPainMeds; + + const DailyEntry({ + required this.date, + required this.feelingMigrainy, + required this.tookZomig, + required this.hadMigraine, + required this.tookPainMeds}); +} \ No newline at end of file