WT1.1.6+3 bodyType animation, bug fixes
This commit is contained in:
@@ -21,6 +21,7 @@ class CustomerApi with Logging {
|
||||
}
|
||||
|
||||
Future<void> saveCustomer(Customer customer) async {
|
||||
customer.dateChange = DateTime.now();
|
||||
String body = JsonEncoder().convert(customer.toJson());
|
||||
log(" ===== saving customer id: " + customer.customerId.toString() + ":" + body);
|
||||
await _client.post("customers/" + customer.customerId.toString(), body);
|
||||
@@ -32,6 +33,8 @@ class CustomerApi with Logging {
|
||||
}
|
||||
|
||||
Future<void> addCustomer(Customer customer) async {
|
||||
customer.dateAdd = DateTime.now();
|
||||
customer.dateChange = DateTime.now();
|
||||
String body = JsonEncoder().convert(customer.toJson());
|
||||
log(" ===== add new customer: " + body);
|
||||
await _client.post("customers", body);
|
||||
@@ -84,7 +87,7 @@ class CustomerApi with Logging {
|
||||
Cache().userLoggedIn = customer;
|
||||
final List properties = await this.getActualProperties(customer.customerId);
|
||||
if (properties != null) {
|
||||
this._initProperties(properties);
|
||||
this.initProperties(properties);
|
||||
}
|
||||
} on FormatException {
|
||||
throw new Exception(responseBody);
|
||||
@@ -103,7 +106,7 @@ class CustomerApi with Logging {
|
||||
//log(" ---- Props: " + properties.toJson().toString());
|
||||
//await Cache().initCustomer(customerId);
|
||||
if (properties != null) {
|
||||
this._initProperties(properties);
|
||||
this.initProperties(properties);
|
||||
}
|
||||
} on Exception catch (exception) {
|
||||
log("Exception: " + exception.toString());
|
||||
@@ -113,7 +116,7 @@ class CustomerApi with Logging {
|
||||
}
|
||||
}
|
||||
|
||||
void _initProperties(List<CustomerProperty> customerProperties) {
|
||||
void initProperties(final List<CustomerProperty> customerProperties) {
|
||||
List<Property> properties = Cache().getProperties();
|
||||
Customer customer = Cache().userLoggedIn;
|
||||
customer.properties = LinkedHashMap<String, CustomerProperty>();
|
||||
@@ -190,22 +193,53 @@ class CustomerApi with Logging {
|
||||
return properties;
|
||||
}
|
||||
|
||||
Future<void> addProperty(CustomerProperty property) async {
|
||||
Future<CustomerProperty> addProperty(CustomerProperty property) async {
|
||||
String body = JsonEncoder().convert(property.toJson());
|
||||
log(" ===== add new customer property: " + body);
|
||||
final String responseBody = await _client.post("customer_property", body);
|
||||
CustomerProperty customerProperty;
|
||||
String responseBody;
|
||||
try {
|
||||
responseBody = await _client.post("customer_property", body);
|
||||
log(" responseBody: " + responseBody);
|
||||
int status = jsonDecode(responseBody)['status'];
|
||||
if (status != null) {
|
||||
throw new Exception(jsonDecode(responseBody)['error']);
|
||||
} else {
|
||||
CustomerProperty customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
|
||||
customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
|
||||
if (customerProperty == null) {
|
||||
throw new Exception("Property Insert was not successful");
|
||||
}
|
||||
}
|
||||
} on FormatException {
|
||||
throw new Exception(responseBody);
|
||||
} on Exception catch (e) {
|
||||
throw new Exception(e);
|
||||
}
|
||||
return customerProperty;
|
||||
}
|
||||
|
||||
Future<CustomerProperty> updateProperty(CustomerProperty property) async {
|
||||
String body = JsonEncoder().convert(property.toJson());
|
||||
CustomerProperty customerProperty;
|
||||
log(" ===== update customer property: " + body);
|
||||
String responseBody;
|
||||
try {
|
||||
responseBody = await _client.post("customer_property/update/" + property.customerPropertyId.toString(), body);
|
||||
log(" responseBody: " + responseBody);
|
||||
int status = jsonDecode(responseBody)['status'];
|
||||
if (status != null) {
|
||||
throw new Exception(jsonDecode(responseBody)['error']);
|
||||
} else {
|
||||
customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
|
||||
if (customerProperty == null) {
|
||||
throw new Exception("Property Update was not successful");
|
||||
}
|
||||
}
|
||||
} on FormatException {
|
||||
throw new Exception(responseBody);
|
||||
} on Exception catch (e) {
|
||||
throw new Exception(e);
|
||||
}
|
||||
return customerProperty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,6 @@ import 'package:aitrainer_app/service/logging.dart';
|
||||
class ExerciseApi with Logging {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<List<Exercise>> getExerciseTypes(String param) async {
|
||||
final body = await _client.get("exercises", param);
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<Exercise> exerciseTypes = json.map((exerciseType) => Exercise.fromJson(exerciseType)).toList();
|
||||
|
||||
return exerciseTypes;
|
||||
}
|
||||
|
||||
Future<void> saveExercise(Exercise exercise) async {
|
||||
String body = JsonEncoder().convert(exercise.toJson());
|
||||
log(" ===== saving exercise id: " + exercise.exerciseId.toString() + ":" + body);
|
||||
|
||||
@@ -20,7 +20,7 @@ class ExerciseTreeApi with Logging {
|
||||
if (exerciseTree != null) {
|
||||
await Future.forEach(exerciseTree, (element) async {
|
||||
//exerciseTree.forEach((element) async {
|
||||
element.imageUrl = await _buildImage(element.imageUrl, element.treeId);
|
||||
element.imageUrl = await buildImage(element.imageUrl, element.treeId);
|
||||
});
|
||||
log("ExerciseTree downloaded");
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
@@ -29,7 +29,7 @@ class ExerciseTreeApi with Logging {
|
||||
return exerciseTree;
|
||||
}
|
||||
|
||||
Future<String> _buildImage(String imageUrl, int treeId) async {
|
||||
Future<String> buildImage(String imageUrl, int treeId) async {
|
||||
String assetImage = 'asset/menu/' + imageUrl.substring(7);
|
||||
return await rootBundle.load(assetImage).then((value) {
|
||||
return assetImage;
|
||||
@@ -41,7 +41,7 @@ class ExerciseTreeApi with Logging {
|
||||
}
|
||||
|
||||
Future<List<ExerciseTree>> getExerciseTreeParents(List<ExerciseTree> exerciseTree) async {
|
||||
List<ExerciseTree> copyList = this._copyList(exerciseTree);
|
||||
List<ExerciseTree> copyList = this.copyList(exerciseTree);
|
||||
|
||||
final String body = await _client.get("exercise_tree_parents", "");
|
||||
Iterable json = jsonDecode(body);
|
||||
@@ -71,7 +71,7 @@ class ExerciseTreeApi with Logging {
|
||||
return exerciseTree;
|
||||
}
|
||||
|
||||
List<ExerciseTree> _copyList(List<ExerciseTree> tree) {
|
||||
List<ExerciseTree> copyList(List<ExerciseTree> tree) {
|
||||
final List<ExerciseTree> copyList = List();
|
||||
tree.forEach((element) {
|
||||
final ExerciseTree copy = element.copy(-1);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'package:aitrainer_app/library/image_cache.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
@@ -14,9 +13,8 @@ class ExerciseTypeApi with Logging {
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
||||
if (exerciseTypes != null) {
|
||||
exerciseTypes.forEach((element) async {
|
||||
element.imageUrl = await _buildImage(element.imageUrl, element.exerciseTypeId);
|
||||
//ImageCache().downloadAndSaveImage(element.exerciseTypeId, element.imageUrl);
|
||||
await Future.forEach(exerciseTypes, (element) async {
|
||||
element.imageUrl = await buildImage(element.imageUrl, element.exerciseTypeId);
|
||||
});
|
||||
log("ExerciseTypes downloaded");
|
||||
Cache().setExerciseTypes(exerciseTypes);
|
||||
@@ -25,7 +23,7 @@ class ExerciseTypeApi with Logging {
|
||||
return exerciseTypes;
|
||||
}
|
||||
|
||||
Future<String> _buildImage(String imageUrl, int exerciseTypeId) async {
|
||||
Future<String> buildImage(String imageUrl, int exerciseTypeId) async {
|
||||
if (imageUrl.length > 8) {
|
||||
String assetImage = 'asset/menu/' + imageUrl.substring(7);
|
||||
return rootBundle.load(assetImage).then((value) {
|
||||
@@ -39,16 +37,4 @@ class ExerciseTypeApi with Logging {
|
||||
return imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveExerciseType(ExerciseType exerciseType) async {
|
||||
String body = JsonEncoder().convert(exerciseType.toJson());
|
||||
log(" ===== saving exerciseType id: " + exerciseType.exerciseTypeId.toString() + ":" + body);
|
||||
await _client.post("exercise_type/" + exerciseType.exerciseTypeId.toString(), body);
|
||||
}
|
||||
|
||||
Future<void> addExerciseType(ExerciseType exerciseType) async {
|
||||
String body = JsonEncoder().convert(exerciseType.toJson());
|
||||
log(" ===== add new exerciseType: " + body);
|
||||
await _client.post("exercise_type", body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/model/customer_exercise_device.dart';
|
||||
import 'package:aitrainer_app/model/customer_property.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_device.dart';
|
||||
import 'package:aitrainer_app/model/exercise_result.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree_parents.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
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/service/api.dart';
|
||||
import 'package:aitrainer_app/service/exercise_type_service.dart';
|
||||
import 'package:aitrainer_app/util/not_found_exception.dart';
|
||||
|
||||
import 'customer_service.dart';
|
||||
import 'exercise_tree_service.dart';
|
||||
|
||||
class PackageApi {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<void> getPackage() async {
|
||||
List<ExerciseTree> exerciseTree;
|
||||
List<ExerciseTreeParents> exerciseTreeParents;
|
||||
final body = await _client.get("app_package/", "");
|
||||
|
||||
final List<String> models = body.split("|||");
|
||||
await Future.forEach(models, (element) async {
|
||||
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();
|
||||
Cache().setDevices(devices);
|
||||
} else if (headRecord[0] == "Product") {
|
||||
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();
|
||||
Cache().setProperties(properties);
|
||||
} else if (headRecord[0] == "ExerciseTree") {
|
||||
exerciseTree = json.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree)).toList();
|
||||
} else if (headRecord[0] == "ExerciseType") {
|
||||
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
||||
if (exerciseTypes != null) {
|
||||
await Future.forEach(exerciseTypes, (element) async {
|
||||
element.imageUrl = await ExerciseTypeApi().buildImage(element.imageUrl, element.exerciseTypeId);
|
||||
});
|
||||
Cache().setExerciseTypes(exerciseTypes);
|
||||
}
|
||||
} else if (headRecord[0] == "ExerciseAbility") {
|
||||
} else if (headRecord[0] == "ExerciseTreeParents") {
|
||||
exerciseTreeParents = json.map((exerciseTreeParent) => ExerciseTreeParents.fromJson(exerciseTreeParent)).toList();
|
||||
}
|
||||
});
|
||||
|
||||
exerciseTree = this.getExerciseTreeParents(exerciseTree, exerciseTreeParents);
|
||||
if (exerciseTree != null) {
|
||||
await Future.forEach(exerciseTree, (element) async {
|
||||
element.imageUrl = await ExerciseTreeApi().buildImage(element.imageUrl, element.treeId);
|
||||
});
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
List<ExerciseTree> getExerciseTreeParents(final List<ExerciseTree> exerciseTree, final List<ExerciseTreeParents> exerciseTreeParents) {
|
||||
List<ExerciseTree> copyList = ExerciseTreeApi().copyList(exerciseTree);
|
||||
|
||||
int treeIndex = 0;
|
||||
copyList.forEach((element) async {
|
||||
int index = 0;
|
||||
exerciseTreeParents.forEach((parent) {
|
||||
if (parent.exerciseTreeChildId == element.treeId) {
|
||||
if (index > 0) {
|
||||
ExerciseTree newElement = element.copy(parent.exerciseTreeParentId);
|
||||
exerciseTree.add(newElement);
|
||||
} else {
|
||||
element.parentId = parent.exerciseTreeParentId;
|
||||
exerciseTree[treeIndex].parentId = parent.exerciseTreeParentId;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
});
|
||||
|
||||
treeIndex++;
|
||||
});
|
||||
|
||||
return exerciseTree;
|
||||
}
|
||||
|
||||
Future<void> getCustomerPackage(int customerId) async {
|
||||
try {
|
||||
final body = await _client.get("app_customer_package/" + customerId.toString(), "");
|
||||
|
||||
final List<String> models = body.split("|||");
|
||||
await Future.forEach(models, (element) async {
|
||||
final List<String> headRecord = element.split("***");
|
||||
//print("Class " + headRecord[0]);
|
||||
if (headRecord[0] == "Customer") {
|
||||
Customer customer = Customer.fromJson(jsonDecode(headRecord[1]));
|
||||
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();
|
||||
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();
|
||||
Cache().setExercises(exercises);
|
||||
} else if (headRecord[0] == "ProductTest") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<ProductTest> productTests = json.map((productTest) => ProductTest.fromJson(productTest)).toList();
|
||||
Cache().productTests = productTests;
|
||||
} else if (headRecord[0] == "Purchase") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
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();
|
||||
CustomerApi().initProperties(customerProperties);
|
||||
} else if (headRecord[0] == "ExerciseResult") {
|
||||
final Iterable json = jsonDecode(headRecord[1]);
|
||||
final List<ExerciseResult> exerciseResults = json.map((exerciseResult) {
|
||||
ExerciseResult item = ExerciseResult.fromJson(exerciseResult);
|
||||
return item;
|
||||
}).toList();
|
||||
// ToDo
|
||||
}
|
||||
});
|
||||
} on NotFoundException catch (_) {
|
||||
throw Exception("Please log in");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:aitrainer_app/model/tracking.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'dart:convert';
|
||||
import 'api.dart';
|
||||
|
||||
class TrackingApi with Logging {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<void> saveTracking(Tracking tracking) async {
|
||||
String body = JsonEncoder().convert(tracking.toJson());
|
||||
log(" ===== saving tracking:" + body);
|
||||
await _client.post("tracking/", body);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user