Aitrainer_app 1.1.1
test menu, customer modification, exercise save images, localization
This commit is contained in:
+20
-5
@@ -7,11 +7,18 @@ class APIClient extends ChangeNotifier {
|
||||
|
||||
Future<String> get(String endPoint, String param) async {
|
||||
final url = Auth.getBaseUrl() + endPoint + param;
|
||||
Auth auth = Auth();
|
||||
String authToken = Auth().getAuthToken();
|
||||
if ( authToken.length == 0 ) {
|
||||
var responseJson = await APIClient.authenticateUser(
|
||||
Auth.username,
|
||||
Auth.password
|
||||
);
|
||||
authToken = responseJson['token'];
|
||||
}
|
||||
final response = await http.get(url,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization' : "Bearer " + auth.getAuthToken() }
|
||||
'Authorization' : "Bearer " + authToken }
|
||||
);
|
||||
notifyListeners();
|
||||
if(response.statusCode == 200) {
|
||||
@@ -24,11 +31,18 @@ class APIClient extends ChangeNotifier {
|
||||
Future<String> post(String endPoint, String body) async {
|
||||
final url = Auth.getBaseUrl() + endPoint;
|
||||
print(" ------------ http/post endpoint $endPoint body $body - url: $url ");
|
||||
Auth auth = Auth();
|
||||
String authToken = Auth().getAuthToken();
|
||||
if ( authToken.length == 0 ) {
|
||||
var responseJson = await APIClient.authenticateUser(
|
||||
Auth.username,
|
||||
Auth.password
|
||||
);
|
||||
authToken = responseJson['token'];
|
||||
}
|
||||
final response = await http.post(url,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization' : "Bearer " + auth.getAuthToken()
|
||||
'Authorization' : "Bearer " + authToken
|
||||
},
|
||||
body: body
|
||||
);
|
||||
@@ -59,7 +73,8 @@ class APIClient extends ChangeNotifier {
|
||||
return responseJson;
|
||||
|
||||
} catch (exception) {
|
||||
return { "error" : "Network error, try again later"};
|
||||
return { "error" : "Network error, try again later "
|
||||
+ exception.toString()};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,8 @@ class CustomerApi {
|
||||
final String responseBody = await _client.post(
|
||||
"registration",
|
||||
body);
|
||||
Auth auth = Auth();
|
||||
Customer customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
auth.afterRegistration(customer);
|
||||
Auth().afterRegistration(customer);
|
||||
|
||||
}
|
||||
|
||||
@@ -49,9 +48,8 @@ class CustomerApi {
|
||||
final String responseBody = await _client.post(
|
||||
"login",
|
||||
body);
|
||||
Auth auth = Auth();
|
||||
Customer customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
auth.afterRegistration(customer);
|
||||
Auth().afterRegistration(customer);
|
||||
}
|
||||
|
||||
Future<void> getCustomer(int customerId) async {
|
||||
@@ -60,8 +58,7 @@ class CustomerApi {
|
||||
final String responseBody = await _client.get(
|
||||
"customers/"+customerId.toString(),
|
||||
body);
|
||||
Auth auth = Auth();
|
||||
Customer customer = Customer.fromJson(jsonDecode(responseBody));
|
||||
auth.afterRegistration(customer);
|
||||
Auth().afterRegistration(customer);
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,12 @@ class ExerciseApi {
|
||||
body);
|
||||
}
|
||||
|
||||
Future<List<Exercise>> getExercisesByCustomer(int customerId ) async {
|
||||
final body = await _client.get("exercises/customer/", customerId.toString() );
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<Exercise> exercises = json.map( (exercise) => Exercise.fromJson(exercise) ).toList();
|
||||
|
||||
return exercises;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'package:aitrainer_app/model/auth.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
|
||||
@@ -10,7 +11,7 @@ class ExerciseTypeApi {
|
||||
final body = await _client.get("exercise_type", param);
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<ExerciseType> exerciseTypes = json.map( (exerciseType) => ExerciseType.fromJson(exerciseType) ).toList();
|
||||
|
||||
Auth().setExerciseTypes(exerciseTypes);
|
||||
return exerciseTypes;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user