Aitrainer_app 0.0.1
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class APIClient {
|
||||
final String _baseUrl = 'http://andio.eu:8888/api/';
|
||||
|
||||
Future<String> get(String endPoint, String param) async {
|
||||
final url = _baseUrl + endPoint + param;
|
||||
final response = await http.get(url, headers: {'Content-Type': 'application/json'});
|
||||
if(response.statusCode == 200) {
|
||||
return utf8.decode(response.bodyBytes);
|
||||
} else {
|
||||
throw Exception("Unable to perform HTTP request!");
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> post(String endPoint, String body) async {
|
||||
final url = _baseUrl + endPoint;
|
||||
print(" ------------ http/post endpoint $endPoint body $body");
|
||||
final response = await http.post(url,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: body
|
||||
);
|
||||
print(" ------------ response: " + response.body.toString());
|
||||
return response.body;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'dart:convert';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
|
||||
|
||||
class CustomerApi {
|
||||
final APIClient _client=new APIClient();
|
||||
|
||||
Future<List<Customer>> getRealCustomers(String param) async {
|
||||
final body = await _client.get("customers/", param);
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<Customer> customers = json.map( (customer) => Customer.fromJson(customer) ).toList();
|
||||
|
||||
return customers;
|
||||
}
|
||||
|
||||
Future<void> saveCustomer(Customer customer) async {
|
||||
String body = JsonEncoder().convert(customer.toJson());
|
||||
print(" ===== saving exerciseType id: " + customer.customerId.toString() + ":" + body );
|
||||
await _client.post(
|
||||
"customers/"+customer.customerId.toString(),
|
||||
body);
|
||||
}
|
||||
|
||||
Future<void> addCustomer(Customer customer) async {
|
||||
String body = JsonEncoder().convert(customer.toJson());
|
||||
print(" ===== add new customer: " + body );
|
||||
await _client.post(
|
||||
"customers",
|
||||
body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'dart:convert';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
|
||||
|
||||
class ExerciseApi {
|
||||
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());
|
||||
print(" ===== saving exercise id: " + exercise.exerciseId.toString() + ":" + body );
|
||||
await _client.post(
|
||||
"exercises/"+exercise.exerciseId.toString(),
|
||||
body);
|
||||
}
|
||||
|
||||
Future<void> addExercise(Exercise exercise) async {
|
||||
String body = JsonEncoder().convert(exercise.toJson());
|
||||
print(" ===== add new exercise: " + body );
|
||||
await _client.post(
|
||||
"exercises",
|
||||
body);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'dart:convert';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
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);
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<ExerciseType> exerciseTypes = json.map( (exerciseType) => ExerciseType.fromJson(exerciseType) ).toList();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Future<void> addExerciseType(ExerciseType exerciseType) async {
|
||||
String body = JsonEncoder().convert(exerciseType.toJson());
|
||||
print(" ===== add new exerciseType: " + body );
|
||||
await _client.post(
|
||||
"exercise_type",
|
||||
body);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user