-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#61 - task(firestore service): add converters for firestore data
While this solution comes with quite a bit of boilerplate code, this seems to be the most straight forward way without any auto generation of code from mapper libraries.
- Loading branch information
1 parent
8b32e1b
commit 0ec3e7c
Showing
7 changed files
with
102 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abstract class JsonSerializable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
typedef FirestoreJson = Map<String, dynamic>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:lifting_progress_tracker/firebase/firestore_json.dart'; | ||
import 'package:lifting_progress_tracker/training_plan/models/training_plan_entry.dart'; | ||
|
||
class TrainingPlan { | ||
Map<String, TrainingPlanEntry> planEntries; | ||
|
||
TrainingPlan({required this.planEntries}); | ||
|
||
TrainingPlan.fromJson(FirestoreJson json) | ||
: planEntries = json.map( | ||
(key, value) => MapEntry( | ||
key, | ||
TrainingPlanEntry.fromJson(value as FirestoreJson), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:lifting_progress_tracker/firebase/firestore_json.dart'; | ||
|
||
class TrainingPlanEntry { | ||
String repeats; | ||
String exerciseName; | ||
String weight; | ||
|
||
TrainingPlanEntry({ | ||
required this.repeats, | ||
required this.exerciseName, | ||
required this.weight, | ||
}); | ||
|
||
TrainingPlanEntry.fromJson(FirestoreJson json) | ||
: repeats = json["repeats"] as String, | ||
exerciseName = json["exerciseName"] as String, | ||
weight = json["weight"] as String; | ||
|
||
FirestoreJson toJson() { | ||
return { | ||
"repeats": repeats, | ||
"exerciseName": exerciseName, | ||
"weight": weight, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:lifting_progress_tracker/firebase/firestore_json.dart'; | ||
import 'package:lifting_progress_tracker/training_plan/models/training_plan.dart'; | ||
|
||
class TrainingPlanList { | ||
Map<String, TrainingPlan> trainingPlanList; | ||
|
||
TrainingPlanList({required this.trainingPlanList}); | ||
|
||
TrainingPlanList.fromJson(FirestoreJson json) | ||
: trainingPlanList = json.map( | ||
(key, value) => MapEntry( | ||
key, | ||
TrainingPlan.fromJson(value as FirestoreJson), | ||
), | ||
); | ||
|
||
FirestoreJson toJson() { | ||
return { | ||
"trainingPlanList": trainingPlanList, | ||
}; | ||
} | ||
} |