wt1.1a flutter_bloc
This commit is contained in:
@@ -39,8 +39,13 @@ class CustomerApi {
|
||||
body);
|
||||
Customer customer;
|
||||
try {
|
||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
Auth().afterRegistration(customer);
|
||||
int status = jsonDecode(responseBody)['status'];
|
||||
if ( status != null ) {
|
||||
throw new Exception(jsonDecode(responseBody)['error']);
|
||||
} else {
|
||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
Auth().afterRegistration(customer);
|
||||
}
|
||||
} on FormatException catch(exception) {
|
||||
throw new Exception(responseBody);
|
||||
}
|
||||
@@ -56,7 +61,7 @@ class CustomerApi {
|
||||
Customer customer;
|
||||
try {
|
||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
Auth().afterRegistration(customer);
|
||||
await Auth().afterLogin(customer);
|
||||
} on FormatException catch(exception) {
|
||||
throw new Exception(responseBody);
|
||||
}
|
||||
@@ -66,10 +71,17 @@ class CustomerApi {
|
||||
Future<void> getCustomer(int customerId) async {
|
||||
String body = "";
|
||||
print(" ===== get the customer by id: " + customerId.toString() );
|
||||
final String responseBody = await _client.get(
|
||||
"customers/"+customerId.toString(),
|
||||
body);
|
||||
Customer customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
Auth().afterRegistration(customer);
|
||||
try {
|
||||
final String responseBody = await _client.get(
|
||||
"customers/"+customerId.toString(),
|
||||
body);
|
||||
Customer customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
Auth().afterRegistration(customer);
|
||||
} catch (exception) {
|
||||
print ("Exception: " + exception.toString());
|
||||
print (" === go to registration ");
|
||||
Auth().logout();
|
||||
Auth().startPage = "registration";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:aitrainer_app/model/auth.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.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();
|
||||
Auth().setExerciseTree(exerciseTree);
|
||||
return exerciseTree;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import 'package:aitrainer_app/service/api.dart';
|
||||
class ExerciseTypeApi {
|
||||
final APIClient _client=new APIClient();
|
||||
|
||||
Future<List<ExerciseType>> getExerciseTypes(String param) async {
|
||||
final body = await _client.get("exercise_type", param);
|
||||
Future<List<ExerciseType>> getExerciseTypes() async {
|
||||
final body = await _client.get("exercise_type/active", "");
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<ExerciseType> exerciseTypes = json.map( (exerciseType) => ExerciseType.fromJson(exerciseType) ).toList();
|
||||
Auth().setExerciseTypes(exerciseTypes);
|
||||
|
||||
Reference in New Issue
Block a user