v1.1 dart fix

This commit is contained in:
bossanyit
2023-05-14 09:53:18 +02:00
parent 7e4934f15e
commit 14731c5ee7
9 changed files with 68 additions and 64 deletions
+27 -27
View File
@@ -35,7 +35,7 @@ class CustomerApi with Logging {
Future<void> deactivateCustomer(int customerId) async {
log(" ===== deactivate : $customerId");
await _client.post("customers/deactivate/$customerId", "");
}
}
Future<void> addCustomer(Customer customer) async {
customer.dateAdd = DateTime.now();
@@ -85,7 +85,7 @@ class CustomerApi with Logging {
final String responseBody = await _client.get("customers/find_by_email/$email", "");
Customer customer;
try {
customer = Customer.fromJson(jsonDecode(responseBody));
customer = Customer.fromJson(jsonDecode(responseBody));
if (customer.firebaseUid == null) {
await updateFirebaseUid(customer.customerId!, Cache().firebaseUid!);
}
@@ -128,32 +128,32 @@ class CustomerApi with Logging {
if (properties != null) {
// reset Properties
properties.forEach((property) {
for (var property in properties) {
CustomerProperty customerProperty =
CustomerProperty(propertyId: property.propertyId, customerId: customer.customerId!, dateAdd: DateTime.now(), propertyValue: 0);
customer.properties[property.propertyName] = customerProperty;
});
}
customerProperties!.forEach((customerProperty) {
properties.forEach((property) {
for (var customerProperty in customerProperties!) {
for (var property in properties) {
if (customerProperty.propertyId == property.propertyId) {
customer.properties[property.propertyName] = customerProperty;
}
});
});
}
}
}
}
Future<Customer> getTrainee(int customerId) async {
String body = "";
Customer customer;
log(" ===== get Trainee customer by id: " + customerId.toString());
log(" ===== get Trainee customer by id: $customerId");
try {
final String responseBody = await _client.get("customers/" + customerId.toString(), body);
final String responseBody = await _client.get("customers/$customerId", body);
customer = Customer.fromJson(jsonDecode(responseBody));
log(" --- Trainee: " + customer.toJson().toString());
log(" --- Trainee: ${customer.toJson()}");
} catch (exception) {
log("Exception: " + exception.toString());
log("Exception: $exception");
throw Exception(exception);
}
return customer;
@@ -164,11 +164,11 @@ class CustomerApi with Logging {
log("Get trainees list");
try {
String body = "";
final String responseBody = await _client.get("customers/trainees/" + trainerId.toString(), body);
final String responseBody = await _client.get("customers/trainees/$trainerId", body);
final Iterable json = jsonDecode(responseBody);
trainees = json.map((customer) => Customer.fromJson(customer)).toList();
} catch (exception) {
log("Exception: " + exception.toString());
log("Exception: $exception");
throw Exception(exception);
}
return trainees;
@@ -195,45 +195,45 @@ class CustomerApi with Logging {
}
Future<CustomerProperty> addProperty(CustomerProperty property) async {
String body = JsonEncoder().convert(property.toJson());
log(" ===== add new customer property: " + body);
String body = const JsonEncoder().convert(property.toJson());
log(" ===== add new customer property: $body");
CustomerProperty customerProperty;
String? responseBody;
try {
responseBody = await _client.post("customer_property", body);
log(" responseBody: " + responseBody);
log(" responseBody: $responseBody");
int? status = jsonDecode(responseBody)['status'];
if (status != null) {
throw new Exception(jsonDecode(responseBody)['error']);
throw Exception(jsonDecode(responseBody)['error']);
} else {
customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
}
} on FormatException {
throw new Exception(responseBody);
throw Exception(responseBody);
} on Exception catch (e) {
throw new Exception(e);
throw Exception(e);
}
return customerProperty;
}
Future<CustomerProperty> updateProperty(CustomerProperty property) async {
String body = JsonEncoder().convert(property.toJson());
String body = const JsonEncoder().convert(property.toJson());
CustomerProperty? customerProperty;
log(" ===== update customer property: " + body);
log(" ===== update customer property: $body");
String? responseBody;
try {
responseBody = await _client.post("customer_property/update/" + property.customerPropertyId.toString(), body);
log(" responseBody: " + responseBody);
responseBody = await _client.post("customer_property/update/${property.customerPropertyId}", body);
log(" responseBody: $responseBody");
int? status = jsonDecode(responseBody)['status'];
if (status != null) {
throw new Exception(jsonDecode(responseBody)['error']);
throw Exception(jsonDecode(responseBody)['error']);
} else {
customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
}
} on FormatException {
throw new Exception(responseBody);
throw Exception(responseBody);
} on Exception catch (e) {
throw new Exception(e);
throw Exception(e);
}
return customerProperty;
}
+2 -2
View File
@@ -51,7 +51,7 @@ class ExerciseTreeApi with Logging {
int treeIndex = 0;
copyList.forEach((element) async {
int index = 0;
exerciseTreeParents.forEach((parent) {
for (var parent in exerciseTreeParents) {
if (parent.exerciseTreeChildId == element.treeId) {
if (index > 0) {
ExerciseTree newElement = element.copy(parent.exerciseTreeParentId);
@@ -64,7 +64,7 @@ class ExerciseTreeApi with Logging {
}
index++;
}
});
}
treeIndex++;
});
return exerciseTree;
+2 -2
View File
@@ -134,7 +134,7 @@ class PackageApi {
int treeIndex = 0;
copyList.forEach((element) async {
int index = 0;
exerciseTreeParents.forEach((parent) {
for (var parent in exerciseTreeParents) {
if (parent.exerciseTreeChildId == element.treeId) {
if (index > 0) {
ExerciseTree newElement = element.copy(parent.exerciseTreeParentId);
@@ -148,7 +148,7 @@ class PackageApi {
}
index++;
}
});
}
treeIndex++;
});