32 lines
1016 B
Dart
32 lines
1016 B
Dart
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);
|
|
}
|
|
} |