WT 1.1.8+1 TrainingPlan
This commit is contained in:
@@ -13,19 +13,19 @@ class ExerciseTreeApi with Logging {
|
||||
Future<List<ExerciseTree>> getExerciseTree() async {
|
||||
final String body = await _client.get("exercise_tree", "");
|
||||
Iterable json = jsonDecode(body);
|
||||
List<ExerciseTree>? exerciseTree = json.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree)).toList();
|
||||
List<ExerciseTree>? exerciseTrees = json.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree)).toList();
|
||||
|
||||
exerciseTree = await getExerciseTreeParents(exerciseTree);
|
||||
exerciseTrees = await getExerciseTreeParents(exerciseTrees);
|
||||
|
||||
await Future.forEach(exerciseTree, (element) async {
|
||||
await Future.forEach(exerciseTrees, (element) async {
|
||||
ExerciseTree exerciseTree = element as ExerciseTree;
|
||||
exerciseTree.imageUrl = await buildImage(exerciseTree.imageUrl, exerciseTree.treeId);
|
||||
});
|
||||
exerciseTree = await getExerciseTreeParents(exerciseTree);
|
||||
log("ExerciseTree downloaded");
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
exerciseTrees = await getExerciseTreeParents(exerciseTrees);
|
||||
log("ExerciseTree downloaded $exerciseTrees");
|
||||
Cache().setExerciseTree(exerciseTrees);
|
||||
|
||||
return exerciseTree;
|
||||
return exerciseTrees;
|
||||
}
|
||||
|
||||
Future<String> buildImage(String imageUrl, int treeId) async {
|
||||
|
||||
@@ -18,6 +18,7 @@ import 'package:aitrainer_app/model/product.dart';
|
||||
import 'package:aitrainer_app/model/product_test.dart';
|
||||
import 'package:aitrainer_app/model/property.dart';
|
||||
import 'package:aitrainer_app/model/purchase.dart';
|
||||
import 'package:aitrainer_app/model/training_plan.dart';
|
||||
import 'package:aitrainer_app/model/tutorial.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
import 'package:aitrainer_app/service/exercise_type_service.dart';
|
||||
@@ -86,6 +87,11 @@ class PackageApi {
|
||||
final List<Faq>? faqs = json.map((faq) => Faq.fromJson(faq)).toList();
|
||||
//print("Faq: $faqs");
|
||||
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();
|
||||
|
||||
Cache().setTrainingPlans(plans);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -95,6 +101,7 @@ class PackageApi {
|
||||
ExerciseTree tree = element as ExerciseTree;
|
||||
tree.imageUrl = await ExerciseTreeApi().buildImage(tree.imageUrl, tree.treeId);
|
||||
});
|
||||
//print("tree: $exerciseTree");
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:aitrainer_app/model/customer_training_plan.dart';
|
||||
import 'package:aitrainer_app/model/customer_training_plan_exercise.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
|
||||
class TrainingPlanApi with Logging {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<CustomerTrainingPlan> saveCustomerTrainingPlan(CustomerTrainingPlan plan) async {
|
||||
String body = JsonEncoder().convert(plan.toJson());
|
||||
log(" ===== saving customer training plan:" + body);
|
||||
final String response = await _client.post("customer_training_plan/", body);
|
||||
final CustomerTrainingPlan saved = CustomerTrainingPlan.fromJson(jsonDecode(response));
|
||||
return saved;
|
||||
}
|
||||
|
||||
Future<CustomerTrainingPlanExercise> saveCustomerTrainingPlanExercise(CustomerTrainingPlanExercise planExercise) async {
|
||||
String body = JsonEncoder().convert(planExercise.toJson());
|
||||
log(" ===== saving customer training plan exercise:" + body);
|
||||
final String response = await _client.post("customer_training_plan_exercise/", body);
|
||||
final CustomerTrainingPlanExercise saved = CustomerTrainingPlanExercise.fromJson(jsonDecode(response));
|
||||
return saved;
|
||||
}
|
||||
|
||||
Future<CustomerTrainingPlan> updateCustomerTrainingPlan(CustomerTrainingPlan plan, int customerTrainingPlanId) async {
|
||||
String body = JsonEncoder().convert(plan.toJson());
|
||||
log(" ===== update customer training plan:" + body);
|
||||
final String response = await _client.post("customer_training_plan/update/$customerTrainingPlanId", body);
|
||||
final CustomerTrainingPlan saved = CustomerTrainingPlan.fromJson(jsonDecode(response));
|
||||
return saved;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user