This commit is contained in:
bossanyit
2022-10-18 18:48:18 +02:00
parent fb01016494
commit b5e387ee2a
9 changed files with 113 additions and 107 deletions
+29 -67
View File
@@ -44,62 +44,44 @@ class PackageApi {
final List<String> headRecord = element.split("***");
final Iterable json = jsonDecode(headRecord[1]);
if (headRecord[0] == "ExerciseDevice") {
final List<ExerciseDevice> devices =
json.map((device) => ExerciseDevice.fromJson(device)).toList();
final List<ExerciseDevice> devices = json.map((device) => ExerciseDevice.fromJson(device)).toList();
Cache().setDevices(devices);
} else if (headRecord[0] == "Product") {
final List<Product> products =
json.map((product) => Product.fromJson(product)).toList();
final List<Product> products = json.map((product) => Product.fromJson(product)).toList();
Cache().setProducts(products);
} else if (headRecord[0] == "Property") {
final List<Property> properties =
json.map((property) => Property.fromJson(property)).toList();
final List<Property> properties = json.map((property) => Property.fromJson(property)).toList();
Cache().setProperties(properties);
} else if (headRecord[0] == "ExerciseTree") {
exerciseTree = json
.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree))
.toList();
exerciseTree = json.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree)).toList();
} else if (headRecord[0] == "ExerciseType") {
final List<ExerciseType> exerciseTypes = json
.map((exerciseType) => ExerciseType.fromJson(exerciseType))
.toList();
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
await Future.forEach(exerciseTypes, (elem) async {
final ExerciseType exerciseType = elem as ExerciseType;
exerciseType.imageUrl = await ExerciseTypeApi()
.buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
exerciseType.imageUrl = await ExerciseTypeApi().buildImage(exerciseType.imageUrl, exerciseType.exerciseTypeId);
});
Cache().setExerciseTypes(exerciseTypes);
} else if (headRecord[0] == "ExerciseAbility") {
} else if (headRecord[0] == "ExercisePlanTemplate") {
final List<ExercisePlanTemplate> exercisePlanTemplates = json
.map((exercisePlanTemplate) =>
ExercisePlanTemplate.fromJson(exercisePlanTemplate))
.toList();
final List<ExercisePlanTemplate> exercisePlanTemplates =
json.map((exercisePlanTemplate) => ExercisePlanTemplate.fromJson(exercisePlanTemplate)).toList();
Cache().setExercisePlanTemplates(exercisePlanTemplates);
} else if (headRecord[0] == "ExerciseTreeParents") {
exerciseTreeParents = json
.map((exerciseTreeParent) =>
ExerciseTreeParents.fromJson(exerciseTreeParent))
.toList();
exerciseTreeParents = json.map((exerciseTreeParent) => ExerciseTreeParents.fromJson(exerciseTreeParent)).toList();
} else if (headRecord[0] == "Evaluation") {
final List<Evaluation> evaluations =
json.map((evaluation) => Evaluation.fromJson(evaluation)).toList();
final List<Evaluation> evaluations = json.map((evaluation) => Evaluation.fromJson(evaluation)).toList();
Cache().evaluations = evaluations;
} else if (headRecord[0] == "Sport") {
final List<Sport> sports =
json.map((sport) => Sport.fromJson(sport)).toList();
final List<Sport> sports = json.map((sport) => Sport.fromJson(sport)).toList();
Cache().setSports(sports);
} else if (headRecord[0] == "Tutorial") {
final Iterable json = jsonDecode(headRecord[1]);
final List<Tutorial> tutorials =
json.map((tutorial) => Tutorial.fromJson(tutorial)).toList();
final List<Tutorial> tutorials = json.map((tutorial) => Tutorial.fromJson(tutorial)).toList();
Cache().setTutorials(tutorials);
} else if (headRecord[0] == "Description") {
final Iterable json = jsonDecode(headRecord[1]);
final List<Description>? descriptions = json
.map((description) => Description.fromJson(description))
.toList();
final List<Description>? descriptions = json.map((description) => Description.fromJson(description)).toList();
//print("Description: $descriptions");
Cache().setDescriptions(descriptions);
} else if (headRecord[0] == "Faq") {
@@ -109,8 +91,7 @@ class PackageApi {
Cache().setFaqs(faqs);
} else if (headRecord[0] == "TrainingPlan") {
final Iterable json = jsonDecode(headRecord[1]);
final List<TrainingPlan>? plans =
json.map((plan) => TrainingPlan.fromJson(plan)).toList();
final List<TrainingPlan>? plans = json.map((plan) => TrainingPlan.fromJson(plan)).toList();
List<TrainingPlan> activePlans = [];
if (plans != null) {
@@ -123,38 +104,31 @@ class PackageApi {
Cache().setTrainingPlans(activePlans);
} else if (headRecord[0] == "SplitTests") {
final Iterable json = jsonDecode(headRecord[1]);
final List<SplitTest>? tests =
json.map((test) => SplitTest.fromJson(test)).toList();
final List<SplitTest>? tests = json.map((test) => SplitTest.fromJson(test)).toList();
//print("A/B tests: $tests");
Cache().setSplitTests(tests);
} else if (headRecord[0] == "TrainingPlanDay") {
final Iterable json = jsonDecode(headRecord[1]);
final List<TrainingPlanDay>? days =
json.map((day) => TrainingPlanDay.fromJson(day)).toList();
final List<TrainingPlanDay>? days = json.map((day) => TrainingPlanDay.fromJson(day)).toList();
Cache().setTrainingPlanDays(days);
}
});
exerciseTree =
this.getExerciseTreeParents(exerciseTree, exerciseTreeParents);
exerciseTree = this.getExerciseTreeParents(exerciseTree, exerciseTreeParents);
await Future.forEach(exerciseTree, (element) async {
ExerciseTree tree = element as ExerciseTree;
tree.imageUrl =
await ExerciseTreeApi().buildImage(tree.imageUrl, tree.treeId);
tree.imageUrl = await ExerciseTreeApi().buildImage(tree.imageUrl, tree.treeId);
});
Cache().setExerciseTree(exerciseTree);
TrainingPlanDayRepository trainingPlanDayRepository =
TrainingPlanDayRepository();
TrainingPlanDayRepository trainingPlanDayRepository = TrainingPlanDayRepository();
trainingPlanDayRepository.assignTrainingPlanDays();
return;
}
List<ExerciseTree> getExerciseTreeParents(
final List<ExerciseTree> exerciseTree,
final List<ExerciseTreeParents> exerciseTreeParents) {
List<ExerciseTree> getExerciseTreeParents(final List<ExerciseTree> exerciseTree, final List<ExerciseTreeParents> exerciseTreeParents) {
List<ExerciseTree> copyList = ExerciseTreeApi().copyList(exerciseTree);
int treeIndex = 0;
@@ -184,8 +158,7 @@ class PackageApi {
Future<void> getCustomerPackage(int customerId) async {
try {
final body = await _client.get(
"app_customer_package/" + customerId.toString(), "");
final body = await _client.get("app_customer_package/" + customerId.toString(), "");
final List<String> models = body.split("|||");
await Future.forEach(models, (elem) async {
@@ -197,33 +170,24 @@ class PackageApi {
Cache().userLoggedIn = customer;
} else if (headRecord[0] == "CustomerExerciseDevice") {
final Iterable json = jsonDecode(headRecord[1]);
final List<CustomerExerciseDevice> devices = json
.map((device) => CustomerExerciseDevice.fromJson(device))
.toList();
final List<CustomerExerciseDevice> devices = json.map((device) => CustomerExerciseDevice.fromJson(device)).toList();
Cache().setCustomerDevices(devices);
// ToDo
} else if (headRecord[0] == "Exercises") {
final Iterable json = jsonDecode(headRecord[1]);
final List<Exercise> exercises = json
.map((exerciseType) => Exercise.fromJson(exerciseType))
.toList();
final List<Exercise> exercises = json.map((exerciseType) => Exercise.fromJson(exerciseType)).toList();
Cache().setExercises(exercises);
} else if (headRecord[0] == "Purchase") {
final Iterable json = jsonDecode(headRecord[1]);
final List<Purchase> purchases =
json.map((purchase) => Purchase.fromJson(purchase)).toList();
final List<Purchase> purchases = json.map((purchase) => Purchase.fromJson(purchase)).toList();
Cache().setPurchases(purchases);
} else if (headRecord[0] == "CustomerProperty") {
final Iterable json = jsonDecode(headRecord[1]);
final List<CustomerProperty> customerProperties = json
.map((property) => CustomerProperty.fromJson(property))
.toList();
final List<CustomerProperty> customerProperties = json.map((property) => CustomerProperty.fromJson(property)).toList();
CustomerApi().initProperties(customerProperties);
} else if (headRecord[0] == "CustomerPropertyAll") {
final Iterable json = jsonDecode(headRecord[1]);
final List<CustomerProperty> allCustomerProperties = json
.map((property) => CustomerProperty.fromJson(property))
.toList();
final List<CustomerProperty> allCustomerProperties = json.map((property) => CustomerProperty.fromJson(property)).toList();
print(" All Properties ---- $allCustomerProperties");
Cache().setCustomerPropertyAll(allCustomerProperties);
} else if (headRecord[0] == "ExerciseResult") {
@@ -235,14 +199,12 @@ class PackageApi {
// ToDo */
} else if (headRecord[0] == "CustomerActivity") {
final Iterable json = jsonDecode(headRecord[1]);
final List<CustomerActivity> customerActivities = json
.map((activity) => CustomerActivity.fromJson(activity))
.toList();
final List<CustomerActivity> customerActivities = json.map((activity) => CustomerActivity.fromJson(activity)).toList();
Cache().setCustomerActivities(customerActivities);
}
});
} on NotFoundException catch (_) {
throw Exception("Please log in");
} on NotFoundException catch (e) {
throw Exception("Please log in $e");
}
}
}