WT 1.1.0+35 Design, Menü filter, Test Server
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:aitrainer_app/model/cache.dart';
|
||||
class APIClient with Common {
|
||||
Future<String> get(String endPoint, String param) async {
|
||||
final url = Cache.getBaseUrl() + endPoint + param;
|
||||
print("-------- API get " + url);
|
||||
String authToken = Cache().getAuthToken();
|
||||
if (authToken.length == 0) {
|
||||
var responseJson = await APIClient.authenticateUser(Cache.username, Cache.password);
|
||||
|
||||
@@ -2,18 +2,61 @@ import 'dart:convert';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree_parents.dart';
|
||||
import 'api.dart';
|
||||
|
||||
class ExerciseTreeApi {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<List<ExerciseTree>> getExerciseTree() async {
|
||||
final body = await _client.get("exercise_tree", "");
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<ExerciseTree> exerciseTree = json.map((exerciseTree) =>
|
||||
ExerciseTree.fromJson(exerciseTree)).toList();
|
||||
final String body = await _client.get("exercise_tree", "");
|
||||
Iterable json = jsonDecode(body);
|
||||
List<ExerciseTree> exerciseTree = json.map((exerciseTree) => ExerciseTree.fromJson(exerciseTree)).toList();
|
||||
|
||||
exerciseTree = await getExerciseTreeParents(exerciseTree);
|
||||
|
||||
Cache().setExerciseTree(exerciseTree);
|
||||
return exerciseTree;
|
||||
}
|
||||
|
||||
Future<List<ExerciseTree>> getExerciseTreeParents(List<ExerciseTree> exerciseTree) async {
|
||||
List<ExerciseTree> copyList = this._copyList(exerciseTree);
|
||||
|
||||
final String body = await _client.get("exercise_tree_parents", "");
|
||||
Iterable json = jsonDecode(body);
|
||||
final List<ExerciseTreeParents> exerciseTreeParents =
|
||||
json.map((exerciseTreeParent) => ExerciseTreeParents.fromJson(exerciseTreeParent)).toList();
|
||||
|
||||
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);
|
||||
print("ExerciseTree " + newElement.toJson().toString());
|
||||
} else {
|
||||
element.parentId = parent.exerciseTreeParentId;
|
||||
exerciseTree[treeIndex].parentId = parent.exerciseTreeParentId;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
});
|
||||
print("ExerciseTree " + element.toJson().toString());
|
||||
treeIndex++;
|
||||
});
|
||||
|
||||
return exerciseTree;
|
||||
}
|
||||
|
||||
List<ExerciseTree> _copyList(List<ExerciseTree> tree) {
|
||||
final List<ExerciseTree> copyList = List();
|
||||
tree.forEach((element) {
|
||||
final ExerciseTree copy = element.copy(-1);
|
||||
copyList.add(copy);
|
||||
});
|
||||
|
||||
return copyList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,31 +3,26 @@ import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
|
||||
|
||||
class ExerciseTypeApi {
|
||||
final APIClient _client=new APIClient();
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<List<ExerciseType>> getExerciseTypes() async {
|
||||
final body = await _client.get("exercise_type/active", "");
|
||||
final body = await _client.get("exercise_type", "");
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<ExerciseType> exerciseTypes = json.map( (exerciseType) => ExerciseType.fromJson(exerciseType) ).toList();
|
||||
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
|
||||
Cache().setExerciseTypes(exerciseTypes);
|
||||
return exerciseTypes;
|
||||
}
|
||||
|
||||
Future<void> saveExerciseType(ExerciseType exerciseType) async {
|
||||
String body = JsonEncoder().convert(exerciseType.toJson());
|
||||
print(" ===== saving exerciseType id: " + exerciseType.exerciseTypeId.toString() + ":" + body );
|
||||
await _client.post(
|
||||
"exercise_type/"+exerciseType.exerciseTypeId.toString(),
|
||||
body);
|
||||
print(" ===== 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());
|
||||
print(" ===== add new exerciseType: " + body );
|
||||
await _client.post(
|
||||
"exercise_type",
|
||||
body);
|
||||
print(" ===== add new exerciseType: " + body);
|
||||
await _client.post("exercise_type", body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user